X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmapi%2Fstub.c;h=45e4f7dc69e6d5454fa0ca40b803ef8d95710b1f;hb=HEAD;hp=688dc8143a43c7fd0b5536ef0139ec212a2705f8;hpb=d5e9426b9605264608e0b1204ebf818103f1f011;p=mesa.git diff --git a/src/mapi/stub.c b/src/mapi/stub.c index 688dc8143a4..45e4f7dc69e 100644 --- a/src/mapi/stub.c +++ b/src/mapi/stub.c @@ -1,6 +1,5 @@ /* * Mesa 3-D graphics library - * Version: 7.9 * * Copyright (C) 2010 LunarG Inc. * @@ -29,14 +28,14 @@ #include #include #include +#include "c11/threads.h" +#include "util/macros.h" #include "u_current.h" -#include "u_thread.h" #include "entry.h" #include "stub.h" #include "table.h" -#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) struct mapi_stub { const void *name; @@ -55,16 +54,8 @@ static int next_dynamic_slot = MAPI_TABLE_NUM_STATIC; void stub_init_once(void) { -#ifdef HAVE_PTHREAD - static pthread_once_t once = PTHREAD_ONCE_INIT; - pthread_once(&once, entry_patch_public); -#else - static int first = 1; - if (first) { - first = 0; - entry_patch_public(); - } -#endif + static once_flag flag = ONCE_FLAG_INIT; + call_once(&flag, entry_patch_public); } static int @@ -111,7 +102,7 @@ stub_add_dynamic(const char *name) if (!stub->addr) return NULL; - stub->name = (const void *) name; + stub->name = (const void *) strdup(name); /* to be fixed later */ stub->slot = -1; @@ -127,11 +118,11 @@ stub_add_dynamic(const char *name) struct mapi_stub * stub_find_dynamic(const char *name, int generate) { - u_mutex_declare_static(dynamic_mutex); + static mtx_t dynamic_mutex = _MTX_INITIALIZER_NP; struct mapi_stub *stub = NULL; int count, i; - u_mutex_lock(dynamic_mutex); + mtx_lock(&dynamic_mutex); if (generate) assert(!stub_find_public(name)); @@ -148,7 +139,7 @@ stub_find_dynamic(const char *name, int generate) if (generate && !stub) stub = stub_add_dynamic(name); - u_mutex_unlock(dynamic_mutex); + mtx_unlock(&dynamic_mutex); return stub; }