Skip to content

Commit fe9a290

Browse files
authored
Merge pull request #37117 from mikeash/concurrency-autorelease-pools
[Concurrency] Push an autorelease pool around job runs.
2 parents 605a923 + b144a71 commit fe9a290

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
@@ -62,6 +62,11 @@
6262
#include <processthreadsapi.h>
6363
#endif
6464

65+
#if SWIFT_OBJC_INTEROP
66+
extern "C" void *objc_autoreleasePoolPush();
67+
extern "C" void objc_autoreleasePoolPop(void *);
68+
#endif
69+
6570
using namespace swift;
6671

6772
/// Should we yield the thread?
@@ -198,6 +203,10 @@ SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(
198203
void swift::runJobInEstablishedExecutorContext(Job *job) {
199204
_swift_tsan_acquire(job);
200205

206+
#if SWIFT_OBJC_INTEROP
207+
auto pool = objc_autoreleasePoolPush();
208+
#endif
209+
201210
if (auto task = dyn_cast<AsyncTask>(job)) {
202211
// Update the active task in the current thread.
203212
ActiveTask::set(task);
@@ -216,6 +225,10 @@ void swift::runJobInEstablishedExecutorContext(Job *job) {
216225
job->runSimpleInFullyEstablishedContext();
217226
}
218227

228+
#if SWIFT_OBJC_INTEROP
229+
objc_autoreleasePoolPop(pool);
230+
#endif
231+
219232
_swift_tsan_release(job);
220233
}
221234

0 commit comments

Comments
 (0)