Skip to content

Commit 6e875da

Browse files
committed
[Threading] Remove thread_get_main().
Removing thread_get_main() means we don't need a static initializer on Darwin, which means we can delete Darwin.cpp as well. We can also delete Nothreads.cpp while we're about it, because there's nothing in that file. rdar://90776105
1 parent dadd23e commit 6e875da

File tree

15 files changed

+11
-118
lines changed

15 files changed

+11
-118
lines changed

include/swift/Threading/Impl/C11.h

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ do { \
4949
using thread_id = ::thrd_t;
5050

5151
inline thread_id thread_get_current() { return ::thrd_current(); }
52-
thread_id thread_get_main();
5352
bool thread_is_main();
5453
inline bool threads_same(thread_id a, thread_id b) {
5554
return ::thrd_equal(a, b);

include/swift/Threading/Impl/Darwin.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ using thread_id = ::pthread_t;
3232

3333
inline thread_id thread_get_current() { return ::pthread_self(); }
3434

35-
thread_id thread_get_main();
36-
bool thread_is_main();
35+
inline bool thread_is_main() { return pthread_main_np(); }
3736

3837
inline bool threads_same(thread_id a, thread_id b) {
3938
return ::pthread_equal(a, b);

include/swift/Threading/Impl/Linux.h

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ using thread_id = ::pthread_t;
5555

5656
inline thread_id thread_get_current() { return ::pthread_self(); }
5757

58-
thread_id thread_get_main();
5958
bool thread_is_main();
6059

6160
inline bool threads_same(thread_id a, thread_id b) {

include/swift/Threading/Impl/Nothreads.h

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace threading_impl {
2525
using thread_id = unsigned;
2626

2727
inline thread_id thread_get_current() { return 0; }
28-
inline thread_id thread_get_main() { return 0; }
2928
inline bool thread_is_main() { return true; }
3029
inline bool threads_same(thread_id a, thread_id b) { return a == b; }
3130

include/swift/Threading/Impl/Pthreads.h

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ using thread_id = ::pthread_t;
5454

5555
inline thread_id thread_get_current() { return ::pthread_self(); }
5656

57-
thread_id thread_get_main();
5857
bool thread_is_main();
5958

6059
inline bool threads_same(thread_id a, thread_id b) {

include/swift/Threading/Impl/Win32.h

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ namespace threading_impl {
2929
using thread_id = ::DWORD;
3030

3131
inline thread_id thread_get_current() { return ::GetCurrentThreadId(); }
32-
thread_id thread_get_main();
3332
bool thread_is_main();
3433
inline bool threads_same(thread_id a, thread_id b) { return a == b; }
3534

include/swift/Threading/Thread.h

-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ class Thread {
5555
return Thread(threading_impl::thread_get_current());
5656
}
5757

58-
/// Returns the main thread in this program
59-
static Thread main() {
60-
return Thread(threading_impl::thread_get_main());
61-
}
62-
6358
/// Returns true iff executed on the main thread
6459
static bool onMainThread() {
6560
return threading_impl::thread_is_main();

lib/Threading/C11.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,9 @@ C11ThreadingHelper helper;
6464
using namespace swift;
6565
using namespace threading_impl;
6666

67-
thread_id
68-
swift::threading_impl::thread_get_main() {
69-
return helper.main_thread();
70-
}
71-
7267
bool
7368
swift::threading_impl::thread_is_main() {
74-
return thrd_equal(thrd_current(), thread_get_main());
69+
return thrd_equal(thrd_current(), helper.main_thread());
7570
}
7671

7772
void

lib/Threading/CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
# If you update this, you also need to update the CMakeLists.txt file in
2+
# stdlib/public/Threading
3+
14
add_swift_host_library(swiftThreading STATIC
25
C11.cpp
3-
Darwin.cpp
46
Linux.cpp
5-
Nothreads.cpp
67
Pthreads.cpp
78
Win32.cpp)

lib/Threading/Darwin.cpp

-57
This file was deleted.

lib/Threading/Linux.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,9 @@ MainThreadRememberer rememberer;
4242
using namespace swift;
4343
using namespace threading_impl;
4444

45-
thread_id
46-
swift::threading_impl::thread_get_main() {
47-
return rememberer.main_thread();
48-
}
49-
5045
bool
5146
swift::threading_impl::thread_is_main() {
52-
return pthread_equal(pthread_self(), thread_get_main());
47+
return pthread_equal(pthread_self(), rememberer.main_thread());
5348
}
5449

5550
void

lib/Threading/Nothreads.cpp

-21
This file was deleted.

lib/Threading/Pthreads.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,9 @@ pthread_cond_t onceCond = PTHREAD_COND_INITIALIZER;
4444
using namespace swift;
4545
using namespace threading_impl;
4646

47-
thread_id
48-
swift::threading_impl::thread_get_main() {
49-
return rememberer.main_thread();
50-
}
51-
5247
bool
5348
swift::threading_impl::thread_is_main() {
54-
return pthread_equal(pthread_self(), thread_get_main());
49+
return pthread_equal(pthread_self(), rememberer.main_thread());
5550
}
5651

5752
void

lib/Threading/Win32.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,9 @@ CONDITION_VARIABLE onceCond = CONDITION_VARIABLE_INIT;
5252
using namespace swift;
5353
using namespace threading_impl;
5454

55-
thread_id
56-
swift::threading_impl::thread_get_main() {
57-
return rememberer.main_thread();
58-
}
59-
6055
bool
6156
swift::threading_impl::thread_is_main() {
62-
return ::GetCurrentThreadId() == thread_get_main();
57+
return ::GetCurrentThreadId() == rememberer.main_thread();
6358
}
6459

6560
void
+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
# This is the counterpart to lib/Threading/CMakeLists.txt. Any updates
2+
# need to be reflected in both places.
3+
14
add_swift_target_library(swiftThreading OBJECT_LIBRARY
25
"${SWIFT_SOURCE_DIR}/lib/Threading/C11.cpp"
3-
"${SWIFT_SOURCE_DIR}/lib/Threading/Darwin.cpp"
46
"${SWIFT_SOURCE_DIR}/lib/Threading/Linux.cpp"
5-
"${SWIFT_SOURCE_DIR}/lib/Threading/Nothreads.cpp"
67
"${SWIFT_SOURCE_DIR}/lib/Threading/Pthreads.cpp"
78
"${SWIFT_SOURCE_DIR}/lib/Threading/Win32.cpp"
89
INSTALL_IN_COMPONENT never_install)

0 commit comments

Comments
 (0)