File tree Expand file tree Collapse file tree 7 files changed +13
-17
lines changed Expand file tree Collapse file tree 7 files changed +13
-17
lines changed Original file line number Diff line number Diff line change @@ -95,9 +95,8 @@ struct lazy_mutex_handle {
95
95
std::int32_t once; // -1 = initialized, 0 = uninitialized, 1 = initializing
96
96
};
97
97
98
- inline constexpr lazy_mutex_handle lazy_mutex_initializer () {
99
- return (lazy_mutex_handle){};
100
- }
98
+ #define SWIFT_LAZY_MUTEX_INITIALIZER ((lazy_mutex_handle){})
99
+
101
100
inline void lazy_mutex_init (lazy_mutex_handle &handle) {
102
101
// Sadly, we can't use call_once() for this as it doesn't have a context
103
102
if (std::atomic_load_explicit ((std::atomic<std::int32_t > *)&handle.once ,
Original file line number Diff line number Diff line change @@ -108,9 +108,8 @@ inline void mutex_unsafe_unlock(mutex_handle &handle) {
108
108
using lazy_mutex_handle = ::os_unfair_lock;
109
109
110
110
// We don't need to be lazy here because Darwin has OS_UNFAIR_LOCK_INIT.
111
- inline constexpr lazy_mutex_handle lazy_mutex_initializer () {
112
- return OS_UNFAIR_LOCK_INIT;
113
- }
111
+ #define SWIFT_LAZY_MUTEX_INITIALIZER OS_UNFAIR_LOCK_INIT
112
+
114
113
inline void lazy_mutex_destroy (lazy_mutex_handle &handle) {}
115
114
116
115
inline void lazy_mutex_lock (lazy_mutex_handle &handle) {
Original file line number Diff line number Diff line change @@ -110,9 +110,8 @@ using lazy_mutex_handle = ::pthread_mutex_t;
110
110
111
111
// We don't actually need to be lazy here because pthreads has
112
112
// PTHREAD_MUTEX_INITIALIZER.
113
- inline constexpr lazy_mutex_handle lazy_mutex_initializer () {
114
- return PTHREAD_MUTEX_INITIALIZER;
115
- }
113
+ #define SWIFT_LAZY_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
114
+
116
115
inline void lazy_mutex_destroy (lazy_mutex_handle &handle) {
117
116
SWIFT_LINUXTHREADS_CHECK (::pthread_mutex_destroy (&handle));
118
117
}
Original file line number Diff line number Diff line change @@ -50,7 +50,8 @@ inline void mutex_unsafe_unlock(mutex_handle &handle) {}
50
50
51
51
using lazy_mutex_handle = unsigned ;
52
52
53
- inline constexpr lazy_mutex_handle lazy_mutex_initializer () { return 0 ; }
53
+ #define SWIFT_LAZY_MUTEX_INITIALIZER 0
54
+
54
55
inline void lazy_mutex_destroy (lazy_mutex_handle &handle) {}
55
56
inline void lazy_mutex_lock (lazy_mutex_handle &handle) {}
56
57
inline void lazy_mutex_unlock (lazy_mutex_handle &handle) {}
Original file line number Diff line number Diff line change @@ -107,9 +107,8 @@ using lazy_mutex_handle = ::pthread_mutex_t;
107
107
108
108
// We don't actually need to be lazy here because pthreads has
109
109
// PTHREAD_MUTEX_INITIALIZER.
110
- inline constexpr lazy_mutex_handle lazy_mutex_initializer () {
111
- return PTHREAD_MUTEX_INITIALIZER;
112
- }
110
+ #define SWIFT_LAZY_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
111
+
113
112
inline void lazy_mutex_destroy (lazy_mutex_handle &handle) {
114
113
SWIFT_PTHREADS_CHECK (::pthread_mutex_destroy (&handle));
115
114
}
Original file line number Diff line number Diff line change @@ -66,9 +66,8 @@ inline void mutex_unsafe_unlock(mutex_handle &handle) {
66
66
using lazy_mutex_handle = SWIFT_SRWLOCK;
67
67
68
68
// We don't need to be lazy here because Win32 has SRWLOCK_INIT.
69
- inline constexpr lazy_mutex_handle lazy_mutex_initializer () {
70
- return SRWLOCK_INIT;
71
- }
69
+ #define SWIFT_LAZY_MUTEX_INITIALIZER SRWLOCK_INIT
70
+
72
71
inline void lazy_mutex_destroy (lazy_mutex_handle &handle) {}
73
72
74
73
inline void lazy_mutex_lock (lazy_mutex_handle &handle) {
Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ class LazyMutex {
144
144
LazyMutex &operator =(LazyMutex &&) = delete ;
145
145
146
146
public:
147
- constexpr LazyMutex () : Handle(threading_impl::lazy_mutex_initializer() ) {}
147
+ constexpr LazyMutex () : Handle(SWIFT_LAZY_MUTEX_INITIALIZER ) {}
148
148
149
149
// No destructor; this is intentional; this class is for STATIC allocation
150
150
// and you don't need to delete mutexes on termination.
You can’t perform that action at this time.
0 commit comments