Skip to content

Commit 1088aab

Browse files
committed
lock: adopt the POSIX behaviour on Windows
Ideally we would do the lazy semaphore approach that Mach does. Unfortunately, the queue wasn't getting drained as in that case. A follow up should investigate and fix the lazy allocation.
1 parent 86f184f commit 1088aab

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/shims/lock.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ _pop_timer_resolution(DWORD ms)
270270
if (ms) timeEndPeriod(ms);
271271
}
272272

273-
void
274-
_dispatch_sema4_create_slow(_dispatch_sema4_t *s4, int policy DISPATCH_UNUSED)
273+
void _dispatch_sema4_init(_dispatch_sema4_t *sema, int policy)
275274
{
276275
HANDLE tmp;
277276

@@ -281,7 +280,7 @@ _dispatch_sema4_create_slow(_dispatch_sema4_t *s4, int policy DISPATCH_UNUSED)
281280
_dispatch_temporary_resource_shortage();
282281
}
283282

284-
if (!os_atomic_cmpxchg(s4, 0, tmp, relaxed)) {
283+
if (!os_atomic_cmpxchg(sema, 0, tmp, relaxed)) {
285284
CloseHandle(tmp);
286285
}
287286
}

src/shims/lock.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ typedef HANDLE _dispatch_sema4_t;
205205
#define _DSEMA4_POLICY_LIFO 0
206206
#define _DSEMA4_TIMEOUT() ((errno) = ETIMEDOUT, -1)
207207

208-
#define _dispatch_sema4_init(sema, policy) (void)(*(sema) = 0)
209-
#define _dispatch_sema4_is_created(sema) (*(sema) != 0)
210-
void _dispatch_sema4_create_slow(_dispatch_sema4_t *sema, int policy);
208+
void _dispatch_sema4_init(_dispatch_sema4_t *sema, int policy);
209+
#define _dispatch_sema4_is_created(sema) ((void)sema, 1)
210+
#define _dispatch_sema4_create_slow(sema, policy) ((void)sema, (void)policy)
211211

212212
#else
213213
#error "port has to implement _dispatch_sema4_t"
@@ -285,9 +285,6 @@ _dispatch_thread_event_init(dispatch_thread_event_t dte)
285285
dte->dte_value = 0;
286286
#else
287287
_dispatch_sema4_init(&dte->dte_sema, _DSEMA4_POLICY_FIFO);
288-
#if defined(_WIN32)
289-
_dispatch_sema4_create(&dte->dte_sema, _DSEMA4_POLICY_FIFO);
290-
#endif
291288
#endif
292289
}
293290

0 commit comments

Comments
 (0)