Skip to content

Commit c18331c

Browse files
committed
Move swift_task_alloc/dealloc into the Concurrency library.
Also, rename them to follow the general namespacing scheme.
1 parent a8464dc commit c18331c

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

include/swift/Runtime/Concurrency.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121

2222
namespace swift {
2323

24+
/// Allocate memory in a task.
25+
///
26+
/// This must be called synchronously with the task.
27+
///
28+
/// All allocations will be rounded to a multiple of MAX_ALIGNMENT.
29+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
30+
void *swift_task_alloc(AsyncTask *task, size_t size);
31+
32+
/// Deallocate memory in a task.
33+
///
34+
/// The pointer provided must be the last pointer allocated on
35+
/// this task that has not yet been deallocated; that is, memory
36+
/// must be allocated and deallocated in a strict stack discipline.
37+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
38+
void swift_task_dealloc(AsyncTask *task, void *ptr);
39+
2440
/// Cancel a task and all of its child tasks.
2541
///
2642
/// This can be called from any thread.

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,17 +1461,17 @@ FUNCTION(GetTypeByMangledNameInContextInMetadataState,
14611461
Int8PtrPtrTy),
14621462
ATTRS(NoUnwind, ArgMemOnly))
14631463

1464-
// void *swift_taskAlloc(SwiftTask *task, size_t size);
1464+
// void *swift_task_alloc(AsyncTask *task, size_t size);
14651465
FUNCTION(TaskAlloc,
1466-
swift_taskAlloc, SwiftCC,
1466+
swift_task_alloc, SwiftCC,
14671467
ConcurrencyAvailability,
14681468
RETURNS(Int8PtrTy),
14691469
ARGS(SwiftTaskPtrTy, SizeTy),
14701470
ATTRS(NoUnwind, ArgMemOnly))
14711471

1472-
// void swift_taskDealloc(SwiftTask *task, void *ptr);
1472+
// void swift_task_dealloc(AsyncTask *task, void *ptr);
14731473
FUNCTION(TaskDealloc,
1474-
swift_taskDealloc, SwiftCC,
1474+
swift_task_dealloc, SwiftCC,
14751475
ConcurrencyAvailability,
14761476
RETURNS(VoidTy),
14771477
ARGS(SwiftTaskPtrTy, Int8PtrTy),

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
1414
Actor.swift
1515
PartialAsyncTask.swift
16+
TaskAlloc.cpp
1617
TaskStatus.cpp
1718
Mutex.cpp
1819

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===------------ Concurrency.cpp - Swift Concurrency Support ------------===//
1+
//===--- TaskAlloc.cpp - Task-local stack allocator -----------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,28 +10,22 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// Implementations of the concurrency runtime functions.
13+
// A task-local allocator that obeys a stack discipline.
1414
//
15-
// void *swift_taskAlloc(SwiftTask *task, size_t size);
16-
// void swift_taskDealloc(SwiftTask *task, void *ptr);
15+
// Because allocation is task-local, and there's at most one thread
16+
// running a task at once, no synchronization is required.
1717
//
1818
//===----------------------------------------------------------------------===//
1919

20-
#include "../SwiftShims/Visibility.h"
21-
#include "swift/Runtime/Config.h"
22-
#include <cstddef>
20+
#include "swift/Runtime/Concurrency.h"
2321
#include <stdlib.h>
2422

25-
struct SwiftTask;
23+
using namespace swift;
2624

27-
SWIFT_RUNTIME_EXPORT
28-
SWIFT_CC(swift)
29-
void *swift_taskAlloc(SwiftTask *task, size_t size) {
25+
void *swift::swift_task_alloc(AsyncTask *task, size_t size) {
3026
return malloc(size);
3127
}
3228

33-
SWIFT_RUNTIME_EXPORT
34-
SWIFT_CC(swift)
35-
void swift_taskDealloc(SwiftTask *task, void *ptr) {
29+
void swift::swift_task_dealloc(AsyncTask *task, void *ptr) {
3630
free(ptr);
3731
}

stdlib/public/Concurrency/TaskStatus.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- Metadata.cpp - Swift Language ABI Metadata Support ---------------===//
1+
//===--- TaskStatus.cpp - Asynchronous task status tracking ---------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,7 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// Routines for cancelling tasks.
13+
// Routines for maintaining and interacting with the current state of a
14+
// task, including tracking child tasks, deadlines, and cancellation.
1415
//
1516
//===----------------------------------------------------------------------===//
1617

stdlib/public/runtime/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ set(swift_runtime_sources
3131
BackDeployment.cpp
3232
Casting.cpp
3333
CompatibilityOverride.cpp
34-
Concurrency.cpp
3534
CygwinPort.cpp
3635
Demangle.cpp
3736
DynamicCast.cpp

0 commit comments

Comments
 (0)