diff options
author | Chris Robinson <[email protected]> | 2014-04-17 00:11:12 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-04-17 00:11:12 -0700 |
commit | c3b1c31d9b530e64e84805435784ec53eb5ea745 (patch) | |
tree | 4d289aa82e96d6fbba5242889f755e02c3820420 /Alc/threads.c | |
parent | 8cc3d05949b9c2750a5460488cac58c82174e85c (diff) |
Rename althread_key_ wrappers to altss_ and move it to threads.h/c
Diffstat (limited to 'Alc/threads.c')
-rw-r--r-- | Alc/threads.c | 34 |
1 files changed, 34 insertions, 0 deletions
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 |