Skip to content

Commit c2aab00

Browse files
Merge pull request swiftlang#23214 from aschwaighofer/remove_heap_allocation_of_std_thread
IRGen: Remove heap allocation of std::thread
2 parents 321d2f9 + 76bf9f4 commit c2aab00

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

lib/IRGen/IRGen.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -879,14 +879,11 @@ struct LLVMCodeGenThreads {
879879
#ifdef __APPLE__
880880
pthread_t threadId;
881881
#else
882-
std::thread *thread;
882+
std::thread thread;
883883
#endif
884884

885885
Thread(LLVMCodeGenThreads &parent, unsigned threadIndex)
886886
: parent(parent), threadIndex(threadIndex)
887-
#ifndef __APPLE__
888-
, thread(nullptr)
889-
#endif
890887
{}
891888

892889
/// Run llvm codegen.
@@ -950,7 +947,7 @@ struct LLVMCodeGenThreads {
950947
pthread_attr_destroy(&stackSizeAttribute);
951948
#else
952949
for (auto &thread : threads) {
953-
thread.thread = new std::thread(runThread, &thread);
950+
thread.thread = std::thread(runThread, &thread);
954951
}
955952
#endif
956953

@@ -967,8 +964,7 @@ struct LLVMCodeGenThreads {
967964
pthread_join(thread.threadId, 0);
968965
#else
969966
for (auto &thread: threads) {
970-
thread.thread->join();
971-
delete thread.thread;
967+
thread.thread.join();
972968
}
973969
#endif
974970
}

0 commit comments

Comments
 (0)