diff options
author | Chris Robinson <[email protected]> | 2014-04-17 21:39:51 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-04-17 21:39:51 -0700 |
commit | 6c8bf9ec42b74635e05241a769f70ea5572a335c (patch) | |
tree | 462829a2c824adb0a6cd5de39f539c6cb16fbfec | |
parent | 20e5ec18e1e28b83ecaa588b87973be2cf295e74 (diff) |
Rename althread_once to be more C11-like
-rw-r--r-- | Alc/ALc.c | 4 | ||||
-rw-r--r-- | Alc/compat.h | 8 | ||||
-rw-r--r-- | Alc/helpers.c | 11 | ||||
-rw-r--r-- | Alc/threads.c | 12 | ||||
-rw-r--r-- | OpenAL32/Include/threads.h | 19 |
5 files changed, 30 insertions, 24 deletions
@@ -737,7 +737,7 @@ enum LogLevel LogLevel = LogError; static ALCboolean TrapALCError = ALC_FALSE; /* One-time configuration init control */ -static althread_once_t alc_config_once = ALTHREAD_ONCE_INIT; +static alonce_flag alc_config_once = AL_ONCE_INIT; /* Default effect that applies to sources that don't have an effect on send 0 */ static ALeffect DefaultEffect; @@ -1139,7 +1139,7 @@ static void alc_initconfig(void) if((str && str[0]) || ConfigValueStr(NULL, "default-reverb", &str)) LoadReverbPreset(str, &DefaultEffect); } -#define DO_INITCONFIG() althread_once(&alc_config_once, alc_initconfig) +#define DO_INITCONFIG() alcall_once(&alc_config_once, alc_initconfig) /************************************************ diff --git a/Alc/compat.h b/Alc/compat.h index 50516ce8..2765ef18 100644 --- a/Alc/compat.h +++ b/Alc/compat.h @@ -8,10 +8,6 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> -typedef LONG althread_once_t; -#define ALTHREAD_ONCE_INIT 0 -void althread_once(althread_once_t *once, void (*callback)(void)); - WCHAR *strdupW(const WCHAR *str); /* Opens a file with standard I/O. The filename is expected to be UTF-8. */ @@ -23,10 +19,6 @@ FILE *al_fopen(const char *fname, const char *mode); #include <pthread.h> -#define althread_once_t pthread_once_t -#define ALTHREAD_ONCE_INIT PTHREAD_ONCE_INIT -#define althread_once pthread_once - #define al_fopen(_n, _m) fopen((_n), (_m)) #if defined(HAVE_DLFCN_H) && !defined(IN_IDE_PARSER) diff --git a/Alc/helpers.c b/Alc/helpers.c index 79dac143..e1e94f10 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -311,17 +311,6 @@ void RestoreFPUMode(const FPUCtl *ctl) #ifdef _WIN32 -void althread_once(althread_once_t *once, void (*callback)(void)) -{ - LONG ret; - while((ret=InterlockedExchange(once, 1)) == 1) - althrd_yield(); - if(ret == 0) - callback(); - InterlockedExchange(once, 2); -} - - static WCHAR *FromUTF8(const char *str) { WCHAR *out = NULL; diff --git a/Alc/threads.c b/Alc/threads.c index d0aea6e8..d9dabec1 100644 --- a/Alc/threads.c +++ b/Alc/threads.c @@ -294,6 +294,17 @@ int altimespec_get(struct timespec *ts, int base) return 0; } + +void alcall_once(alonce_flag *once, void (*callback)(void)) +{ + LONG ret; + while((ret=InterlockedExchange(once, 1)) == 1) + althrd_yield(); + if(ret == 0) + (*callback)(); + InterlockedExchange(once, 2); +} + #else #include <unistd.h> @@ -304,6 +315,7 @@ int altimespec_get(struct timespec *ts, int base) extern inline int althrd_sleep(const struct timespec *ts, struct timespec *rem); +extern inline void alcall_once(alonce_flag *once, void (*callback)(void)); void althrd_setname(althrd_t thr, const char *name) diff --git a/OpenAL32/Include/threads.h b/OpenAL32/Include/threads.h index eade2406..afeaeb4b 100644 --- a/OpenAL32/Include/threads.h +++ b/OpenAL32/Include/threads.h @@ -29,9 +29,6 @@ typedef void (*altss_dtor_t)(void*); #define WIN32_LEAN_AND_MEAN #include <windows.h> -typedef DWORD althrd_t; -typedef CRITICAL_SECTION almtx_t; -typedef DWORD altss_t; #ifndef __MINGW32__ struct timespec { @@ -40,8 +37,15 @@ struct timespec { }; #endif +typedef DWORD althrd_t; +typedef CRITICAL_SECTION almtx_t; +typedef DWORD altss_t; +typedef LONG alonce_flag; + +#define AL_ONCE_INIT 0 int althrd_sleep(const struct timespec *ts, struct timespec *rem); +void alcall_once(alonce_flag *once, void (*callback)(void)); inline althrd_t althrd_current(void) @@ -109,6 +113,9 @@ inline int altss_set(altss_t tss_id, void *val) typedef pthread_t althrd_t; typedef pthread_mutex_t almtx_t; typedef pthread_key_t altss_t; +typedef pthread_once_t alonce_flag; + +#define AL_ONCE_INIT PTHREAD_ONCE_INIT inline althrd_t althrd_current(void) @@ -190,6 +197,12 @@ inline int altss_set(altss_t tss_id, void *val) return althrd_success; } + +inline void alcall_once(alonce_flag *once, void (*callback)(void)) +{ + pthread_once(once, callback); +} + #endif |