From c17d4999f108d86c468cf4b11b08f915c282ce12 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 10 Dec 2010 17:14:04 +0800 Subject: 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. --- src/mapi/mapi/entry_x86-64_tls.h | 4 ++-- src/mapi/mapi/entry_x86_tls.h | 2 +- src/mapi/mapi/u_current.c | 35 ++++++++++++++---------------- src/mapi/mapi/u_current.h | 46 +++++++++++++--------------------------- 4 files changed, 34 insertions(+), 53 deletions(-) (limited to 'src/mapi/mapi') 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_ */ -- cgit v1.2.3