Skip to content

Commit 2a19c34

Browse files
committed
[Concurrency] Add a couple of comments.
Add some documentation comments to the Dispatch and CF executors, and update the comments for the allocation and private data APIs.
1 parent 12806cb commit 2a19c34

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

stdlib/public/Concurrency/CFExecutor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum CoreFoundation {
4343

4444
// .. Main Executor ............................................................
4545

46+
/// A CFRunLoop-based main executor (Apple platforms only)
4647
@available(StdlibDeploymentTarget 6.2, *)
4748
public final class CFMainExecutor: DispatchMainExecutor, @unchecked Sendable {
4849

@@ -58,6 +59,7 @@ public final class CFMainExecutor: DispatchMainExecutor, @unchecked Sendable {
5859

5960
// .. Task Executor ............................................................
6061

62+
/// A `TaskExecutor` to match `CFMainExecutor` (Apple platforms only)
6163
@available(StdlibDeploymentTarget 6.2, *)
6264
public final class CFTaskExecutor: DispatchGlobalTaskExecutor,
6365
@unchecked Sendable {

stdlib/public/Concurrency/DispatchExecutor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Swift
2323

2424
// .. Main Executor ............................................................
2525

26+
/// A Dispatch-based main executor.
2627
@available(StdlibDeploymentTarget 6.2, *)
2728
public class DispatchMainExecutor: RunLoopExecutor, SchedulingExecutor,
2829
@unchecked Sendable {
@@ -75,6 +76,7 @@ extension DispatchMainExecutor: MainExecutor {}
7576

7677
// .. Task Executor ............................................................
7778

79+
/// A Dispatch-based `TaskExecutor`
7880
@available(StdlibDeploymentTarget 6.2, *)
7981
public class DispatchGlobalTaskExecutor: TaskExecutor, SchedulingExecutor,
8082
@unchecked Sendable {

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ public struct ExecutorJob: Sendable, ~Copyable {
309309
}
310310

311311
/// Execute a closure, passing it the bounds of the executor private data
312-
/// for the job.
312+
/// for the job. The executor is responsible for ensuring that any resources
313+
/// referenced from the private data area are cleared up prior to running the
314+
/// job.
313315
///
314316
/// Parameters:
315317
///
@@ -501,9 +503,8 @@ extension ExecutorJob {
501503
/// A job-local stack-disciplined allocator.
502504
///
503505
/// This can be used to allocate additional data required by an
504-
/// executor implementation; memory allocated in this manner will
505-
/// be released automatically when the job is disposed of by the
506-
/// runtime.
506+
/// executor implementation; memory allocated in this manner must
507+
/// be released by the executor before the job is executed.
507508
///
508509
/// N.B. Because this allocator is stack disciplined, explicitly
509510
/// deallocating memory out-of-order will cause your program to abort.
@@ -531,23 +532,20 @@ extension ExecutorJob {
531532
return unsafe UnsafeMutableBufferPointer<T>(start: typedBase, count: capacity)
532533
}
533534

534-
/// Deallocate previously allocated memory. Note that the task
535-
/// allocator is stack disciplined, so if you deallocate a block of
536-
/// memory, all memory allocated after that block is also deallocated.
535+
/// Deallocate previously allocated memory. You must do this in
536+
/// reverse order of allocations, prior to running the job.
537537
public func deallocate(_ buffer: UnsafeMutableRawBufferPointer) {
538538
unsafe _jobDeallocate(context, buffer.baseAddress!)
539539
}
540540

541-
/// Deallocate previously allocated memory. Note that the task
542-
/// allocator is stack disciplined, so if you deallocate a block of
543-
/// memory, all memory allocated after that block is also deallocated.
541+
/// Deallocate previously allocated memory. You must do this in
542+
/// reverse order of allocations, prior to running the job.
544543
public func deallocate<T>(_ pointer: UnsafeMutablePointer<T>) {
545544
unsafe _jobDeallocate(context, UnsafeMutableRawPointer(pointer))
546545
}
547546

548-
/// Deallocate previously allocated memory. Note that the task
549-
/// allocator is stack disciplined, so if you deallocate a block of
550-
/// memory, all memory allocated after that block is also deallocated.
547+
/// Deallocate previously allocated memory. You must do this in
548+
/// reverse order of allocations, prior to running the job.
551549
public func deallocate<T>(_ buffer: UnsafeMutableBufferPointer<T>) {
552550
unsafe _jobDeallocate(context, UnsafeMutableRawPointer(buffer.baseAddress!))
553551
}

0 commit comments

Comments
 (0)