Skip to content

Commit c19ff7a

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 3d176b3 commit c19ff7a

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/shims/lock.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ _pop_timer_resolution(DWORD ms)
260260
if (ms) timeEndPeriod(ms);
261261
}
262262

263-
void
264-
_dispatch_sema4_create_slow(_dispatch_sema4_t *s4, int policy DISPATCH_UNUSED)
263+
void _dispatch_sema4_init(_dispatch_sema4_t *sema, int policy DISPATCH_UNUSED)
265264
{
266265
HANDLE tmp;
267266

@@ -271,7 +270,7 @@ _dispatch_sema4_create_slow(_dispatch_sema4_t *s4, int policy DISPATCH_UNUSED)
271270
_dispatch_temporary_resource_shortage();
272271
}
273272

274-
if (!os_atomic_cmpxchg(s4, 0, tmp, relaxed)) {
273+
if (!os_atomic_cmpxchg(sema, 0, tmp, relaxed)) {
275274
CloseHandle(tmp);
276275
}
277276
}

src/shims/lock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ typedef HANDLE _dispatch_sema4_t;
213213
#define _DSEMA4_POLICY_LIFO 0
214214
#define _DSEMA4_TIMEOUT() ((errno) = ETIMEDOUT, -1)
215215

216-
#define _dispatch_sema4_init(sema, policy) (void)(*(sema) = 0)
217-
#define _dispatch_sema4_is_created(sema) (*(sema) != 0)
218-
void _dispatch_sema4_create_slow(_dispatch_sema4_t *sema, int policy);
216+
void _dispatch_sema4_init(_dispatch_sema4_t *sema, int policy);
217+
#define _dispatch_sema4_is_created(sema) ((void)sema, 1)
218+
#define _dispatch_sema4_create_slow(sema, policy) ((void)sema, (void)policy)
219219

220220
#else
221221
#error "port has to implement _dispatch_sema4_t"

0 commit comments

Comments
 (0)