Skip to content

Commit 4b4ac29

Browse files
authored
Merge pull request #40647 from rjmccall/uncondition-variables
Remove dead code: override jobs and condition variables
2 parents 92b31c4 + 3343331 commit 4b4ac29

File tree

8 files changed

+90
-1056
lines changed

8 files changed

+90
-1056
lines changed

include/swift/Runtime/Mutex.h

Lines changed: 8 additions & 375 deletions
Large diffs are not rendered by default.

include/swift/Runtime/MutexPThread.h

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// Mutex, ConditionVariable, Read/Write lock, and Scoped lock implementations
13+
// Mutex, Read/Write lock, and Scoped lock implementations
1414
// using PThreads.
1515
//
1616
//===----------------------------------------------------------------------===//
@@ -27,8 +27,6 @@
2727

2828
namespace swift {
2929

30-
typedef pthread_cond_t ConditionHandle;
31-
typedef pthread_mutex_t ConditionMutexHandle;
3230
typedef pthread_rwlock_t ReadWriteLockHandle;
3331

3432
#if HAS_OS_UNFAIR_LOCK
@@ -42,50 +40,18 @@ typedef pthread_mutex_t MutexHandle;
4240
// constexpr for static allocation versions. The way they define things
4341
// results in a reinterpret_cast which violates constexpr.
4442
// WASI currently doesn't support threading/locking at all.
45-
#define SWIFT_CONDITION_SUPPORTS_CONSTEXPR 0
4643
#define SWIFT_MUTEX_SUPPORTS_CONSTEXPR 0
4744
#define SWIFT_READWRITELOCK_SUPPORTS_CONSTEXPR 0
4845
#else
49-
#define SWIFT_CONDITION_SUPPORTS_CONSTEXPR 1
5046
#define SWIFT_MUTEX_SUPPORTS_CONSTEXPR 1
5147
#define SWIFT_READWRITELOCK_SUPPORTS_CONSTEXPR 1
5248
#endif
5349

54-
/// PThread low-level implementation that supports ConditionVariable
55-
/// found in Mutex.h
56-
///
57-
/// See ConditionVariable
58-
struct ConditionPlatformHelper {
59-
#if SWIFT_CONDITION_SUPPORTS_CONSTEXPR
60-
static constexpr
61-
#else
62-
static
63-
#endif
64-
ConditionHandle
65-
staticInit() {
66-
return PTHREAD_COND_INITIALIZER;
67-
};
68-
static void init(ConditionHandle &condition);
69-
static void destroy(ConditionHandle &condition);
70-
static void notifyOne(ConditionHandle &condition);
71-
static void notifyAll(ConditionHandle &condition);
72-
static void wait(ConditionHandle &condition, ConditionMutexHandle &mutex);
73-
};
74-
7550
/// PThread low-level implementation that supports Mutex
7651
/// found in Mutex.h
7752
///
7853
/// See Mutex
7954
struct MutexPlatformHelper {
80-
#if SWIFT_MUTEX_SUPPORTS_CONSTEXPR
81-
static constexpr
82-
#else
83-
static
84-
#endif
85-
ConditionMutexHandle
86-
conditionStaticInit() {
87-
return PTHREAD_MUTEX_INITIALIZER;
88-
};
8955
#if SWIFT_MUTEX_SUPPORTS_CONSTEXPR
9056
static constexpr
9157
#else
@@ -99,35 +65,55 @@ struct MutexPlatformHelper {
9965
return PTHREAD_MUTEX_INITIALIZER;
10066
#endif
10167
}
102-
static void init(ConditionMutexHandle &mutex, bool checked = false);
103-
static void destroy(ConditionMutexHandle &mutex);
104-
static void lock(ConditionMutexHandle &mutex);
105-
static void unlock(ConditionMutexHandle &mutex);
106-
static bool try_lock(ConditionMutexHandle &mutex);
107-
108-
// The ConditionMutexHandle versions handle everything on-Apple platforms.
109-
#if HAS_OS_UNFAIR_LOCK
11068

11169
static void init(MutexHandle &mutex, bool checked = false);
11270
static void destroy(MutexHandle &mutex);
11371
static void lock(MutexHandle &mutex);
11472
static void unlock(MutexHandle &mutex);
11573
static bool try_lock(MutexHandle &mutex);
11674

75+
#if HAS_OS_UNFAIR_LOCK
11776
// os_unfair_lock always checks for errors, so just call through.
118-
static void unsafeLock(MutexHandle &mutex) { lock(mutex); }
119-
static void unsafeUnlock(MutexHandle &mutex) { unlock(mutex); }
120-
#endif
121-
122-
// The unsafe versions don't do error checking.
123-
static void unsafeLock(ConditionMutexHandle &mutex) {
77+
static void unsafeLock(MutexHandle &mutex) {
78+
lock(mutex);
79+
}
80+
static void unsafeUnlock(MutexHandle &mutex) {
81+
unlock(mutex);
82+
}
83+
#else
84+
// Skip error checking for the unsafe versions.
85+
static void unsafeLock(MutexHandle &mutex) {
12486
(void)pthread_mutex_lock(&mutex);
12587
}
126-
static void unsafeUnlock(ConditionMutexHandle &mutex) {
88+
static void unsafeUnlock(MutexHandle &mutex) {
12789
(void)pthread_mutex_unlock(&mutex);
12890
}
91+
#endif
12992
};
13093

94+
#if HAS_OS_UNFAIR_LOCK
95+
96+
inline void MutexPlatformHelper::init(os_unfair_lock &lock, bool checked) {
97+
(void)checked; // Unfair locks are always checked.
98+
lock = OS_UNFAIR_LOCK_INIT;
99+
}
100+
101+
inline void MutexPlatformHelper::destroy(os_unfair_lock &lock) {}
102+
103+
inline void MutexPlatformHelper::lock(os_unfair_lock &lock) {
104+
os_unfair_lock_lock(&lock);
105+
}
106+
107+
inline void MutexPlatformHelper::unlock(os_unfair_lock &lock) {
108+
os_unfair_lock_unlock(&lock);
109+
}
110+
111+
inline bool MutexPlatformHelper::try_lock(os_unfair_lock &lock) {
112+
return os_unfair_lock_trylock(&lock);
113+
}
114+
115+
#endif
116+
131117
/// PThread low-level implementation that supports ReadWriteLock
132118
/// found in Mutex.h
133119
///

include/swift/Runtime/MutexSingleThreaded.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,14 @@
2121

2222
namespace swift {
2323

24-
typedef void* ConditionHandle;
25-
typedef void* ConditionMutexHandle;
2624
typedef void* MutexHandle;
2725
typedef void* ReadWriteLockHandle;
2826

29-
#define SWIFT_CONDITION_SUPPORTS_CONSTEXPR 1
3027
#define SWIFT_MUTEX_SUPPORTS_CONSTEXPR 1
3128
#define SWIFT_READWRITELOCK_SUPPORTS_CONSTEXPR 1
3229

33-
struct ConditionPlatformHelper {
34-
static constexpr ConditionHandle staticInit() {
35-
return nullptr;
36-
};
37-
static void init(ConditionHandle &condition) {}
38-
static void destroy(ConditionHandle &condition) {}
39-
static void notifyOne(ConditionHandle &condition) {}
40-
static void notifyAll(ConditionHandle &condition) {}
41-
static void wait(ConditionHandle &condition, MutexHandle &mutex) {
42-
fatalError(0, "single-threaded runtime cannot wait for condition");
43-
}
44-
};
45-
4630
struct MutexPlatformHelper {
4731
static constexpr MutexHandle staticInit() { return nullptr; }
48-
static constexpr ConditionMutexHandle conditionStaticInit() {
49-
return nullptr;
50-
}
5132
static void init(MutexHandle &mutex, bool checked = false) {}
5233
static void destroy(MutexHandle &mutex) {}
5334
static void lock(MutexHandle &mutex) {}

include/swift/Runtime/MutexWin32.h

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// Mutex, ConditionVariable, Read/Write lock, and Scoped lock implementations
14-
// using Windows Slim Reader/Writer Locks and Conditional Variables.
13+
// Mutex and Read/Write lock implementations using Windows Slim
14+
// Reader/Writer Locks and Conditional Variables.
1515
//
1616
//===----------------------------------------------------------------------===//
1717

@@ -24,37 +24,14 @@
2424

2525
namespace swift {
2626

27-
typedef CONDITION_VARIABLE ConditionHandle;
28-
typedef SRWLOCK ConditionMutexHandle;
2927
typedef SRWLOCK MutexHandle;
3028
typedef SRWLOCK ReadWriteLockHandle;
3129

32-
#define SWIFT_CONDITION_SUPPORTS_CONSTEXPR 1
3330
#define SWIFT_MUTEX_SUPPORTS_CONSTEXPR 1
3431
#define SWIFT_READWRITELOCK_SUPPORTS_CONSTEXPR 1
3532

36-
struct ConditionPlatformHelper {
37-
static constexpr ConditionHandle staticInit() {
38-
return CONDITION_VARIABLE_INIT;
39-
};
40-
static void init(ConditionHandle &condition) {
41-
InitializeConditionVariable(&condition);
42-
}
43-
static void destroy(ConditionHandle &condition) {}
44-
static void notifyOne(ConditionHandle &condition) {
45-
WakeConditionVariable(&condition);
46-
}
47-
static void notifyAll(ConditionHandle &condition) {
48-
WakeAllConditionVariable(&condition);
49-
}
50-
static void wait(ConditionHandle &condition, MutexHandle &mutex);
51-
};
52-
5333
struct MutexPlatformHelper {
5434
static constexpr MutexHandle staticInit() { return SRWLOCK_INIT; }
55-
static constexpr ConditionMutexHandle conditionStaticInit() {
56-
return SRWLOCK_INIT;
57-
}
5835
static void init(MutexHandle &mutex, bool checked = false) {
5936
InitializeSRWLock(&mutex);
6037
}

0 commit comments

Comments
 (0)