1 #ifndef _U_CURRENT_H_ 2 #define _U_CURRENT_H_ 3 4 #include "c99_compat.h" 5 #include "util/macros.h" 6 7 8 #if defined(MAPI_MODE_UTIL) || defined(MAPI_MODE_GLAPI) || \ 9 defined(MAPI_MODE_BRIDGE) 10 11 #include "glapi/glapi.h" 12 13 #ifdef GLX_USE_TLS 14 #define u_current_table _glapi_tls_Dispatch 15 #define u_current_context _glapi_tls_Context 16 #else 17 #define u_current_table _glapi_Dispatch 18 #define u_current_context _glapi_Context 19 #endif 20 21 #define u_current_get_table_internal _glapi_get_dispatch 22 #define u_current_get_context_internal _glapi_get_context 23 24 #define u_current_table_tsd _gl_DispatchTSD 25 26 #else /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */ 27 28 struct _glapi_table; 29 30 #ifdef GLX_USE_TLS 31 32 extern __thread struct _glapi_table *u_current_table 33 __attribute__((tls_model("initial-exec"))); 34 35 extern __thread void *u_current_context 36 __attribute__((tls_model("initial-exec"))); 37 38 #else /* GLX_USE_TLS */ 39 40 extern struct _glapi_table *u_current_table; 41 extern void *u_current_context; 42 43 #endif /* GLX_USE_TLS */ 44 45 #endif /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */ 46 47 void 48 u_current_init(void); 49 50 void 51 u_current_destroy(void); 52 53 void 54 u_current_set_table(const struct _glapi_table *tbl); 55 56 struct _glapi_table * 57 u_current_get_table_internal(void); 58 59 void 60 u_current_set_context(const void *ptr); 61 62 void * 63 u_current_get_context_internal(void); 64 65 static inline const struct _glapi_table * u_current_get_table(void)66u_current_get_table(void) 67 { 68 #ifdef GLX_USE_TLS 69 return u_current_table; 70 #else 71 return (likely(u_current_table) ? 72 u_current_table : u_current_get_table_internal()); 73 #endif 74 } 75 76 static inline const void * u_current_get_context(void)77u_current_get_context(void) 78 { 79 #ifdef GLX_USE_TLS 80 return u_current_context; 81 #else 82 return likely(u_current_context) ? u_current_context : u_current_get_context_internal(); 83 #endif 84 } 85 86 #endif /* _U_CURRENT_H_ */ 87