diff options
author | Emil Velikov <[email protected]> | 2015-03-06 16:54:56 +0000 |
---|---|---|
committer | Emil Velikov <[email protected]> | 2015-03-11 23:28:25 +0000 |
commit | a806df3f23cd5fadffbfe818f8c5af7e17205426 (patch) | |
tree | 3152796ada4b81ac94e90df2477f1a294dab6175 /src/egl/main | |
parent | efe87f1a801c61d087cd2b29a2c150453241c3d4 (diff) |
egl/main: convert thread management to use c11 threads
Convert the code to use the C11 threads implementation, and nuke the
Windows non-pthreads code-path. The c11/threads_win32.h abstraction
should be better than the current code.
Signed-off-by: Emil Velikov <[email protected]>
Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/egl/main')
-rw-r--r-- | src/egl/main/eglcurrent.c | 48 |
1 files changed, 6 insertions, 42 deletions
diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c index dc32ed4c210..5d8cae4ee31 100644 --- a/src/egl/main/eglcurrent.c +++ b/src/egl/main/eglcurrent.c @@ -29,6 +29,7 @@ #include <stdlib.h> #include <string.h> #include "c99_compat.h" +#include "c11/threads.h" #include "egllog.h" #include "eglcurrent.h" @@ -41,14 +42,9 @@ /* a fallback thread info to guarantee that every thread always has one */ static _EGLThreadInfo dummy_thread = _EGL_THREAD_INFO_INITIALIZER; - - -#if HAVE_PTHREAD -#include <pthread.h> - static mtx_t _egl_TSDMutex = _MTX_INITIALIZER_NP; static EGLBoolean _egl_TSDInitialized; -static pthread_key_t _egl_TSD; +static tss_t _egl_TSD; static void (*_egl_FreeTSD)(_EGLThreadInfo *); #ifdef GLX_USE_TLS @@ -58,7 +54,7 @@ static __thread const _EGLThreadInfo *_egl_TLS static inline void _eglSetTSD(const _EGLThreadInfo *t) { - pthread_setspecific(_egl_TSD, (const void *) t); + tss_set(_egl_TSD, (const void *) t); #ifdef GLX_USE_TLS _egl_TLS = t; #endif @@ -69,7 +65,7 @@ static inline _EGLThreadInfo *_eglGetTSD(void) #ifdef GLX_USE_TLS return (_EGLThreadInfo *) _egl_TLS; #else - return (_EGLThreadInfo *) pthread_getspecific(_egl_TSD); + return (_EGLThreadInfo *) tss_get(_egl_TSD); #endif } @@ -82,7 +78,7 @@ static inline void _eglFiniTSD(void) _egl_TSDInitialized = EGL_FALSE; if (t && _egl_FreeTSD) _egl_FreeTSD((void *) t); - pthread_key_delete(_egl_TSD); + tss_delete(_egl_TSD); } mtx_unlock(&_egl_TSDMutex); } @@ -94,7 +90,7 @@ static inline EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *)) /* check again after acquiring lock */ if (!_egl_TSDInitialized) { - if (pthread_key_create(&_egl_TSD, (void (*)(void *)) dtor) != 0) { + if (tss_create(&_egl_TSD, (void (*)(void *)) dtor) != thrd_success) { mtx_unlock(&_egl_TSDMutex); return EGL_FALSE; } @@ -109,38 +105,6 @@ static inline EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *)) return EGL_TRUE; } -#else /* HAVE_PTHREAD */ -static const _EGLThreadInfo *_egl_TSD; -static void (*_egl_FreeTSD)(_EGLThreadInfo *); - -static inline void _eglSetTSD(const _EGLThreadInfo *t) -{ - _egl_TSD = t; -} - -static inline _EGLThreadInfo *_eglGetTSD(void) -{ - return (_EGLThreadInfo *) _egl_TSD; -} - -static inline void _eglFiniTSD(void) -{ - if (_egl_FreeTSD && _egl_TSD) - _egl_FreeTSD((_EGLThreadInfo *) _egl_TSD); -} - -static inline EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *)) -{ - if (!_egl_FreeTSD && dtor) { - _egl_FreeTSD = dtor; - _eglAddAtExitCall(_eglFiniTSD); - } - return EGL_TRUE; -} - -#endif /* !HAVE_PTHREAD */ - - static void _eglInitThreadInfo(_EGLThreadInfo *t) { |