Skip to content

Commit 0f8bdca

Browse files
committed
[5.5][Concurrency] Push an autorelease pool around job runs.
This ensures that job code that calls out to ObjC code will see a consistent autorelease environment. rdar://75329282
1 parent b08d3bb commit 0f8bdca

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
#include <processthreadsapi.h>
6060
#endif
6161

62+
#if SWIFT_OBJC_INTEROP
63+
extern "C" void *objc_autoreleasePoolPush();
64+
extern "C" void objc_autoreleasePoolPop(void *);
65+
#endif
66+
6267
using namespace swift;
6368

6469
/// Should we yield the thread?
@@ -195,6 +200,10 @@ SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(
195200
void swift::runJobInEstablishedExecutorContext(Job *job) {
196201
_swift_tsan_acquire(job);
197202

203+
#if SWIFT_OBJC_INTEROP
204+
auto pool = objc_autoreleasePoolPush();
205+
#endif
206+
198207
if (auto task = dyn_cast<AsyncTask>(job)) {
199208
// Update the active task in the current thread.
200209
ActiveTask::set(task);
@@ -213,6 +222,10 @@ void swift::runJobInEstablishedExecutorContext(Job *job) {
213222
job->runSimpleInFullyEstablishedContext();
214223
}
215224

225+
#if SWIFT_OBJC_INTEROP
226+
objc_autoreleasePoolPop(pool);
227+
#endif
228+
216229
_swift_tsan_release(job);
217230
}
218231

0 commit comments

Comments
 (0)