aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-04-17 00:11:12 -0700
committerChris Robinson <[email protected]>2014-04-17 00:11:12 -0700
commitc3b1c31d9b530e64e84805435784ec53eb5ea745 (patch)
tree4d289aa82e96d6fbba5242889f755e02c3820420 /Alc
parent8cc3d05949b9c2750a5460488cac58c82174e85c (diff)
Rename althread_key_ wrappers to altss_ and move it to threads.h/c
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c31
-rw-r--r--Alc/compat.h12
-rw-r--r--Alc/helpers.c25
-rw-r--r--Alc/threads.c34
4 files changed, 51 insertions, 51 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 14d95023..c4492c96 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -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