File tree 1 file changed +2
-7
lines changed
1 file changed +2
-7
lines changed Original file line number Diff line number Diff line change @@ -98,22 +98,17 @@ void *_dispatch_wait_for_enqueuer(void **ptr);
98
98
#define _dispatch_contention_spins () \
99
99
((DISPATCH_CONTENTION_SPINS_MIN) + ((DISPATCH_CONTENTION_SPINS_MAX) - \
100
100
(DISPATCH_CONTENTION_SPINS_MIN)) / 2)
101
- #elif defined( _WIN32 )
101
+ #else
102
102
// Use randomness to prevent threads from resonating at the same frequency and
103
103
// permanently contending. Windows doesn't provide rand_r(), so use a simple
104
104
// LCG. (msvcrt has rand_s(), but its security guarantees aren't optimal here.)
105
+ // The implementation of rand() can contain a lock (known with glibc at least).
105
106
#define _dispatch_contention_spins () ({ \
106
107
static os_atomic(unsigned int) _seed = 1; \
107
108
unsigned int _next = os_atomic_load(&_seed, relaxed); \
108
109
os_atomic_store(&_seed, _next * 1103515245 + 12345, relaxed); \
109
110
((_next >> 24) & (DISPATCH_CONTENTION_SPINS_MAX)) | \
110
111
(DISPATCH_CONTENTION_SPINS_MIN); })
111
- #else
112
- // Use randomness to prevent threads from resonating at the same
113
- // frequency and permanently contending.
114
- #define _dispatch_contention_spins () ({ \
115
- ((unsigned int)rand() & (DISPATCH_CONTENTION_SPINS_MAX)) | \
116
- (DISPATCH_CONTENTION_SPINS_MIN); })
117
112
#endif
118
113
#define _dispatch_contention_wait_until (c ) ({ \
119
114
bool _out = false; \
You can’t perform that action at this time.
0 commit comments