diff options
author | Chris Robinson <[email protected]> | 2011-08-20 01:07:27 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-08-20 01:07:27 -0700 |
commit | b036bc9e049efe97a5532b24e08640e7f5cf3934 (patch) | |
tree | 390b9ef8b98946c8ed418e189ed2076a916c9520 | |
parent | 9989f33fc24042578bf4bf2c50a06a6366d07c1d (diff) |
More closely emulate pthread_once in Windows
-rw-r--r-- | Alc/ALc.c | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -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) { |