diff options
author | Chia-I Wu <olv@lunarg.com> | 2010-12-10 17:14:04 +0800 |
---|---|---|
committer | Chia-I Wu <olv@lunarg.com> | 2010-12-18 15:05:52 +0800 |
commit | c17d4999f108d86c468cf4b11b08f915c282ce12 (patch) | |
tree | ebe64e1ef25fef106b66b188a317c84cbe21a709 | |
parent | c7119e281b21bcfc88e5fdce2a5d8ebdbf6c6b62 (diff) |
mapi: Clean up u_current interface.
Try not to use macros to make u_current.h appear to be glapi.h. Use
u_current.h to implement glapi.h instead whenever possible.
-rw-r--r-- | src/mapi/es1api/Makefile | 2 | ||||
-rw-r--r-- | src/mapi/glapi/Makefile | 2 | ||||
-rw-r--r-- | src/mapi/glapi/SConscript | 1 | ||||
-rw-r--r-- | src/mapi/glapi/glapi.c | 65 | ||||
-rw-r--r-- | src/mapi/glapi/sources.mak | 3 | ||||
-rw-r--r-- | src/mapi/mapi/entry_x86-64_tls.h | 4 | ||||
-rw-r--r-- | src/mapi/mapi/entry_x86_tls.h | 2 | ||||
-rw-r--r-- | src/mapi/mapi/u_current.c | 35 | ||||
-rw-r--r-- | src/mapi/mapi/u_current.h | 46 |
9 files changed, 104 insertions, 56 deletions
diff --git a/src/mapi/es1api/Makefile b/src/mapi/es1api/Makefile index 576ac5afdc..1e2b5e523b 100644 --- a/src/mapi/es1api/Makefile +++ b/src/mapi/es1api/Makefile @@ -72,7 +72,7 @@ lib$(ESAPI).a: $(ESAPI_OBJECTS) @$(MKLIB) -o $(ESAPI) -static $(ESAPI_OBJECTS) $(GLAPI_OBJECTS): %.o: $(GLAPI)/%.c - $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) -DMAPI_GLAPI_CURRENT $< -o $@ $(GLAPI_ASM_OBJECTS): %.o: $(GEN)/%.S $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ diff --git a/src/mapi/glapi/Makefile b/src/mapi/glapi/Makefile index ca9381d425..acd8429778 100644 --- a/src/mapi/glapi/Makefile +++ b/src/mapi/glapi/Makefile @@ -28,7 +28,7 @@ lib$(TARGET).a: $(TARGET_OBJECTS) @$(MKLIB) -o $(TARGET) -static $(TARGET_OBJECTS) $(GLAPI_OBJECTS): %.o: %.c - $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) -DMAPI_GLAPI_CURRENT $< -o $@ $(GLAPI_ASM_OBJECTS): %.o: %.S $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ diff --git a/src/mapi/glapi/SConscript b/src/mapi/glapi/SConscript index 4ef855fc35..27258f808a 100644 --- a/src/mapi/glapi/SConscript +++ b/src/mapi/glapi/SConscript @@ -29,6 +29,7 @@ if env['platform'] != 'winddk': 'glapi_getproc.c', 'glapi_nop.c', 'glthread.c', + 'glapi.c', ] mapi_sources = [ diff --git a/src/mapi/glapi/glapi.c b/src/mapi/glapi/glapi.c new file mode 100644 index 0000000000..f7655c558c --- /dev/null +++ b/src/mapi/glapi/glapi.c @@ -0,0 +1,65 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * 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. + * + * Authors: + * Chia-I Wu <olv@lunarg.com> + */ + +#include "glapi/glapi.h" +#include "mapi/u_current.h" + +/* + * Global variables, _glapi_get_context, and _glapi_get_dispatch are defined in + * u_current.c. + */ + +#ifdef GLX_USE_TLS +/* not used, but defined for compatibility */ +const struct _glapi_table *_glapi_Dispatch; +const void *_glapi_Context; +#endif /* GLX_USE_TLS */ + +void +_glapi_destroy_multithread(void) +{ + u_current_destroy(); +} + +void +_glapi_check_multithread(void) +{ + u_current_init(); +} + +void +_glapi_set_context(void *context) +{ + u_current_set_user((const void *) context); +} + +void +_glapi_set_dispatch(struct _glapi_table *dispatch) +{ + u_current_set((const struct mapi_table *) dispatch); +} diff --git a/src/mapi/glapi/sources.mak b/src/mapi/glapi/sources.mak index cdcfa36e51..0b4d8cf65d 100644 --- a/src/mapi/glapi/sources.mak +++ b/src/mapi/glapi/sources.mak @@ -5,7 +5,8 @@ GLAPI_SOURCES = \ glapi_entrypoint.c \ glapi_getproc.c \ glapi_nop.c \ - glthread.c + glthread.c \ + glapi.c X86_API = \ glapi_x86.S diff --git a/src/mapi/mapi/entry_x86-64_tls.h b/src/mapi/mapi/entry_x86-64_tls.h index cc3d5a8d7e..2c02933802 100644 --- a/src/mapi/mapi/entry_x86-64_tls.h +++ b/src/mapi/mapi/entry_x86-64_tls.h @@ -46,7 +46,7 @@ __asm__(".section .note.ABI-tag, \"a\"\n\t" __asm__(".text"); __asm__("x86_64_current_tls:\n\t" - "movq u_current_table_tls@GOTTPOFF(%rip), %rax\n\t" + "movq u_current_table@GOTTPOFF(%rip), %rax\n\t" "ret"); #define STUB_ASM_ENTRY(func) \ @@ -56,7 +56,7 @@ __asm__("x86_64_current_tls:\n\t" func ":" #define STUB_ASM_CODE(slot) \ - "movq u_current_table_tls@GOTTPOFF(%rip), %rax\n\t" \ + "movq u_current_table@GOTTPOFF(%rip), %rax\n\t" \ "movq %fs:(%rax), %r11\n\t" \ "jmp *(8 * " slot ")(%r11)" diff --git a/src/mapi/mapi/entry_x86_tls.h b/src/mapi/mapi/entry_x86_tls.h index 9a1f6e4ec4..3d0b7caffe 100644 --- a/src/mapi/mapi/entry_x86_tls.h +++ b/src/mapi/mapi/entry_x86_tls.h @@ -50,7 +50,7 @@ __asm__("x86_current_tls:\n\t" "1:\n\t" "popl %eax\n\t" "addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax\n\t" - "movl u_current_table_tls@GOTNTPOFF(%eax), %eax\n\t" + "movl u_current_table@GOTNTPOFF(%eax), %eax\n\t" "ret"); #ifndef GLX_X86_READONLY_TEXT diff --git a/src/mapi/mapi/u_current.c b/src/mapi/mapi/u_current.c index 77a593b330..d84520f313 100644 --- a/src/mapi/mapi/u_current.c +++ b/src/mapi/mapi/u_current.c @@ -99,16 +99,13 @@ extern void (*__glapi_noop_table[])(void); /*@{*/ #if defined(GLX_USE_TLS) -__thread struct mapi_table *u_current_table_tls +__thread struct mapi_table *u_current_table __attribute__((tls_model("initial-exec"))) = (struct mapi_table *) table_noop_array; -__thread void *u_current_user_tls +__thread void *u_current_user __attribute__((tls_model("initial-exec"))); -const struct mapi_table *u_current_table; -const void *u_current_user; - #else struct mapi_table *u_current_table = @@ -179,8 +176,8 @@ u_current_init(void) } else if (knownID != u_thread_self()) { ThreadSafe = 1; - u_current_set_internal(NULL); - u_current_set_user_internal(NULL); + u_current_set(NULL); + u_current_set_user(NULL); } CHECK_MULTITHREAD_UNLOCK(); } @@ -202,17 +199,17 @@ u_current_init(void) * void from the real context pointer type. */ void -u_current_set_user_internal(void *ptr) +u_current_set_user(const void *ptr) { u_current_init(); #if defined(GLX_USE_TLS) - u_current_user_tls = ptr; + u_current_user = (void *) ptr; #elif defined(THREADS) - u_tsd_set(&u_current_user_tsd, ptr); - u_current_user = (ThreadSafe) ? NULL : ptr; + u_tsd_set(&u_current_user_tsd, (void *) ptr); + u_current_user = (ThreadSafe) ? NULL : (void *) ptr; #else - u_current_user = ptr; + u_current_user = (void *) ptr; #endif } @@ -225,7 +222,7 @@ void * u_current_get_user_internal(void) { #if defined(GLX_USE_TLS) - return u_current_user_tls; + return u_current_user; #elif defined(THREADS) return (ThreadSafe) ? u_tsd_get(&u_current_user_tsd) @@ -241,22 +238,22 @@ u_current_get_user_internal(void) * table (__glapi_noop_table). */ void -u_current_set_internal(struct mapi_table *tbl) +u_current_set(const struct mapi_table *tbl) { u_current_init(); stub_init_once(); if (!tbl) - tbl = (struct mapi_table *) table_noop_array; + tbl = (const struct mapi_table *) table_noop_array; #if defined(GLX_USE_TLS) - u_current_table_tls = tbl; + u_current_table = (struct mapi_table *) tbl; #elif defined(THREADS) u_tsd_set(&u_current_table_tsd, (void *) tbl); - u_current_table = (ThreadSafe) ? NULL : tbl; + u_current_table = (ThreadSafe) ? NULL : (void *) tbl; #else - u_current_table = tbl; + u_current_table = (struct mapi_table *) tbl; #endif } @@ -267,7 +264,7 @@ struct mapi_table * u_current_get_internal(void) { #if defined(GLX_USE_TLS) - return u_current_table_tls; + return u_current_table; #elif defined(THREADS) return (struct mapi_table *) ((ThreadSafe) ? u_tsd_get(&u_current_table_tsd) : (void *) u_current_table); diff --git a/src/mapi/mapi/u_current.h b/src/mapi/mapi/u_current.h index 62e54c6c93..373d48fb93 100644 --- a/src/mapi/mapi/u_current.h +++ b/src/mapi/mapi/u_current.h @@ -8,16 +8,15 @@ /* ugly renames to match glapi.h */ #define mapi_table _glapi_table -#define u_current_table_tls _glapi_tls_Dispatch -#define u_current_user_tls _glapi_tls_Context +#ifdef GLX_USE_TLS +#define u_current_table _glapi_tls_Dispatch +#define u_current_user _glapi_tls_Context +#else #define u_current_table _glapi_Dispatch #define u_current_user _glapi_Context +#endif -#define u_current_destroy _glapi_destroy_multithread -#define u_current_init _glapi_check_multithread -#define u_current_set_internal _glapi_set_dispatch #define u_current_get_internal _glapi_get_dispatch -#define u_current_set_user_internal _glapi_set_context #define u_current_get_user_internal _glapi_get_context #define u_current_table_tsd _gl_DispatchTSD @@ -30,15 +29,12 @@ struct mapi_table; #ifdef GLX_USE_TLS -extern __thread struct mapi_table *u_current_table_tls +extern __thread struct mapi_table *u_current_table __attribute__((tls_model("initial-exec"))); -extern __thread void *u_current_user_tls +extern __thread void *u_current_user __attribute__((tls_model("initial-exec"))); -extern const struct mapi_table *u_current_table; -extern const void *u_current_user; - #else /* GLX_USE_TLS */ extern struct mapi_table *u_current_table; @@ -46,6 +42,8 @@ extern void *u_current_user; #endif /* GLX_USE_TLS */ +#endif /* MAPI_GLAPI_CURRENT */ + void u_current_init(void); @@ -53,50 +51,36 @@ void u_current_destroy(void); void -u_current_set_internal(struct mapi_table *tbl); +u_current_set(const struct mapi_table *tbl); struct mapi_table * u_current_get_internal(void); void -u_current_set_user_internal(void *ptr); +u_current_set_user(const void *ptr); void * u_current_get_user_internal(void); -static INLINE void -u_current_set(const struct mapi_table *tbl) -{ - u_current_set_internal((struct mapi_table *) tbl); -} - static INLINE const struct mapi_table * u_current_get(void) { #ifdef GLX_USE_TLS - return (const struct mapi_table *) u_current_table_tls; + return u_current_table; #else return (likely(u_current_table) ? - (const struct mapi_table *) u_current_table : u_current_get_internal()); + u_current_table : u_current_get_internal()); #endif } -static INLINE void -u_current_set_user(void *ptr) -{ - u_current_set_internal(ptr); -} - -static INLINE void * +static INLINE const void * u_current_get_user(void) { #ifdef GLX_USE_TLS - return u_current_user_tls; + return u_current_user; #else return likely(u_current_user) ? u_current_user : u_current_get_user_internal(); #endif } -#endif /* MAPI_GLAPI_CURRENT */ - #endif /* _U_CURRENT_H_ */ |