373d48fb939a79425a99c257a78570eb5b24d169
[mesa.git] / src / mapi / mapi / u_current.h
1 #ifndef _U_CURRENT_H_
2 #define _U_CURRENT_H_
3
4 #ifdef MAPI_GLAPI_CURRENT
5
6 #include "glapi/glapi.h"
7
8 /* ugly renames to match glapi.h */
9 #define mapi_table _glapi_table
10
11 #ifdef GLX_USE_TLS
12 #define u_current_table _glapi_tls_Dispatch
13 #define u_current_user _glapi_tls_Context
14 #else
15 #define u_current_table _glapi_Dispatch
16 #define u_current_user _glapi_Context
17 #endif
18
19 #define u_current_get_internal _glapi_get_dispatch
20 #define u_current_get_user_internal _glapi_get_context
21
22 #define u_current_table_tsd _gl_DispatchTSD
23
24 #else /* MAPI_GLAPI_CURRENT */
25
26 #include "u_compiler.h"
27
28 struct mapi_table;
29
30 #ifdef GLX_USE_TLS
31
32 extern __thread struct mapi_table *u_current_table
33 __attribute__((tls_model("initial-exec")));
34
35 extern __thread void *u_current_user
36 __attribute__((tls_model("initial-exec")));
37
38 #else /* GLX_USE_TLS */
39
40 extern struct mapi_table *u_current_table;
41 extern void *u_current_user;
42
43 #endif /* GLX_USE_TLS */
44
45 #endif /* MAPI_GLAPI_CURRENT */
46
47 void
48 u_current_init(void);
49
50 void
51 u_current_destroy(void);
52
53 void
54 u_current_set(const struct mapi_table *tbl);
55
56 struct mapi_table *
57 u_current_get_internal(void);
58
59 void
60 u_current_set_user(const void *ptr);
61
62 void *
63 u_current_get_user_internal(void);
64
65 static INLINE const struct mapi_table *
66 u_current_get(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_internal());
73 #endif
74 }
75
76 static INLINE const void *
77 u_current_get_user(void)
78 {
79 #ifdef GLX_USE_TLS
80 return u_current_user;
81 #else
82 return likely(u_current_user) ? u_current_user : u_current_get_user_internal();
83 #endif
84 }
85
86 #endif /* _U_CURRENT_H_ */