19
19
20
20
#if (defined(__APPLE__) || defined(__linux__) || defined(__CYGWIN__))
21
21
#define SWIFT_RUNTIME_MUTEX_HAVE_PHTREADS
22
+ #else
23
+ #error "Must implement the following if your platform doesn't support phtreads."
22
24
#endif
23
25
24
26
#ifdef SWIFT_RUNTIME_MUTEX_HAVE_PHTREADS
@@ -74,18 +76,15 @@ class MutexImpl {
74
76
MutexImpl (MutexImpl &&) = delete ;
75
77
MutexImpl &operator =(MutexImpl &&) = delete ;
76
78
77
- protected:
78
- explicit MutexImpl (bool checked);
79
-
80
79
public:
81
80
void lock ();
82
81
void unlock ();
83
82
bool try_lock ();
84
-
85
- public:
86
83
void wait (Condition &condition);
87
84
88
85
private:
86
+ explicit MutexImpl (bool checked);
87
+
89
88
#ifdef SWIFT_RUNTIME_MUTEX_HAVE_PHTREADS
90
89
pthread_mutex_t PThreadMutex;
91
90
#endif
@@ -95,6 +94,7 @@ class MutexImpl {
95
94
// / Use ScopedLock instead (see below).
96
95
class ScopedLockImpl {
97
96
friend class Mutex ;
97
+ friend class ScopedLock ;
98
98
99
99
public:
100
100
ScopedLockImpl () = delete ;
@@ -105,20 +105,16 @@ class ScopedLockImpl {
105
105
ScopedLockImpl (ScopedLockImpl &&) = delete ;
106
106
ScopedLockImpl &operator =(ScopedLockImpl &&) = delete ;
107
107
108
- protected:
109
- ScopedLockImpl (MutexImpl &impl) : Impl(impl) { Impl.lock (); }
110
-
111
- public:
112
- void wait (Condition &condition) { Impl.wait (condition); }
113
-
114
108
private:
109
+ ScopedLockImpl (MutexImpl &impl) : Impl(impl) { Impl.lock (); }
115
110
MutexImpl &Impl;
116
111
};
117
112
118
113
// / Internal (private) implementation of scoped unlocking functionality.
119
114
// / Use ScopedUnlock instead (see below).
120
115
class ScopedUnlockImpl {
121
116
friend class Mutex ;
117
+ friend class ScopedUnlock ;
122
118
123
119
public:
124
120
ScopedUnlockImpl () = delete ;
@@ -129,10 +125,8 @@ class ScopedUnlockImpl {
129
125
ScopedUnlockImpl (ScopedUnlockImpl &&) = delete ;
130
126
ScopedUnlockImpl &operator =(ScopedUnlockImpl &&) = delete ;
131
127
132
- protected:
133
- ScopedUnlockImpl (MutexImpl &impl) : Impl(impl) { Impl.unlock (); }
134
-
135
128
private:
129
+ ScopedUnlockImpl (MutexImpl &impl) : Impl(impl) { Impl.unlock (); }
136
130
MutexImpl &Impl;
137
131
};
138
132
@@ -292,12 +286,6 @@ class ScopedLock : ScopedLockImpl {
292
286
ScopedLock &operator =(const ScopedLock &) = delete ;
293
287
ScopedLock (ScopedLock &&) = delete ;
294
288
ScopedLock &operator =(ScopedLock &&) = delete ;
295
-
296
- public:
297
- // / Releases lock, waits on supplied condition, and relocks before returning.
298
- // /
299
- // / Precondition: Mutex locked by this thread, undefined otherwise.
300
- void wait (Condition &condition) { ScopedLockImpl::wait (condition); }
301
289
};
302
290
303
291
// / A stack based object that unlocks the supplied mutex on construction
0 commit comments