blob: 3c9a414ee84d86d3062be9302677a1cd381eb3a7 [file] [log] [blame]
Chia-I Wua73c6542010-04-23 16:06:26 +08001#ifndef _U_CURRENT_H_
2#define _U_CURRENT_H_
3
Brian Paul8aa91912015-03-03 17:15:05 -07004#include "c99_compat.h"
5#include "util/macros.h"
6
7
Chia-I Wu97185bf2010-12-17 00:24:27 +08008#if defined(MAPI_MODE_UTIL) || defined(MAPI_MODE_GLAPI) || \
9 defined(MAPI_MODE_BRIDGE)
Chia-I Wua73c6542010-04-23 16:06:26 +080010
Chia-I Wu760451b2010-08-21 11:50:22 +080011#include "glapi/glapi.h"
12
Chia-I Wuc17d4992010-12-10 17:14:04 +080013#ifdef GLX_USE_TLS
14#define u_current_table _glapi_tls_Dispatch
Brian Paul280e0652014-03-05 07:47:41 -070015#define u_current_context _glapi_tls_Context
Chia-I Wuc17d4992010-12-10 17:14:04 +080016#else
Chia-I Wudf984232010-08-21 12:10:02 +080017#define u_current_table _glapi_Dispatch
Brian Paul280e0652014-03-05 07:47:41 -070018#define u_current_context _glapi_Context
Chia-I Wuc17d4992010-12-10 17:14:04 +080019#endif
Chia-I Wudf984232010-08-21 12:10:02 +080020
Brian Paul846a7e82014-03-05 07:47:41 -070021#define u_current_get_table_internal _glapi_get_dispatch
Brian Paul280e0652014-03-05 07:47:41 -070022#define u_current_get_context_internal _glapi_get_context
Chia-I Wudf984232010-08-21 12:10:02 +080023
24#define u_current_table_tsd _gl_DispatchTSD
25
Chia-I Wu97185bf2010-12-17 00:24:27 +080026#else /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */
Chia-I Wua73c6542010-04-23 16:06:26 +080027
Emil Velikov4562d882017-04-13 18:23:50 +010028struct _glapi_table;
Chia-I Wua73c6542010-04-23 16:06:26 +080029
30#ifdef GLX_USE_TLS
31
Emil Velikov4562d882017-04-13 18:23:50 +010032extern __thread struct _glapi_table *u_current_table
Chia-I Wua73c6542010-04-23 16:06:26 +080033 __attribute__((tls_model("initial-exec")));
34
Brian Paul280e0652014-03-05 07:47:41 -070035extern __thread void *u_current_context
Chia-I Wua73c6542010-04-23 16:06:26 +080036 __attribute__((tls_model("initial-exec")));
37
Chia-I Wua73c6542010-04-23 16:06:26 +080038#else /* GLX_USE_TLS */
39
Emil Velikov4562d882017-04-13 18:23:50 +010040extern struct _glapi_table *u_current_table;
Brian Paul280e0652014-03-05 07:47:41 -070041extern void *u_current_context;
Chia-I Wua73c6542010-04-23 16:06:26 +080042
43#endif /* GLX_USE_TLS */
44
Chia-I Wu97185bf2010-12-17 00:24:27 +080045#endif /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */
Chia-I Wuc17d4992010-12-10 17:14:04 +080046
Chia-I Wu760451b2010-08-21 11:50:22 +080047void
Chia-I Wudf984232010-08-21 12:10:02 +080048u_current_init(void);
Chia-I Wua73c6542010-04-23 16:06:26 +080049
Chia-I Wu760451b2010-08-21 11:50:22 +080050void
Chia-I Wudf984232010-08-21 12:10:02 +080051u_current_destroy(void);
52
53void
Emil Velikov4562d882017-04-13 18:23:50 +010054u_current_set_table(const struct _glapi_table *tbl);
Chia-I Wudf984232010-08-21 12:10:02 +080055
Emil Velikov4562d882017-04-13 18:23:50 +010056struct _glapi_table *
Brian Paul846a7e82014-03-05 07:47:41 -070057u_current_get_table_internal(void);
Chia-I Wudf984232010-08-21 12:10:02 +080058
59void
Brian Paul280e0652014-03-05 07:47:41 -070060u_current_set_context(const void *ptr);
Chia-I Wua73c6542010-04-23 16:06:26 +080061
Chia-I Wu760451b2010-08-21 11:50:22 +080062void *
Brian Paul280e0652014-03-05 07:47:41 -070063u_current_get_context_internal(void);
Chia-I Wua73c6542010-04-23 16:06:26 +080064
Emil Velikov4562d882017-04-13 18:23:50 +010065static inline const struct _glapi_table *
Brian Paul846a7e82014-03-05 07:47:41 -070066u_current_get_table(void)
Chia-I Wua73c6542010-04-23 16:06:26 +080067{
68#ifdef GLX_USE_TLS
Chia-I Wuc17d4992010-12-10 17:14:04 +080069 return u_current_table;
Chia-I Wua73c6542010-04-23 16:06:26 +080070#else
Chia-I Wudf984232010-08-21 12:10:02 +080071 return (likely(u_current_table) ?
Brian Paul846a7e82014-03-05 07:47:41 -070072 u_current_table : u_current_get_table_internal());
Chia-I Wua73c6542010-04-23 16:06:26 +080073#endif
74}
75
Brian Paul41c87cc2015-03-03 09:08:22 -070076static inline const void *
Brian Paul280e0652014-03-05 07:47:41 -070077u_current_get_context(void)
Chia-I Wua73c6542010-04-23 16:06:26 +080078{
79#ifdef GLX_USE_TLS
Brian Paul280e0652014-03-05 07:47:41 -070080 return u_current_context;
Chia-I Wua73c6542010-04-23 16:06:26 +080081#else
Brian Paul280e0652014-03-05 07:47:41 -070082 return likely(u_current_context) ? u_current_context : u_current_get_context_internal();
Chia-I Wua73c6542010-04-23 16:06:26 +080083#endif
84}
85
Chia-I Wu760451b2010-08-21 11:50:22 +080086#endif /* _U_CURRENT_H_ */