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:
Jeffrey Altman
2015-11-29 12:13:01 -05:00
parent 6fbe672451
commit 4735faba59
2 changed files with 19 additions and 2 deletions

View File

@@ -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;