mapi: Avoid Data Execution Prevention on windows.
[mesa.git] / src / mapi / mapi / u_current.h
1 #ifndef _U_CURRENT_H_
2 #define _U_CURRENT_H_
3
4 #include "u_compiler.h"
5
6 #ifdef MAPI_GLAPI_CURRENT
7 #define GLAPI_EXPORT PUBLIC
8 #else
9 #define GLAPI_EXPORT
10 #endif
11
12 /*
13 * Unlike other utility functions, we need to keep the old names (_glapi_*) for
14 * ABI compatibility. The desired functions are wrappers to the old ones.
15 */
16
17 struct _glapi_table;
18
19 #ifdef GLX_USE_TLS
20
21 GLAPI_EXPORT extern __thread struct _glapi_table *_glapi_tls_Dispatch
22 __attribute__((tls_model("initial-exec")));
23
24 GLAPI_EXPORT extern __thread void *_glapi_tls_Context
25 __attribute__((tls_model("initial-exec")));
26
27 GLAPI_EXPORT extern const struct _glapi_table *_glapi_Dispatch;
28 GLAPI_EXPORT extern const void *_glapi_Context;
29
30 #else /* GLX_USE_TLS */
31
32 GLAPI_EXPORT extern struct _glapi_table *_glapi_Dispatch;
33 GLAPI_EXPORT extern void *_glapi_Context;
34
35 #endif /* GLX_USE_TLS */
36
37 GLAPI_EXPORT void
38 _glapi_check_multithread(void);
39
40 GLAPI_EXPORT void
41 _glapi_set_context(void *context);
42
43 GLAPI_EXPORT void *
44 _glapi_get_context(void);
45
46 GLAPI_EXPORT void
47 _glapi_set_dispatch(struct _glapi_table *dispatch);
48
49 GLAPI_EXPORT struct _glapi_table *
50 _glapi_get_dispatch(void);
51
52 void
53 _glapi_destroy_multithread(void);
54
55
56 struct mapi_table;
57
58 static INLINE void
59 u_current_set(const struct mapi_table *tbl)
60 {
61 _glapi_check_multithread();
62 _glapi_set_dispatch((struct _glapi_table *) tbl);
63 }
64
65 static INLINE const struct mapi_table *
66 u_current_get(void)
67 {
68 #ifdef GLX_USE_TLS
69 return (const struct mapi_table *) _glapi_tls_Dispatch;
70 #else
71 return (const struct mapi_table *) (likely(_glapi_Dispatch) ?
72 _glapi_Dispatch : _glapi_get_dispatch());
73 #endif
74 }
75
76 static INLINE void
77 u_current_set_user(void *ptr)
78 {
79 _glapi_check_multithread();
80 _glapi_set_context(ptr);
81 }
82
83 static INLINE void *
84 u_current_get_user(void)
85 {
86 #ifdef GLX_USE_TLS
87 return _glapi_tls_Context;
88 #else
89 return likely(_glapi_Context) ? _glapi_Context : _glapi_get_context();
90 #endif
91 }
92
93 #endif /* GLX_USE_TLS */