Skip to content

Commit 77cf7c6

Browse files
committed
Remove old runAsyncAndBlock internals
runAsyncAndBlock has long been dead, I'm pulling out the machinery that lives in the runtime that used to support it. This is the first layer that can go away.
1 parent aff95bf commit 77cf7c6

File tree

2 files changed

+0
-133
lines changed

2 files changed

+0
-133
lines changed

include/swift/Runtime/Concurrency.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -618,19 +618,6 @@ SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
618618
NearestTaskDeadline
619619
swift_task_getNearestDeadline(AsyncTask *task);
620620

621-
/// Run the given async function and block the current thread until
622-
/// it returns. This is a hack added for testing purposes; eventually
623-
/// top-level code will be an async context, and the need for this in
624-
/// tests should go away. We *definitely* do not want this to be part
625-
/// of the standard feature set.
626-
///
627-
/// The argument is a `() async -> ()` function, whose ABI is currently
628-
/// quite complex. Eventually this should use a different convention;
629-
/// that's rdar://72105841.
630-
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
631-
void swift_task_runAndBlockThread(const void *function,
632-
HeapObject *functionContext);
633-
634621
/// Switch the current task to a new executor if we aren't already
635622
/// running on a compatible executor.
636623
///

stdlib/public/Concurrency/Task.cpp

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -857,126 +857,6 @@ void swift_task_future_wait_throwingImpl(
857857
}
858858
}
859859

860-
namespace {
861-
862-
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
863-
864-
class RunAndBlockSemaphore {
865-
bool Finished = false;
866-
public:
867-
void wait() {
868-
donateThreadToGlobalExecutorUntil([](void *context) {
869-
return *reinterpret_cast<bool*>(context);
870-
}, &Finished);
871-
872-
assert(Finished && "ran out of tasks before we were signalled");
873-
}
874-
875-
void signal() {
876-
Finished = true;
877-
}
878-
};
879-
880-
#else
881-
882-
class RunAndBlockSemaphore {
883-
ConditionVariable Queue;
884-
ConditionVariable::Mutex Lock;
885-
bool Finished = false;
886-
public:
887-
/// Wait for a signal.
888-
void wait() {
889-
Lock.withLockOrWait(Queue, [&] {
890-
return Finished;
891-
});
892-
}
893-
894-
void signal() {
895-
Lock.withLockThenNotifyAll(Queue, [&]{
896-
Finished = true;
897-
});
898-
}
899-
};
900-
901-
#endif
902-
903-
using RunAndBlockSignature =
904-
AsyncSignature<void(HeapObject*), /*throws*/ false>;
905-
struct RunAndBlockContext: AsyncContext {
906-
const void *Function;
907-
HeapObject *FunctionContext;
908-
RunAndBlockSemaphore *Semaphore;
909-
};
910-
using RunAndBlockCalleeContext =
911-
AsyncCalleeContext<RunAndBlockContext, RunAndBlockSignature>;
912-
913-
} // end anonymous namespace
914-
915-
/// Second half of the runAndBlock async function.
916-
SWIFT_CC(swiftasync)
917-
static void runAndBlock_finish(SWIFT_ASYNC_CONTEXT AsyncContext *_context) {
918-
auto calleeContext = static_cast<RunAndBlockCalleeContext*>(_context);
919-
920-
auto context = popAsyncContext(calleeContext);
921-
922-
context->Semaphore->signal();
923-
924-
return context->ResumeParent(context);
925-
}
926-
927-
/// First half of the runAndBlock async function.
928-
SWIFT_CC(swiftasync)
929-
static void runAndBlock_start(SWIFT_ASYNC_CONTEXT AsyncContext *_context,
930-
SWIFT_CONTEXT HeapObject *closureContext) {
931-
auto callerContext = static_cast<RunAndBlockContext*>(_context);
932-
933-
RunAndBlockSignature::FunctionType *function;
934-
size_t calleeContextSize;
935-
auto functionContext = callerContext->FunctionContext;
936-
assert(closureContext == functionContext);
937-
std::tie(function, calleeContextSize)
938-
= getAsyncClosureEntryPointAndContextSize<
939-
RunAndBlockSignature,
940-
SpecialPointerAuthDiscriminators::AsyncRunAndBlockFunction
941-
>(const_cast<void*>(callerContext->Function), functionContext);
942-
943-
auto calleeContext =
944-
pushAsyncContext<RunAndBlockSignature>(callerContext,
945-
calleeContextSize,
946-
&runAndBlock_finish,
947-
functionContext);
948-
return reinterpret_cast<AsyncVoidClosureEntryPoint *>(function)(
949-
calleeContext, functionContext);
950-
}
951-
952-
// TODO: Remove this hack.
953-
void swift::swift_task_runAndBlockThread(const void *function,
954-
HeapObject *functionContext) {
955-
RunAndBlockSemaphore semaphore;
956-
957-
// Set up a task that runs the runAndBlock async function above.
958-
auto flags = TaskCreateFlags();
959-
flags.setPriority(JobPriority::Default);
960-
auto pair = swift_task_create_common(
961-
flags.getOpaqueValue(),
962-
/*options=*/nullptr,
963-
/*futureResultType=*/nullptr,
964-
reinterpret_cast<ThinNullaryAsyncSignature::FunctionType *>(
965-
&runAndBlock_start),
966-
nullptr,
967-
sizeof(RunAndBlockContext));
968-
auto context = static_cast<RunAndBlockContext*>(pair.InitialContext);
969-
context->Function = function;
970-
context->FunctionContext = functionContext;
971-
context->Semaphore = &semaphore;
972-
973-
// Enqueue the task.
974-
swift_task_enqueueGlobal(pair.Task);
975-
976-
// Wait until the task completes.
977-
semaphore.wait();
978-
}
979-
980860
size_t swift::swift_task_getJobFlags(AsyncTask *task) {
981861
return task->Flags.getOpaqueValue();
982862
}

0 commit comments

Comments
 (0)