Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 1 | #ifndef _U_CURRENT_H_ |
2 | #define _U_CURRENT_H_ | ||||
3 | |||||
Brian Paul | 8aa9191 | 2015-03-03 17:15:05 -0700 | [diff] [blame] | 4 | #include "c99_compat.h" |
5 | #include "util/macros.h" | ||||
6 | |||||
7 | |||||
Chia-I Wu | 97185bf | 2010-12-17 00:24:27 +0800 | [diff] [blame] | 8 | #if defined(MAPI_MODE_UTIL) || defined(MAPI_MODE_GLAPI) || \ |
9 | defined(MAPI_MODE_BRIDGE) | ||||
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 10 | |
Chia-I Wu | 760451b | 2010-08-21 11:50:22 +0800 | [diff] [blame] | 11 | #include "glapi/glapi.h" |
12 | |||||
Chia-I Wu | c17d499 | 2010-12-10 17:14:04 +0800 | [diff] [blame] | 13 | #ifdef GLX_USE_TLS |
14 | #define u_current_table _glapi_tls_Dispatch | ||||
Brian Paul | 280e065 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 15 | #define u_current_context _glapi_tls_Context |
Chia-I Wu | c17d499 | 2010-12-10 17:14:04 +0800 | [diff] [blame] | 16 | #else |
Chia-I Wu | df98423 | 2010-08-21 12:10:02 +0800 | [diff] [blame] | 17 | #define u_current_table _glapi_Dispatch |
Brian Paul | 280e065 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 18 | #define u_current_context _glapi_Context |
Chia-I Wu | c17d499 | 2010-12-10 17:14:04 +0800 | [diff] [blame] | 19 | #endif |
Chia-I Wu | df98423 | 2010-08-21 12:10:02 +0800 | [diff] [blame] | 20 | |
Brian Paul | 846a7e8 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 21 | #define u_current_get_table_internal _glapi_get_dispatch |
Brian Paul | 280e065 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 22 | #define u_current_get_context_internal _glapi_get_context |
Chia-I Wu | df98423 | 2010-08-21 12:10:02 +0800 | [diff] [blame] | 23 | |
24 | #define u_current_table_tsd _gl_DispatchTSD | ||||
25 | |||||
Chia-I Wu | 97185bf | 2010-12-17 00:24:27 +0800 | [diff] [blame] | 26 | #else /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */ |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 27 | |
Emil Velikov | 4562d88 | 2017-04-13 18:23:50 +0100 | [diff] [blame] | 28 | struct _glapi_table; |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 29 | |
30 | #ifdef GLX_USE_TLS | ||||
31 | |||||
Emil Velikov | 4562d88 | 2017-04-13 18:23:50 +0100 | [diff] [blame] | 32 | extern __thread struct _glapi_table *u_current_table |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 33 | __attribute__((tls_model("initial-exec"))); |
34 | |||||
Brian Paul | 280e065 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 35 | extern __thread void *u_current_context |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 36 | __attribute__((tls_model("initial-exec"))); |
37 | |||||
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 38 | #else /* GLX_USE_TLS */ |
39 | |||||
Emil Velikov | 4562d88 | 2017-04-13 18:23:50 +0100 | [diff] [blame] | 40 | extern struct _glapi_table *u_current_table; |
Brian Paul | 280e065 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 41 | extern void *u_current_context; |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 42 | |
43 | #endif /* GLX_USE_TLS */ | ||||
44 | |||||
Chia-I Wu | 97185bf | 2010-12-17 00:24:27 +0800 | [diff] [blame] | 45 | #endif /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */ |
Chia-I Wu | c17d499 | 2010-12-10 17:14:04 +0800 | [diff] [blame] | 46 | |
Chia-I Wu | 760451b | 2010-08-21 11:50:22 +0800 | [diff] [blame] | 47 | void |
Chia-I Wu | df98423 | 2010-08-21 12:10:02 +0800 | [diff] [blame] | 48 | u_current_init(void); |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 49 | |
Chia-I Wu | 760451b | 2010-08-21 11:50:22 +0800 | [diff] [blame] | 50 | void |
Chia-I Wu | df98423 | 2010-08-21 12:10:02 +0800 | [diff] [blame] | 51 | u_current_destroy(void); |
52 | |||||
53 | void | ||||
Emil Velikov | 4562d88 | 2017-04-13 18:23:50 +0100 | [diff] [blame] | 54 | u_current_set_table(const struct _glapi_table *tbl); |
Chia-I Wu | df98423 | 2010-08-21 12:10:02 +0800 | [diff] [blame] | 55 | |
Emil Velikov | 4562d88 | 2017-04-13 18:23:50 +0100 | [diff] [blame] | 56 | struct _glapi_table * |
Brian Paul | 846a7e8 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 57 | u_current_get_table_internal(void); |
Chia-I Wu | df98423 | 2010-08-21 12:10:02 +0800 | [diff] [blame] | 58 | |
59 | void | ||||
Brian Paul | 280e065 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 60 | u_current_set_context(const void *ptr); |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 61 | |
Chia-I Wu | 760451b | 2010-08-21 11:50:22 +0800 | [diff] [blame] | 62 | void * |
Brian Paul | 280e065 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 63 | u_current_get_context_internal(void); |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 64 | |
Emil Velikov | 4562d88 | 2017-04-13 18:23:50 +0100 | [diff] [blame] | 65 | static inline const struct _glapi_table * |
Brian Paul | 846a7e8 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 66 | u_current_get_table(void) |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 67 | { |
68 | #ifdef GLX_USE_TLS | ||||
Chia-I Wu | c17d499 | 2010-12-10 17:14:04 +0800 | [diff] [blame] | 69 | return u_current_table; |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 70 | #else |
Chia-I Wu | df98423 | 2010-08-21 12:10:02 +0800 | [diff] [blame] | 71 | return (likely(u_current_table) ? |
Brian Paul | 846a7e8 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 72 | u_current_table : u_current_get_table_internal()); |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 73 | #endif |
74 | } | ||||
75 | |||||
Brian Paul | 41c87cc | 2015-03-03 09:08:22 -0700 | [diff] [blame] | 76 | static inline const void * |
Brian Paul | 280e065 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 77 | u_current_get_context(void) |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 78 | { |
79 | #ifdef GLX_USE_TLS | ||||
Brian Paul | 280e065 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 80 | return u_current_context; |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 81 | #else |
Brian Paul | 280e065 | 2014-03-05 07:47:41 -0700 | [diff] [blame] | 82 | return likely(u_current_context) ? u_current_context : u_current_get_context_internal(); |
Chia-I Wu | a73c654 | 2010-04-23 16:06:26 +0800 | [diff] [blame] | 83 | #endif |
84 | } | ||||
85 | |||||
Chia-I Wu | 760451b | 2010-08-21 11:50:22 +0800 | [diff] [blame] | 86 | #endif /* _U_CURRENT_H_ */ |