u_current.h revision 01e04c3f
1af69d88dSmrg#ifndef _U_CURRENT_H_
2af69d88dSmrg#define _U_CURRENT_H_
3af69d88dSmrg
401e04c3fSmrg#include "c99_compat.h"
501e04c3fSmrg#include "util/macros.h"
601e04c3fSmrg
701e04c3fSmrg
8af69d88dSmrg#if defined(MAPI_MODE_UTIL) || defined(MAPI_MODE_GLAPI) || \
9af69d88dSmrg    defined(MAPI_MODE_BRIDGE)
10af69d88dSmrg
11af69d88dSmrg#include "glapi/glapi.h"
12af69d88dSmrg
13af69d88dSmrg#ifdef GLX_USE_TLS
14af69d88dSmrg#define u_current_table _glapi_tls_Dispatch
15af69d88dSmrg#define u_current_context _glapi_tls_Context
16af69d88dSmrg#else
17af69d88dSmrg#define u_current_table _glapi_Dispatch
18af69d88dSmrg#define u_current_context _glapi_Context
19af69d88dSmrg#endif
20af69d88dSmrg
21af69d88dSmrg#define u_current_get_table_internal _glapi_get_dispatch
22af69d88dSmrg#define u_current_get_context_internal _glapi_get_context
23af69d88dSmrg
24af69d88dSmrg#define u_current_table_tsd _gl_DispatchTSD
25af69d88dSmrg
26af69d88dSmrg#else /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */
27af69d88dSmrg
2801e04c3fSmrgstruct _glapi_table;
29af69d88dSmrg
30af69d88dSmrg#ifdef GLX_USE_TLS
31af69d88dSmrg
3201e04c3fSmrgextern __thread struct _glapi_table *u_current_table
33af69d88dSmrg    __attribute__((tls_model("initial-exec")));
34af69d88dSmrg
35af69d88dSmrgextern __thread void *u_current_context
36af69d88dSmrg    __attribute__((tls_model("initial-exec")));
37af69d88dSmrg
38af69d88dSmrg#else /* GLX_USE_TLS */
39af69d88dSmrg
4001e04c3fSmrgextern struct _glapi_table *u_current_table;
41af69d88dSmrgextern void *u_current_context;
42af69d88dSmrg
43af69d88dSmrg#endif /* GLX_USE_TLS */
44af69d88dSmrg
45af69d88dSmrg#endif /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */
46af69d88dSmrg
47af69d88dSmrgvoid
48af69d88dSmrgu_current_init(void);
49af69d88dSmrg
50af69d88dSmrgvoid
51af69d88dSmrgu_current_destroy(void);
52af69d88dSmrg
53af69d88dSmrgvoid
5401e04c3fSmrgu_current_set_table(const struct _glapi_table *tbl);
55af69d88dSmrg
5601e04c3fSmrgstruct _glapi_table *
57af69d88dSmrgu_current_get_table_internal(void);
58af69d88dSmrg
59af69d88dSmrgvoid
60af69d88dSmrgu_current_set_context(const void *ptr);
61af69d88dSmrg
62af69d88dSmrgvoid *
63af69d88dSmrgu_current_get_context_internal(void);
64af69d88dSmrg
6501e04c3fSmrgstatic inline const struct _glapi_table *
66af69d88dSmrgu_current_get_table(void)
67af69d88dSmrg{
68af69d88dSmrg#ifdef GLX_USE_TLS
69af69d88dSmrg   return u_current_table;
70af69d88dSmrg#else
71af69d88dSmrg   return (likely(u_current_table) ?
72af69d88dSmrg         u_current_table : u_current_get_table_internal());
73af69d88dSmrg#endif
74af69d88dSmrg}
75af69d88dSmrg
7601e04c3fSmrgstatic inline const void *
77af69d88dSmrgu_current_get_context(void)
78af69d88dSmrg{
79af69d88dSmrg#ifdef GLX_USE_TLS
80af69d88dSmrg   return u_current_context;
81af69d88dSmrg#else
82af69d88dSmrg   return likely(u_current_context) ? u_current_context : u_current_get_context_internal();
83af69d88dSmrg#endif
84af69d88dSmrg}
85af69d88dSmrg
86af69d88dSmrg#endif /* _U_CURRENT_H_ */
87