diff options
-rw-r--r-- | Alc/ALc.c | 31 | ||||
-rw-r--r-- | Alc/compat.h | 12 | ||||
-rw-r--r-- | Alc/helpers.c | 25 | ||||
-rw-r--r-- | Alc/threads.c | 34 | ||||
-rw-r--r-- | OpenAL32/Include/threads.h | 31 |
5 files changed, 82 insertions, 51 deletions
@@ -719,7 +719,7 @@ static const ALchar alExtList[] = static volatile ALCenum LastNullDeviceError = ALC_NO_ERROR; /* Thread-local current context */ -static althread_key_t LocalContext; +static altss_t LocalContext; /* Process-wide current context */ static ALCcontext *volatile GlobalContext = NULL; @@ -808,8 +808,8 @@ BOOL APIENTRY DllMain(HINSTANCE hModule,DWORD ul_reason_for_call,LPVOID lpReserv LockUIntMapRead(&TlsDestructor); for(i = 0;i < TlsDestructor.size;i++) { - void *ptr = althread_getspecific(TlsDestructor.array[i].key); - void (*callback)(void*) = (void(*)(void*))TlsDestructor.array[i].value; + void *ptr = altss_get(TlsDestructor.array[i].key); + altss_dtor_t callback = (altss_dtor_t)TlsDestructor.array[i].value; if(ptr && callback) callback(ptr); } @@ -877,9 +877,12 @@ static void alc_init(void) if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1)) ZScale *= -1.0f; - althread_key_create(&LocalContext, ReleaseThreadCtx); + ret = altss_create(&LocalContext, ReleaseThreadCtx); + assert(ret == althrd_success); + ret = almtx_init(&ListLock, almtx_recursive); assert(ret == althrd_success); + ThunkInit(); } @@ -1191,7 +1194,7 @@ static void alc_deinit_safe(void) ThunkExit(); almtx_destroy(&ListLock); - althread_key_delete(LocalContext); + altss_delete(LocalContext); if(LogFile != stderr) fclose(LogFile); @@ -2177,10 +2180,10 @@ static void ReleaseContext(ALCcontext *context, ALCdevice *device) { ALCcontext *volatile*tmp_ctx; - if(althread_getspecific(LocalContext) == context) + if(altss_get(LocalContext) == context) { WARN("%p released while current on thread\n", context); - althread_setspecific(LocalContext, NULL); + altss_set(LocalContext, NULL); ALCcontext_DecRef(context); } @@ -2261,7 +2264,7 @@ ALCcontext *GetContextRef(void) { ALCcontext *context; - context = althread_getspecific(LocalContext); + context = altss_get(LocalContext); if(context) ALCcontext_IncRef(context); else @@ -2949,7 +2952,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void) { ALCcontext *Context; - Context = althread_getspecific(LocalContext); + Context = altss_get(LocalContext); if(!Context) Context = GlobalContext; return Context; @@ -2962,7 +2965,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void) ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void) { ALCcontext *Context; - Context = althread_getspecific(LocalContext); + Context = altss_get(LocalContext); return Context; } @@ -2984,9 +2987,9 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context) context = ExchangePtr((XchgPtr*)&GlobalContext, context); if(context) ALCcontext_DecRef(context); - if((context=althread_getspecific(LocalContext)) != NULL) + if((context=altss_get(LocalContext)) != NULL) { - althread_setspecific(LocalContext, NULL); + altss_set(LocalContext, NULL); ALCcontext_DecRef(context); } @@ -3008,8 +3011,8 @@ ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context) return ALC_FALSE; } /* context's reference count is already incremented */ - old = althread_getspecific(LocalContext); - althread_setspecific(LocalContext, context); + old = altss_get(LocalContext); + altss_set(LocalContext, context); if(old) ALCcontext_DecRef(old); return ALC_TRUE; diff --git a/Alc/compat.h b/Alc/compat.h index 7d577cb7..f11de462 100644 --- a/Alc/compat.h +++ b/Alc/compat.h @@ -8,12 +8,6 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> -typedef DWORD althread_key_t; -int althread_key_create(althread_key_t *key, void (*callback)(void*)); -int althread_key_delete(althread_key_t key); -void *althread_getspecific(althread_key_t key); -int althread_setspecific(althread_key_t key, void *val); - typedef LONG althread_once_t; #define ALTHREAD_ONCE_INIT 0 void althread_once(althread_once_t *once, void (*callback)(void)); @@ -31,12 +25,6 @@ FILE *al_fopen(const char *fname, const char *mode); ALuint timeGetTime(void); -#define althread_key_t pthread_key_t -#define althread_key_create pthread_key_create -#define althread_key_delete pthread_key_delete -#define althread_getspecific pthread_getspecific -#define althread_setspecific pthread_setspecific - #define althread_once_t pthread_once_t #define ALTHREAD_ONCE_INIT PTHREAD_ONCE_INIT #define althread_once pthread_once diff --git a/Alc/helpers.c b/Alc/helpers.c index 17fc9c2c..b8e5be03 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -322,31 +322,6 @@ void althread_once(althread_once_t *once, void (*callback)(void)) } -int althread_key_create(althread_key_t *key, void (*callback)(void*)) -{ - *key = TlsAlloc(); - if(callback) - InsertUIntMapEntry(&TlsDestructor, *key, callback); - return 0; -} - -int althread_key_delete(althread_key_t key) -{ - InsertUIntMapEntry(&TlsDestructor, key, NULL); - TlsFree(key); - return 0; -} - -void *althread_getspecific(althread_key_t key) -{ return TlsGetValue(key); } - -int althread_setspecific(althread_key_t key, void *val) -{ - TlsSetValue(key, val); - return 0; -} - - void *LoadLib(const char *name) { return LoadLibraryA(name); } void CloseLib(void *handle) diff --git a/Alc/threads.c b/Alc/threads.c index 1dece664..e5df3086 100644 --- a/Alc/threads.c +++ b/Alc/threads.c @@ -37,6 +37,9 @@ extern inline int almtx_lock(almtx_t *mtx); extern inline int almtx_unlock(almtx_t *mtx); extern inline int almtx_trylock(almtx_t *mtx); +extern inline void *altss_get(altss_t tss_id); +extern inline int altss_set(altss_t tss_id, void *val); + extern inline void al_nssleep(time_t sec, long nsec); @@ -195,6 +198,24 @@ int almtx_timedlock(almtx_t *mtx, const struct timespec *ts) } +int altss_create(altss_t *tss_id, altss_dtor_t callback) +{ + DWORD key = TlsAlloc(); + if(key == TLS_OUT_OF_INDEXES) + return althrd_error; + + *tss_id = key; + if(callback != NULL) + InsertUIntMapEntry(&TlsDestructor, key, callback); + return althrd_success; +} + +void altss_delete(altss_t tss_id) +{ + InsertUIntMapEntry(&TlsDestructor, tss_id, NULL); + TlsFree(tss_id); +} + #else #include <pthread.h> @@ -350,4 +371,17 @@ int almtx_timedlock(almtx_t *mtx, const struct timespec *ts) return althrd_error; } + +int altss_create(altss_t *tss_id, altss_dtor_t callback) +{ + if(pthread_key_create(tss_id, callback) != 0) + return althrd_error; + return althrd_success; +} + +void altss_delete(altss_t tss_id) +{ + pthread_key_delete(tss_id); +} + #endif diff --git a/OpenAL32/Include/threads.h b/OpenAL32/Include/threads.h index f0ee1b5c..0c9601c9 100644 --- a/OpenAL32/Include/threads.h +++ b/OpenAL32/Include/threads.h @@ -20,6 +20,7 @@ enum { typedef int (*althrd_start_t)(void*); +typedef void (*altss_dtor_t)(void*); #ifdef _WIN32 @@ -28,6 +29,7 @@ typedef int (*althrd_start_t)(void*); typedef HANDLE althrd_t; typedef CRITICAL_SECTION almtx_t; +typedef DWORD altss_t; #ifndef __MINGW32__ struct timespec { @@ -89,6 +91,18 @@ inline int almtx_trylock(almtx_t *mtx) return althrd_success; } + +inline void *altss_get(altss_t tss_id) +{ + return TlsGetValue(tss_id); +} + +inline int altss_set(altss_t tss_id, void *val) +{ + TlsSetValue(tss_id, val); + return althrd_success; +} + #else #include <stdint.h> @@ -98,6 +112,7 @@ inline int almtx_trylock(almtx_t *mtx) typedef pthread_t althrd_t; typedef pthread_mutex_t almtx_t; +typedef pthread_key_t altss_t; inline althrd_t althrd_current(void) @@ -166,6 +181,19 @@ inline int almtx_trylock(almtx_t *mtx) return althrd_error; } + +inline void *altss_get(altss_t tss_id) +{ + return pthread_getspecific(tss_id); +} + +inline int altss_set(altss_t tss_id, void *val) +{ + if(pthread_setspecific(tss_id, val) != 0) + return althrd_error; + return althrd_success; +} + #endif @@ -177,6 +205,9 @@ int almtx_init(almtx_t *mtx, int type); void almtx_destroy(almtx_t *mtx); int almtx_timedlock(almtx_t *mtx, const struct timespec *ts); +int altss_create(altss_t *tss_id, altss_dtor_t callback); +void altss_delete(altss_t tss_id); + void SetThreadName(const char *name); |