diff options
author | marha <marha@users.sourceforge.net> | 2015-03-05 22:17:40 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2015-03-05 22:17:40 +0100 |
commit | 8574eba804031f6b19713f0b02952280730bf62e (patch) | |
tree | 9afa4d6fe299d43ab7e580dc08a5547120274561 /mesalib/src/mapi | |
parent | eef70231353a6103f47fcae88a6e89e765e5cd47 (diff) | |
download | vcxsrv-8574eba804031f6b19713f0b02952280730bf62e.tar.gz vcxsrv-8574eba804031f6b19713f0b02952280730bf62e.tar.bz2 vcxsrv-8574eba804031f6b19713f0b02952280730bf62e.zip |
fontconfig mesa git update 5 Mar 2015
Diffstat (limited to 'mesalib/src/mapi')
25 files changed, 106 insertions, 336 deletions
diff --git a/mesalib/src/mapi/Makefile.am b/mesalib/src/mapi/Makefile.am index 679468291..50c5b2ebb 100644 --- a/mesalib/src/mapi/Makefile.am +++ b/mesalib/src/mapi/Makefile.am @@ -39,11 +39,14 @@ EXTRA_DIST = \ glapi/SConscript \ shared-glapi/SConscript -AM_CFLAGS = $(PTHREAD_CFLAGS) +AM_CFLAGS = \ + $(PTHREAD_CFLAGS) \ + $(MSVC2013_COMPAT_CFLAGS) AM_CPPFLAGS = \ $(DEFINES) \ $(SELINUX_CFLAGS) \ -I$(top_srcdir)/include \ + -I$(top_srcdir)/src \ -I$(top_srcdir)/src/mapi \ -I$(top_builddir)/src/mapi @@ -66,7 +69,7 @@ if HAVE_SHARED_GLAPI BUILT_SOURCES += shared-glapi/glapi_mapi_tmp.h lib_LTLIBRARIES += shared-glapi/libglapi.la -shared_glapi_libglapi_la_SOURCES = $(MAPI_GLAPI_FILES) +shared_glapi_libglapi_la_SOURCES = $(MAPI_GLAPI_FILES) shared-glapi/glapi_mapi_tmp.h shared_glapi_libglapi_la_CPPFLAGS = \ $(AM_CPPFLAGS) \ -DMAPI_MODE_GLAPI \ @@ -115,7 +118,7 @@ glapi_libglapi_la_CPPFLAGS = \ -I$(top_srcdir)/src/mesa if HAVE_SHARED_GLAPI -glapi_libglapi_la_SOURCES += $(MAPI_BRIDGE_FILES) +glapi_libglapi_la_SOURCES += $(MAPI_BRIDGE_FILES) glapi/glapi_mapi_tmp.h glapi_libglapi_la_CPPFLAGS += \ -DMAPI_MODE_BRIDGE \ -DMAPI_ABI_HEADER=\"glapi/glapi_mapi_tmp.h\" @@ -230,10 +233,4 @@ endif es2api/glapi_mapi_tmp.h: glapi/gen/gl_and_es_API.xml $(glapi_gen_mapi_deps) $(call glapi_gen_mapi,$<,es2api) -# XXX: Inline vgapi's Makefile.am here. -EXTRA_DIST += vgapi -# if HAVE_OPENVG -# SUBDIRS += vgapi -# endif - include $(top_srcdir)/install-lib-links.mk diff --git a/mesalib/src/mapi/Makefile.sources b/mesalib/src/mapi/Makefile.sources index 41dbb24c8..07063f390 100644 --- a/mesalib/src/mapi/Makefile.sources +++ b/mesalib/src/mapi/Makefile.sources @@ -15,13 +15,10 @@ # this mode, compile MAPI_BRIDGE_FILES with MAPI_MODE_BRIDGE defined. MAPI_UTIL_FILES = \ - u_compiler.h \ u_current.c \ u_current.h \ u_execmem.c \ - u_execmem.h \ - u_macros.h \ - u_thread.h + u_execmem.h MAPI_BRIDGE_FILES = \ entry.c \ diff --git a/mesalib/src/mapi/entry.c b/mesalib/src/mapi/entry.c index b6e8db28d..27d0db40e 100644 --- a/mesalib/src/mapi/entry.c +++ b/mesalib/src/mapi/entry.c @@ -27,7 +27,9 @@ #include "entry.h" #include "u_current.h" -#include "u_macros.h" + +#define _U_STRINGIFY(x) #x +#define U_STRINGIFY(x) _U_STRINGIFY(x) /* define macros for use by assembly dispatchers */ #define ENTRY_CURRENT_TABLE U_STRINGIFY(u_current_table) @@ -51,7 +53,7 @@ #include <stdlib.h> -static INLINE const struct mapi_table * +static inline const struct mapi_table * entry_current_get(void) { #ifdef MAPI_MODE_BRIDGE diff --git a/mesalib/src/mapi/entry.h b/mesalib/src/mapi/entry.h index dba1c06a3..7c8137c0c 100644 --- a/mesalib/src/mapi/entry.h +++ b/mesalib/src/mapi/entry.h @@ -28,7 +28,6 @@ #ifndef _ENTRY_H_ #define _ENTRY_H_ -#include "u_compiler.h" typedef void (*mapi_func)(void); diff --git a/mesalib/src/mapi/entry_x86-64_tls.h b/mesalib/src/mapi/entry_x86-64_tls.h index 71e9d6063..5c03b0456 100644 --- a/mesalib/src/mapi/entry_x86-64_tls.h +++ b/mesalib/src/mapi/entry_x86-64_tls.h @@ -25,7 +25,6 @@ * Chia-I Wu <olv@lunarg.com> */ -#include "u_macros.h" __asm__(".text\n" ".balign 32\n" @@ -88,7 +87,7 @@ entry_generate(int slot) 0x41, 0xff, 0xa3, 0x34, 0x12, 0x00, 0x00, }; unsigned long addr; - void *code; + char *code; mapi_func entry; addr = x86_64_current_tls(); diff --git a/mesalib/src/mapi/entry_x86_tls.h b/mesalib/src/mapi/entry_x86_tls.h index fa7bc15b8..46d2eced2 100644 --- a/mesalib/src/mapi/entry_x86_tls.h +++ b/mesalib/src/mapi/entry_x86_tls.h @@ -26,7 +26,6 @@ */ #include <string.h> -#include "u_macros.h" __asm__(".text"); @@ -113,7 +112,7 @@ entry_generate(int slot) 0xff, 0xa0, 0x34, 0x12, 0x00, 0x00, /* jmp *0x1234(%eax) */ 0x90, 0x90, 0x90, 0x90 /* nop's */ }; - void *code; + char *code; mapi_func entry; code = u_execmem_alloc(sizeof(code_templ)); diff --git a/mesalib/src/mapi/entry_x86_tsd.h b/mesalib/src/mapi/entry_x86_tsd.h index ece00fac0..ea7bacb43 100644 --- a/mesalib/src/mapi/entry_x86_tsd.h +++ b/mesalib/src/mapi/entry_x86_tsd.h @@ -25,7 +25,6 @@ * Chia-I Wu <olv@lunarg.com> */ -#include "u_macros.h" #define X86_ENTRY_SIZE 32 diff --git a/mesalib/src/mapi/glapi/SConscript b/mesalib/src/mapi/glapi/SConscript index 97ebfe638..8ded46f32 100644 --- a/mesalib/src/mapi/glapi/SConscript +++ b/mesalib/src/mapi/glapi/SConscript @@ -8,6 +8,8 @@ Import('*') env = env.Clone() +env.MSVC2013Compat() + env.Append(CPPDEFINES = [ 'MAPI_MODE_UTIL', ]) @@ -25,6 +27,7 @@ if env['platform'] == 'windows': env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS']) env.Append(CPPPATH = [ + '#/src', '#/src/mapi', '#/src/mesa', Dir('..'), # src/mapi build path diff --git a/mesalib/src/mapi/glapi/gen/gl_enums.py b/mesalib/src/mapi/glapi/gen/gl_enums.py index 35919d68a..d61618f4d 100644 --- a/mesalib/src/mapi/glapi/gen/gl_enums.py +++ b/mesalib/src/mapi/glapi/gen/gl_enums.py @@ -83,7 +83,7 @@ const char *_mesa_lookup_enum_by_nr( int nr ) STATIC_ASSERT(sizeof(enum_string_table) < (1 << 16)); elt = bsearch(& nr, enum_string_table_offsets, - Elements(enum_string_table_offsets), + ARRAY_SIZE(enum_string_table_offsets), sizeof(enum_string_table_offsets[0]), (cfunc) compar_nr); @@ -127,7 +127,7 @@ static const char *prim_names[PRIM_MAX+3] = { const char * _mesa_lookup_prim_by_nr(GLuint nr) { - if (nr < Elements(prim_names)) + if (nr < ARRAY_SIZE(prim_names)) return prim_names[nr]; else return "invalid mode"; diff --git a/mesalib/src/mapi/glapi/gen/gl_x86-64_asm.py b/mesalib/src/mapi/glapi/gen/gl_x86-64_asm.py index 19e0e15b0..5a69e0343 100644 --- a/mesalib/src/mapi/glapi/gen/gl_x86-64_asm.py +++ b/mesalib/src/mapi/glapi/gen/gl_x86-64_asm.py @@ -138,10 +138,6 @@ class PrintGenericStubs(gl_XML.gl_print_base): print '# define GL_PREFIX(n) GLNAME(CONCAT(gl,n))' print '# endif' print '' - print '#if defined(HAVE_PTHREAD) || defined(_WIN32)' - print '# define THREADS' - print '#endif' - print '' print '\t.text' print '' print '#ifdef GLX_USE_TLS' @@ -170,7 +166,7 @@ class PrintGenericStubs(gl_XML.gl_print_base): print '\tmovl\t(%rax), %edi' print '\tjmp\tpthread_getspecific@PLT' print '' - print '#elif defined(THREADS)' + print '#else' print '' print '\t.extern\t_glapi_get_dispatch' print '' diff --git a/mesalib/src/mapi/glapi/gen/gl_x86_asm.py b/mesalib/src/mapi/glapi/gen/gl_x86_asm.py index d87d0bd24..f855dbaaa 100644 --- a/mesalib/src/mapi/glapi/gen/gl_x86_asm.py +++ b/mesalib/src/mapi/glapi/gen/gl_x86_asm.py @@ -78,9 +78,6 @@ class PrintGenericStubs(gl_XML.gl_print_base): print '#define GLOBL_FN(x) GLOBL x' print '#endif' print '' - print '#if defined(HAVE_PTHREAD) || defined(_WIN32)' - print '# define THREADS' - print '#endif' print '' print '#ifdef GLX_USE_TLS' print '' @@ -109,7 +106,7 @@ class PrintGenericStubs(gl_XML.gl_print_base): print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\' print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\' print '\tJMP(GL_OFFSET(off))' - print '#elif defined(THREADS)' + print '#else' print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' print 'ALIGNTEXT16;\t\t\t\t\t\t\\' print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' @@ -120,13 +117,6 @@ class PrintGenericStubs(gl_XML.gl_print_base): print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\' print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\' print '\tJMP(GL_OFFSET(off))' - print '#else /* Non-threaded version. */' - print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' - print 'ALIGNTEXT16;\t\t\t\t\t\t\\' - print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' - print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' - print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\' - print '\tJMP(GL_OFFSET(off))' print '#endif' print '' print '#ifdef HAVE_ALIAS' @@ -164,7 +154,7 @@ class PrintGenericStubs(gl_XML.gl_print_base): print '\tCALL(GLNAME(pthread_getspecific))' print '\tADD_L(CONST(28), ESP)' print '\tRET' - print '#elif defined(THREADS)' + print '#else' print 'EXTERN GLNAME(_glapi_get_dispatch)' print '#endif' print '' diff --git a/mesalib/src/mapi/glapi/glapi.h b/mesalib/src/mapi/glapi/glapi.h index e2fa9252f..8d991fb3b 100644 --- a/mesalib/src/mapi/glapi/glapi.h +++ b/mesalib/src/mapi/glapi/glapi.h @@ -44,7 +44,7 @@ #ifndef _GLAPI_H #define _GLAPI_H -#include "u_thread.h" +#include "util/macros.h" #ifdef __cplusplus @@ -102,21 +102,12 @@ _GLAPI_EXPORT extern const void *_glapi_Context; _GLAPI_EXPORT extern struct _glapi_table *_glapi_Dispatch; _GLAPI_EXPORT extern void *_glapi_Context; -# ifdef THREADS - -# define GET_DISPATCH() \ +#define GET_DISPATCH() \ (likely(_glapi_Dispatch) ? _glapi_Dispatch : _glapi_get_dispatch()) -# define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) \ +#define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) \ (likely(_glapi_Context) ? _glapi_Context : _glapi_get_context()) -# else - -# define GET_DISPATCH() _glapi_Dispatch -# define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) _glapi_Context - -# endif - #endif /* defined (GLX_USE_TLS) */ diff --git a/mesalib/src/mapi/glapi/glapi_entrypoint.c b/mesalib/src/mapi/glapi/glapi_entrypoint.c index 362a8f11b..7facd8aca 100644 --- a/mesalib/src/mapi/glapi/glapi_entrypoint.c +++ b/mesalib/src/mapi/glapi/glapi_entrypoint.c @@ -29,6 +29,7 @@ */ +#include "c11/threads.h" #include "glapi/glapi_priv.h" #include "u_execmem.h" @@ -120,11 +121,9 @@ fill_in_entrypoint_offset(_glapi_proc entrypoint, unsigned int offset) #if defined(GLX_USE_TLS) *((unsigned int *)(code + 8)) = 4 * offset; -#elif defined(THREADS) +#else *((unsigned int *)(code + 11)) = 4 * offset; *((unsigned int *)(code + 22)) = 4 * offset; -#else - *((unsigned int *)(code + 7)) = 4 * offset; #endif } @@ -338,7 +337,7 @@ void init_glapi_relocs_once( void ) { #if defined(HAVE_PTHREAD) || defined(GLX_USE_TLS) - static pthread_once_t once_control = PTHREAD_ONCE_INIT; - pthread_once( & once_control, init_glapi_relocs ); + static once_flag flag = ONCE_FLAG_INIT; + call_once(&flag, init_glapi_relocs); #endif } diff --git a/mesalib/src/mapi/glapi/glapi_priv.h b/mesalib/src/mapi/glapi/glapi_priv.h index 92925faac..d3682603d 100644 --- a/mesalib/src/mapi/glapi/glapi_priv.h +++ b/mesalib/src/mapi/glapi/glapi_priv.h @@ -86,10 +86,8 @@ get_entrypoint_address(unsigned int functionOffset); #if defined(USE_X86_ASM) # if defined(GLX_USE_TLS) # define DISPATCH_FUNCTION_SIZE 16 -# elif defined(THREADS) -# define DISPATCH_FUNCTION_SIZE 32 # else -# define DISPATCH_FUNCTION_SIZE 16 +# define DISPATCH_FUNCTION_SIZE 32 # endif #endif diff --git a/mesalib/src/mapi/mapi.c b/mesalib/src/mapi/mapi.c index aa6b91b42..c235adc4a 100644 --- a/mesalib/src/mapi/mapi.c +++ b/mesalib/src/mapi/mapi.c @@ -29,7 +29,6 @@ #include <string.h> #include "u_current.h" -#include "u_thread.h" #include "mapi.h" #include "stub.h" #include "table.h" diff --git a/mesalib/src/mapi/mapi.h b/mesalib/src/mapi/mapi.h index 2aa8d9fe0..9adf8b5a3 100644 --- a/mesalib/src/mapi/mapi.h +++ b/mesalib/src/mapi/mapi.h @@ -28,8 +28,6 @@ #ifndef _MAPI_H_ #define _MAPI_H_ -#include "u_compiler.h" - #ifdef _WIN32 #ifdef MAPI_DLL_EXPORTS #define MAPI_EXPORT __declspec(dllexport) diff --git a/mesalib/src/mapi/mapi_abi.py b/mesalib/src/mapi/mapi_abi.py index d783ed32f..012a5c3f4 100644 --- a/mesalib/src/mapi/mapi_abi.py +++ b/mesalib/src/mapi/mapi_abi.py @@ -816,25 +816,8 @@ typedef int GLclampx; return header -class VGAPIPrinter(ABIPrinter): - """OpenVG API Printer""" - - def __init__(self, entries): - super(VGAPIPrinter, self).__init__(entries) - - self.api_defines = ['VG_VGEXT_PROTOTYPES'] - self.api_headers = ['"VG/openvg.h"', '"VG/vgext.h"'] - self.api_call = 'VG_API_CALL' - self.api_entry = 'VG_API_ENTRY' - self.api_attrs = 'VG_API_EXIT' - - self.prefix_lib = 'vg' - self.prefix_app = 'vega' - self.prefix_noop = 'noop' - self.prefix_warn = 'vg' - def parse_args(): - printers = ['vgapi', 'glapi', 'es1api', 'es2api', 'shared-glapi'] + printers = ['glapi', 'es1api', 'es2api', 'shared-glapi'] modes = ['lib', 'app'] parser = OptionParser(usage='usage: %prog [options] <filename>') @@ -853,7 +836,6 @@ def parse_args(): def main(): printers = { - 'vgapi': VGAPIPrinter, 'glapi': GLAPIPrinter, 'es1api': ES1APIPrinter, 'es2api': ES2APIPrinter, diff --git a/mesalib/src/mapi/stub.c b/mesalib/src/mapi/stub.c index dfadbe1a5..05436bab6 100644 --- a/mesalib/src/mapi/stub.c +++ b/mesalib/src/mapi/stub.c @@ -28,14 +28,14 @@ #include <stdlib.h> #include <string.h> #include <assert.h> +#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; @@ -54,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 diff --git a/mesalib/src/mapi/table.h b/mesalib/src/mapi/table.h index df59aed4f..e2d6ef03d 100644 --- a/mesalib/src/mapi/table.h +++ b/mesalib/src/mapi/table.h @@ -28,7 +28,7 @@ #ifndef _TABLE_H_ #define _TABLE_H_ -#include "u_compiler.h" +#include "c99_compat.h" #include "entry.h" #define MAPI_TMP_TABLE @@ -37,12 +37,14 @@ #define MAPI_TABLE_NUM_SLOTS (MAPI_TABLE_NUM_STATIC + MAPI_TABLE_NUM_DYNAMIC) #define MAPI_TABLE_SIZE (MAPI_TABLE_NUM_SLOTS * sizeof(mapi_func)) +struct mapi_table; + extern const mapi_func table_noop_array[]; /** * Get the no-op dispatch table. */ -static INLINE const struct mapi_table * +static inline const struct mapi_table * table_get_noop(void) { return (const struct mapi_table *) table_noop_array; @@ -51,7 +53,7 @@ table_get_noop(void) /** * Set the function of a slot. */ -static INLINE void +static inline void table_set_func(struct mapi_table *tbl, int slot, mapi_func func) { mapi_func *funcs = (mapi_func *) tbl; @@ -61,7 +63,7 @@ table_set_func(struct mapi_table *tbl, int slot, mapi_func func) /** * Return the function of a slot. */ -static INLINE mapi_func +static inline mapi_func table_get_func(const struct mapi_table *tbl, int slot) { const mapi_func *funcs = (const mapi_func *) tbl; diff --git a/mesalib/src/mapi/u_compiler.h b/mesalib/src/mapi/u_compiler.h deleted file mode 100644 index f376e97a0..000000000 --- a/mesalib/src/mapi/u_compiler.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _U_COMPILER_H_ -#define _U_COMPILER_H_ - -#include "c99_compat.h" /* inline, __func__, etc. */ - - -/* XXX: Use standard `inline` keyword instead */ -#ifndef INLINE -# define INLINE inline -#endif - -/* Function visibility */ -#ifndef PUBLIC -# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) -# define PUBLIC __attribute__((visibility("default"))) -# elif defined(_MSC_VER) -# define PUBLIC __declspec(dllexport) -# else -# define PUBLIC -# endif -#endif - -#ifndef likely -# if defined(__GNUC__) -# define likely(x) __builtin_expect(!!(x), 1) -# define unlikely(x) __builtin_expect(!!(x), 0) -# else -# define likely(x) (x) -# define unlikely(x) (x) -# endif -#endif - -#endif /* _U_COMPILER_H_ */ diff --git a/mesalib/src/mapi/u_current.c b/mesalib/src/mapi/u_current.c index afa887e06..7e7e275f2 100644 --- a/mesalib/src/mapi/u_current.c +++ b/mesalib/src/mapi/u_current.c @@ -48,8 +48,8 @@ * drivers! No changes to the public glapi interface. */ +#include "c11/threads.h" #include "u_current.h" -#include "u_thread.h" #ifndef MAPI_MODE_UTIL @@ -112,11 +112,9 @@ struct mapi_table *u_current_table = (struct mapi_table *) table_noop_array; void *u_current_context; -#ifdef THREADS -struct u_tsd u_current_table_tsd; -static struct u_tsd u_current_context_tsd; +tss_t u_current_table_tsd; +static tss_t u_current_context_tsd; static int ThreadSafe; -#endif /* THREADS */ #endif /* defined(GLX_USE_TLS) */ /*@}*/ @@ -125,20 +123,20 @@ static int ThreadSafe; void u_current_destroy(void) { -#if defined(THREADS) && defined(_WIN32) - u_tsd_destroy(&u_current_table_tsd); - u_tsd_destroy(&u_current_context_tsd); +#if !defined(GLX_USE_TLS) + tss_delete(u_current_table_tsd); + tss_delete(u_current_context_tsd); #endif } -#if defined(THREADS) && !defined(GLX_USE_TLS) +#if !defined(GLX_USE_TLS) static void u_current_init_tsd(void) { - u_tsd_init(&u_current_table_tsd); - u_tsd_init(&u_current_context_tsd); + tss_create(&u_current_table_tsd, NULL); + tss_create(&u_current_context_tsd, NULL); } /** @@ -146,6 +144,43 @@ u_current_init_tsd(void) */ static mtx_t ThreadCheckMutex = _MTX_INITIALIZER_NP; + +#ifdef _WIN32 +typedef DWORD thread_id; +#else +typedef thrd_t thread_id; +#endif + + +static inline thread_id +get_thread_id(void) +{ + /* + * XXX: Callers of of this function assume it is a lightweight function. + * But unfortunately C11's thrd_current() gives no such guarantees. In + * fact, it's pretty hard to have a compliant implementation of + * thrd_current() on Windows with such characteristics. So for now, we + * side-step this mess and use Windows thread primitives directly here. + */ +#ifdef _WIN32 + return GetCurrentThreadId(); +#else + return thrd_current(); +#endif +} + + +static inline int +thread_id_equal(thread_id t1, thread_id t2) +{ +#ifdef _WIN32 + return t1 == t2; +#else + return thrd_equal(t1, t2); +#endif +} + + /** * We should call this periodically from a function such as glXMakeCurrent * in order to test if multiple threads are being used. @@ -153,7 +188,7 @@ static mtx_t ThreadCheckMutex = _MTX_INITIALIZER_NP; void u_current_init(void) { - static unsigned long knownID; + static thread_id knownID; static int firstCall = 1; if (ThreadSafe) @@ -163,10 +198,10 @@ u_current_init(void) if (firstCall) { u_current_init_tsd(); - knownID = u_thread_self(); + knownID = get_thread_id(); firstCall = 0; } - else if (knownID != u_thread_self()) { + else if (!thread_id_equal(knownID, get_thread_id())) { ThreadSafe = 1; u_current_set_table(NULL); u_current_set_context(NULL); @@ -197,11 +232,9 @@ u_current_set_context(const void *ptr) #if defined(GLX_USE_TLS) u_current_context = (void *) ptr; -#elif defined(THREADS) - u_tsd_set(&u_current_context_tsd, (void *) ptr); - u_current_context = (ThreadSafe) ? NULL : (void *) ptr; #else - u_current_context = (void *) ptr; + tss_set(u_current_context_tsd, (void *) ptr); + u_current_context = (ThreadSafe) ? NULL : (void *) ptr; #endif } @@ -215,12 +248,8 @@ u_current_get_context_internal(void) { #if defined(GLX_USE_TLS) return u_current_context; -#elif defined(THREADS) - return (ThreadSafe) - ? u_tsd_get(&u_current_context_tsd) - : u_current_context; #else - return u_current_context; + return ThreadSafe ? tss_get(u_current_context_tsd) : u_current_context; #endif } @@ -241,11 +270,9 @@ u_current_set_table(const struct mapi_table *tbl) #if defined(GLX_USE_TLS) u_current_table = (struct mapi_table *) tbl; -#elif defined(THREADS) - u_tsd_set(&u_current_table_tsd, (void *) tbl); - u_current_table = (ThreadSafe) ? NULL : (void *) tbl; #else - u_current_table = (struct mapi_table *) tbl; + tss_set(u_current_table_tsd, (void *) tbl); + u_current_table = (ThreadSafe) ? NULL : (void *) tbl; #endif } @@ -257,10 +284,10 @@ u_current_get_table_internal(void) { #if defined(GLX_USE_TLS) return u_current_table; -#elif defined(THREADS) - return (struct mapi_table *) ((ThreadSafe) ? - u_tsd_get(&u_current_table_tsd) : (void *) u_current_table); #else - return u_current_table; + if (ThreadSafe) + return (struct mapi_table *) tss_get(u_current_table_tsd); + else + return (struct mapi_table *) u_current_table; #endif } diff --git a/mesalib/src/mapi/u_current.h b/mesalib/src/mapi/u_current.h index 72708d433..ea4f81723 100644 --- a/mesalib/src/mapi/u_current.h +++ b/mesalib/src/mapi/u_current.h @@ -1,6 +1,10 @@ #ifndef _U_CURRENT_H_ #define _U_CURRENT_H_ +#include "c99_compat.h" +#include "util/macros.h" + + #if defined(MAPI_MODE_UTIL) || defined(MAPI_MODE_GLAPI) || \ defined(MAPI_MODE_BRIDGE) @@ -24,8 +28,6 @@ #else /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */ -#include "u_compiler.h" - struct mapi_table; #ifdef GLX_USE_TLS @@ -63,7 +65,7 @@ u_current_set_context(const void *ptr); void * u_current_get_context_internal(void); -static INLINE const struct mapi_table * +static inline const struct mapi_table * u_current_get_table(void) { #ifdef GLX_USE_TLS @@ -74,7 +76,7 @@ u_current_get_table(void) #endif } -static INLINE const void * +static inline const void * u_current_get_context(void) { #ifdef GLX_USE_TLS diff --git a/mesalib/src/mapi/u_execmem.c b/mesalib/src/mapi/u_execmem.c index ac1cae093..89d5c1d08 100644 --- a/mesalib/src/mapi/u_execmem.c +++ b/mesalib/src/mapi/u_execmem.c @@ -32,8 +32,8 @@ */ -#include "u_compiler.h" -#include "u_thread.h" +#include "c99_compat.h" +#include "c11/threads.h" #include "u_execmem.h" diff --git a/mesalib/src/mapi/u_macros.h b/mesalib/src/mapi/u_macros.h deleted file mode 100644 index 72345b5f1..000000000 --- a/mesalib/src/mapi/u_macros.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _U_MACROS_ -#define _U_MACROS_ - -#define _U_STRINGIFY(x) #x -#define _U_CONCAT(x, y) x ## y -#define _U_CONCAT_STR(x, y) #x#y - -#define U_STRINGIFY(x) _U_STRINGIFY(x) -#define U_CONCAT(x, y) _U_CONCAT(x, y) -#define U_CONCAT_STR(x, y) _U_CONCAT_STR(x, y) - -#endif /* _U_MACROS_ */ diff --git a/mesalib/src/mapi/u_thread.h b/mesalib/src/mapi/u_thread.h deleted file mode 100644 index 57c3b076a..000000000 --- a/mesalib/src/mapi/u_thread.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -/* - * Thread support for gl dispatch. - * - * Initial version by John Stone (j.stone@acm.org) (johns@cs.umr.edu) - * and Christoph Poliwoda (poliwoda@volumegraphics.com) - * Revised by Keith Whitwell - * Adapted for new gl dispatcher by Brian Paul - * Modified for use in mapi by Chia-I Wu - */ - -/* - * If this file is accidentally included by a non-threaded build, - * it should not cause the build to fail, or otherwise cause problems. - * In general, it should only be included when needed however. - */ - -#ifndef _U_THREAD_H_ -#define _U_THREAD_H_ - -#include <stdio.h> -#include <stdlib.h> -#include "u_compiler.h" - -#include "c11/threads.h" - -#if defined(HAVE_PTHREAD) || defined(_WIN32) -#ifndef THREADS -#define THREADS -#endif -#endif - -/* - * Error messages - */ -#define INIT_TSD_ERROR "Mesa: failed to allocate key for thread specific data" -#define GET_TSD_ERROR "Mesa: failed to get thread specific data" -#define SET_TSD_ERROR "Mesa: thread failed to set thread specific data" - - -/* - * Magic number to determine if a TSD object has been initialized. - * Kind of a hack but there doesn't appear to be a better cross-platform - * solution. - */ -#define INIT_MAGIC 0xff8adc98 - -#ifdef __cplusplus -extern "C" { -#endif - - -struct u_tsd { - tss_t key; - unsigned initMagic; -}; - - -static INLINE unsigned long -u_thread_self(void) -{ - /* - * XXX: Callers of u_thread_self assume it is a lightweight function, - * returning a numeric value. But unfortunately C11's thrd_current() gives - * no such guarantees. In fact, it's pretty hard to have a compliant - * implementation of thrd_current() on Windows with such characteristics. - * So for now, we side-step this mess and use Windows thread primitives - * directly here. - * - * FIXME: On the other hand, u_thread_self() is a bad - * abstraction. Even with pthreads, there is no guarantee that - * pthread_self() will return numeric IDs -- we should be using - * pthread_equal() instead of assuming we can compare thread ids... - */ -#ifdef _WIN32 - return GetCurrentThreadId(); -#else - return (unsigned long) (uintptr_t) thrd_current(); -#endif -} - - -static INLINE void -u_tsd_init(struct u_tsd *tsd) -{ - if (tss_create(&tsd->key, NULL/*free*/) != 0) { - perror(INIT_TSD_ERROR); - exit(-1); - } - tsd->initMagic = INIT_MAGIC; -} - - -static INLINE void * -u_tsd_get(struct u_tsd *tsd) -{ - if (tsd->initMagic != INIT_MAGIC) { - u_tsd_init(tsd); - } - return tss_get(tsd->key); -} - - -static INLINE void -u_tsd_set(struct u_tsd *tsd, void *ptr) -{ - if (tsd->initMagic != INIT_MAGIC) { - u_tsd_init(tsd); - } - if (tss_set(tsd->key, ptr) != 0) { - perror(SET_TSD_ERROR); - exit(-1); - } -} - - -static INLINE void -u_tsd_destroy(struct u_tsd *tsd) -{ - if (tsd->initMagic != INIT_MAGIC) { - return; - } - tss_delete(tsd->key); - tsd->initMagic = 0x0; -} - - -#ifdef __cplusplus -} -#endif - -#endif /* _U_THREAD_H_ */ |