base: Windows implementation of heim_base_once
Provide a Windows implementation of heim_base_once that relies upon InterlockedCompareExchange() and SwitchToThread(). Change-Id: I9cdbda796d1a27fe1e17be63f287b10132858d7f
This commit is contained in:
@@ -368,7 +368,16 @@ _heim_type_get_tid(heim_type_t type)
|
||||
void
|
||||
heim_base_once_f(heim_base_once_t *once, void *ctx, void (*func)(void *))
|
||||
{
|
||||
#ifdef HAVE_DISPATCH_DISPATCH_H
|
||||
#if defined(WIN32)
|
||||
if (InterlockedCompareExchange(&once->started, 1L, 0L) == 0L) {
|
||||
once->running = 1L;
|
||||
(*func)(ctx);
|
||||
once->running = 0L;
|
||||
} else {
|
||||
while (once->running)
|
||||
SwitchToThread();
|
||||
}
|
||||
#elif defined(HAVE_DISPATCH_DISPATCH_H)
|
||||
dispatch_once_f(once, ctx, func);
|
||||
#else
|
||||
static HEIMDAL_MUTEX mutex = HEIMDAL_MUTEX_INITIALIZER;
|
||||
|
||||
Reference in New Issue
Block a user