u_current.h revision af69d88d
1af69d88dSmrg#ifndef _U_CURRENT_H_
2af69d88dSmrg#define _U_CURRENT_H_
3af69d88dSmrg
4af69d88dSmrg#if defined(MAPI_MODE_UTIL) || defined(MAPI_MODE_GLAPI) || \
5af69d88dSmrg    defined(MAPI_MODE_BRIDGE)
6af69d88dSmrg
7af69d88dSmrg#include "glapi/glapi.h"
8af69d88dSmrg
9af69d88dSmrg/* ugly renames to match glapi.h */
10af69d88dSmrg#define mapi_table _glapi_table
11af69d88dSmrg
12af69d88dSmrg#ifdef GLX_USE_TLS
13af69d88dSmrg#define u_current_table _glapi_tls_Dispatch
14af69d88dSmrg#define u_current_context _glapi_tls_Context
15af69d88dSmrg#else
16af69d88dSmrg#define u_current_table _glapi_Dispatch
17af69d88dSmrg#define u_current_context _glapi_Context
18af69d88dSmrg#endif
19af69d88dSmrg
20af69d88dSmrg#define u_current_get_table_internal _glapi_get_dispatch
21af69d88dSmrg#define u_current_get_context_internal _glapi_get_context
22af69d88dSmrg
23af69d88dSmrg#define u_current_table_tsd _gl_DispatchTSD
24af69d88dSmrg
25af69d88dSmrg#else /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */
26af69d88dSmrg
27af69d88dSmrg#include "u_compiler.h"
28af69d88dSmrg
29af69d88dSmrgstruct mapi_table;
30af69d88dSmrg
31af69d88dSmrg#ifdef GLX_USE_TLS
32af69d88dSmrg
33af69d88dSmrgextern __thread struct mapi_table *u_current_table
34af69d88dSmrg    __attribute__((tls_model("initial-exec")));
35af69d88dSmrg
36af69d88dSmrgextern __thread void *u_current_context
37af69d88dSmrg    __attribute__((tls_model("initial-exec")));
38af69d88dSmrg
39af69d88dSmrg#else /* GLX_USE_TLS */
40af69d88dSmrg
41af69d88dSmrgextern struct mapi_table *u_current_table;
42af69d88dSmrgextern void *u_current_context;
43af69d88dSmrg
44af69d88dSmrg#endif /* GLX_USE_TLS */
45af69d88dSmrg
46af69d88dSmrg#endif /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */
47af69d88dSmrg
48af69d88dSmrgvoid
49af69d88dSmrgu_current_init(void);
50af69d88dSmrg
51af69d88dSmrgvoid
52af69d88dSmrgu_current_destroy(void);
53af69d88dSmrg
54af69d88dSmrgvoid
55af69d88dSmrgu_current_set_table(const struct mapi_table *tbl);
56af69d88dSmrg
57af69d88dSmrgstruct mapi_table *
58af69d88dSmrgu_current_get_table_internal(void);
59af69d88dSmrg
60af69d88dSmrgvoid
61af69d88dSmrgu_current_set_context(const void *ptr);
62af69d88dSmrg
63af69d88dSmrgvoid *
64af69d88dSmrgu_current_get_context_internal(void);
65af69d88dSmrg
66af69d88dSmrgstatic INLINE const struct mapi_table *
67af69d88dSmrgu_current_get_table(void)
68af69d88dSmrg{
69af69d88dSmrg#ifdef GLX_USE_TLS
70af69d88dSmrg   return u_current_table;
71af69d88dSmrg#else
72af69d88dSmrg   return (likely(u_current_table) ?
73af69d88dSmrg         u_current_table : u_current_get_table_internal());
74af69d88dSmrg#endif
75af69d88dSmrg}
76af69d88dSmrg
77af69d88dSmrgstatic INLINE const void *
78af69d88dSmrgu_current_get_context(void)
79af69d88dSmrg{
80af69d88dSmrg#ifdef GLX_USE_TLS
81af69d88dSmrg   return u_current_context;
82af69d88dSmrg#else
83af69d88dSmrg   return likely(u_current_context) ? u_current_context : u_current_get_context_internal();
84af69d88dSmrg#endif
85af69d88dSmrg}
86af69d88dSmrg
87af69d88dSmrg#endif /* _U_CURRENT_H_ */
88