Skip to content

Commit 6151731

Browse files
Updated implementation to handle SWIFT_CONCURRENCY_ACTORS_AS_LOCKS
1 parent 6243dfa commit 6151731

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,7 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
22052205
_swift_task_clearCurrent();
22062206
}
22072207

2208+
#if !SWIFT_CONCURRENCY_ACTORS_AS_LOCKS
22082209
namespace {
22092210
/// Job that allows to use executor API to schedule a block of task-less
22102211
/// synchronous code.
@@ -2233,6 +2234,7 @@ class IsolatedDeinitJob : public Job {
22332234
}
22342235
};
22352236
} // namespace
2237+
#endif
22362238

22372239
SWIFT_CC(swift)
22382240
static void swift_task_deinitOnExecutorImpl(void *object,
@@ -2253,8 +2255,12 @@ static void swift_task_deinitOnExecutorImpl(void *object,
22532255
return work(object); // 'return' forces tail call
22542256
}
22552257

2256-
// Optimize deallocation of the default actors
2258+
#if SWIFT_CONCURRENCY_ACTORS_AS_LOCKS
2259+
// In this mode taking actor lock is the only possible implementation
2260+
#else
2261+
// Otherwise, it is an optimisation applied when deinitializing default actors
22572262
if (newExecutor.isDefaultActor() && object == newExecutor.getIdentity()) {
2263+
#endif
22582264
// Try to take the lock. This should always succeed, unless someone is
22592265
// running the actor using unsafe unowned reference.
22602266
if (asImpl(newExecutor.getDefaultActor())->tryLock(false)) {
@@ -2284,7 +2290,7 @@ static void swift_task_deinitOnExecutorImpl(void *object,
22842290

22852291
// `work` is a synchronous function, it cannot call swift_task_switch()
22862292
// If it calls any synchronous API that may change executor inside
2287-
// tracking info, that API is also responsible for changing it back.
2293+
// tracking info, that API is also responsible for changing it back.
22882294
assert(newExecutor == trackingInfo.getActiveExecutor());
22892295
assert(taskExecutor == trackingInfo.getTaskExecutor());
22902296

@@ -2294,7 +2300,12 @@ static void swift_task_deinitOnExecutorImpl(void *object,
22942300
// Give up the current actor.
22952301
asImpl(newExecutor.getDefaultActor())->unlock(true);
22962302
return;
2303+
} else {
2304+
#if SWIFT_CONCURRENCY_ACTORS_AS_LOCKS
2305+
assert(false && "Should not enqueue onto default actor in actor as locks model");
2306+
#endif
22972307
}
2308+
#if !SWIFT_CONCURRENCY_ACTORS_AS_LOCKS
22982309
}
22992310

23002311
auto currentTask = swift_task_getCurrent();
@@ -2303,6 +2314,7 @@ static void swift_task_deinitOnExecutorImpl(void *object,
23032314

23042315
auto job = new IsolatedDeinitJob(priority, object, work);
23052316
swift_task_enqueue(job, newExecutor);
2317+
#endif
23062318
}
23072319

23082320
/*****************************************************************************/

stdlib/public/Distributed/DistributedDefaultExecutor.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@ internal final class DistributedRemoteActorReferenceExecutor: SerialExecutor {
2323

2424
internal init() {}
2525

26+
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
27+
@inlinable
28+
func enqueue(_ job: UnownedJob) {
29+
let jobDescription = job.description
30+
fatalError("Attempted to enqueue ExecutorJob (\(jobDescription)) on executor of remote distributed actor reference!")
31+
}
32+
#else
2633
@inlinable
2734
public func enqueue(_ job: consuming ExecutorJob) {
2835
let jobDescription = job.description
2936
fatalError("Attempted to enqueue ExecutorJob (\(jobDescription)) on executor of remote distributed actor reference!")
3037
}
38+
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
3139

3240
public func asUnownedSerialExecutor() -> UnownedSerialExecutor {
3341
UnownedSerialExecutor(ordinary: self)

0 commit comments

Comments
 (0)