From b036bc9e049efe97a5532b24e08640e7f5cf3934 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 20 Aug 2011 01:07:27 -0700 Subject: More closely emulate pthread_once in Windows --- Alc/ALc.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Alc/ALc.c b/Alc/ALc.c index 7322d924..06294392 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -694,23 +694,23 @@ static void alc_initconfig(void) } #ifdef _WIN32 -static struct once_control { - LONG canpass; - LONG hasrun; -} once_control = { TRUE, FALSE }; -static void call_once(struct once_control *once, void (*callback)(void)) +typedef LONG pthread_once_t; +#define PTHREAD_ONCE_INIT 0 + +static void pthread_once(pthread_once_t *once, void (*callback)(void)) { - while(InterlockedExchange(&once->canpass, FALSE) == FALSE) + LONG ret; + while((ret=InterlockedExchange(once, 1)) == 1) Sleep(0); - if(InterlockedExchange(&once->hasrun, TRUE) == FALSE) + if(ret == 0) callback(); - InterlockedExchange(&once->canpass, TRUE); + InterlockedExchange(once, 2); } -#define DO_INITCONFIG() call_once(&once_control, alc_initconfig) -#else +#endif + static pthread_once_t once_control = PTHREAD_ONCE_INIT; #define DO_INITCONFIG() pthread_once(&once_control, alc_initconfig) -#endif + static void ProbeList(ALCchar **list, size_t *listsize, enum DevProbe type) { -- cgit v1.2.3