File tree 4 files changed +36
-1
lines changed
stdlib/public/Concurrency
4 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -382,11 +382,26 @@ extension SerialExecutor {
382
382
#endif
383
383
}
384
384
385
+ #if SWIFT_CONCURRENCY_USES_DISPATCH
386
+ @available ( SwiftStdlib 6 . 2 , * )
387
+ private var _dispatchQueue : OpaquePointer ? {
388
+ return _getDispatchQueueForExecutor ( self . asUnownedSerialExecutor ( ) )
389
+ }
390
+ #endif
391
+
385
392
@available ( SwiftStdlib 6 . 2 , * )
386
393
internal func _isSameExecutor( _ rhs: some SerialExecutor ) -> Bool {
387
394
if rhs === self {
388
395
return true
389
396
}
397
+ #if SWIFT_CONCURRENCY_USES_DISPATCH
398
+ if let rhsQueue = rhs. _dispatchQueue {
399
+ if let ourQueue = _dispatchQueue, ourQueue == rhsQueue {
400
+ return true
401
+ }
402
+ return false
403
+ }
404
+ #endif
390
405
if let rhs = rhs as? Self {
391
406
return isSameExclusiveExecutionContext ( other: rhs)
392
407
}
Original file line number Diff line number Diff line change 18
18
19
19
#include " Error.h"
20
20
#include " ExecutorBridge.h"
21
+ #include " TaskPrivate.h"
21
22
22
23
using namespace swift ;
23
24
@@ -73,6 +74,15 @@ extern "C" SWIFT_CC(swift)
73
74
void swift_dispatchAssertMainQueue () {
74
75
dispatch_assert_queue (dispatch_get_main_queue ());
75
76
}
76
- #endif // SWIFT_CONCURRENCY_ENABLE_DISPATCH
77
+
78
+ extern " C" SWIFT_CC(swift)
79
+ void *swift_getDispatchQueueForExecutor (SerialExecutorRef executor) {
80
+ if (executor.getRawImplementation () == (uintptr_t )_swift_task_getDispatchQueueSerialExecutorWitnessTable ()) {
81
+ return executor.getIdentity ();
82
+ }
83
+ return nullptr ;
84
+ }
85
+
86
+ #endif // SWIFT_CONCURRENCY_USES_DISPATCH
77
87
78
88
#pragma clang diagnostic pop
Original file line number Diff line number Diff line change @@ -130,3 +130,8 @@ internal func _dispatchAssertMainQueue()
130
130
131
131
@_silgen_name( " swift_createDefaultExecutorsOnce" )
132
132
func _createDefaultExecutorsOnce( )
133
+
134
+ @_silgen_name( " swift_getDispatchQueueForExecutor" )
135
+ internal func _getDispatchQueueForExecutor(
136
+ _ executor: UnownedSerialExecutor
137
+ ) -> OpaquePointer ?
Original file line number Diff line number Diff line change @@ -382,6 +382,11 @@ static SerialExecutorRef executorForEnqueuedJob(Job *job) {
382
382
return swift_task_getMainExecutor ();
383
383
}
384
384
385
+ if (auto identity = reinterpret_cast <HeapObject *>(jobQueue)) {
386
+ return SerialExecutorRef::forOrdinary (
387
+ identity, _swift_task_getDispatchQueueSerialExecutorWitnessTable ());
388
+ }
389
+
385
390
return SerialExecutorRef::generic ();
386
391
#endif
387
392
}
You can’t perform that action at this time.
0 commit comments