Rename althread_once to be more C11-like
This commit is contained in:
parent
20e5ec18e1
commit
6c8bf9ec42
@ -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)
|
||||
|
||||
|
||||
/************************************************
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user