Will allow us more freedom wrt building/using waffle on multiple OS's (mostly non-posix).
Note that pthreads_once has been converted to call_once which "can never fail". Signed-off-by: Emil Velikov <emil.l.veli...@gmail.com> --- src/waffle/CMakeLists.txt | 1 + src/waffle/core/wcore_display.c | 8 ++++---- src/waffle/core/wcore_tinfo.c | 26 +++++++++++++------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/waffle/CMakeLists.txt b/src/waffle/CMakeLists.txt index 12cc567..bc7d45b 100644 --- a/src/waffle/CMakeLists.txt +++ b/src/waffle/CMakeLists.txt @@ -42,6 +42,7 @@ set(waffle_libdeps ${x11_LDFLAGS} ${x11-xcb_LDFLAGS} ${xcb_LDFLAGS} + ${THREADS_LIBRARIES} ) set(waffle_sources diff --git a/src/waffle/core/wcore_display.c b/src/waffle/core/wcore_display.c index 43e9e6a..a47e2c3 100644 --- a/src/waffle/core/wcore_display.c +++ b/src/waffle/core/wcore_display.c @@ -24,8 +24,8 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <assert.h> -#include <pthread.h> #include <stdio.h> +#include "threads.h" #include "wcore_display.h" @@ -34,14 +34,14 @@ wcore_display_init(struct wcore_display *self, struct wcore_platform *platform) { static size_t id_counter = 0; - static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + static mtx_t mutex = _MTX_INITIALIZER_NP; assert(self); assert(platform); - pthread_mutex_lock(&mutex); + mtx_lock(&mutex); self->api.display_id = ++id_counter; - pthread_mutex_unlock(&mutex); + mtx_unlock(&mutex); self->platform = platform; diff --git a/src/waffle/core/wcore_tinfo.c b/src/waffle/core/wcore_tinfo.c index df31085..7d749b7 100644 --- a/src/waffle/core/wcore_tinfo.c +++ b/src/waffle/core/wcore_tinfo.c @@ -28,13 +28,13 @@ #include <stdio.h> #include <stdlib.h> -#include <pthread.h> +#include "threads.h" #include "wcore_error.h" #include "wcore_tinfo.h" -static pthread_once_t wcore_tinfo_once = PTHREAD_ONCE_INIT; -static pthread_key_t wcore_tinfo_key; +static once_flag wcore_tinfo_once = ONCE_FLAG_INIT; +static tss_t wcore_tinfo_key; #ifdef WAFFLE_HAS_TLS /// @brief Thread-local storage for all of Waffle. @@ -80,7 +80,7 @@ wcore_tinfo_key_create(void) { int err; - err = pthread_key_create(&wcore_tinfo_key, wcore_tinfo_key_dtor); + err = tss_create(&wcore_tinfo_key, wcore_tinfo_key_dtor); if (err) wcore_tinfo_abort_init(); } @@ -105,12 +105,13 @@ wcore_tinfo_init(struct wcore_tinfo *tinfo) // each instance of tinfo must be registered individually. The key's data // is never retrieved because use the key only to register tinfo for // destruction. - err = pthread_once(&wcore_tinfo_once, wcore_tinfo_key_create); - if (err) - wcore_tinfo_abort_init(); + + // With C11 threads call_once "can never fail"... + // http://open-std.org/twiki/pub/WG14/DefectReports/n1654.htm + call_once(&wcore_tinfo_once, wcore_tinfo_key_create); #endif - err = pthread_setspecific(wcore_tinfo_key, tinfo); + err = tss_set(wcore_tinfo_key, tinfo); if (err) wcore_tinfo_abort_init(); } @@ -122,14 +123,13 @@ wcore_tinfo_get(void) wcore_tinfo_init(&wcore_tinfo); return &wcore_tinfo; #else - int err; struct wcore_tinfo *tinfo; - err = pthread_once(&wcore_tinfo_once, wcore_tinfo_key_create); - if (err) - wcore_tinfo_abort_init(); + // With C11 threads call_once "can never fail"... + // http://open-std.org/twiki/pub/WG14/DefectReports/n1654.htm + call_once(&wcore_tinfo_once, wcore_tinfo_key_create); - tinfo = pthread_getspecific(wcore_tinfo_key); + tinfo = tss_get(wcore_tinfo_key); if (tinfo) return tinfo; -- 2.0.0 _______________________________________________ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle