aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mapi/u_current.h
blob: ea4f81723463cac1aae49f4fe691d73b2d45a3e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef _U_CURRENT_H_
#define _U_CURRENT_H_

#include "c99_compat.h"
#include "util/macros.h"


#if defined(MAPI_MODE_UTIL) || defined(MAPI_MODE_GLAPI) || \
    defined(MAPI_MODE_BRIDGE)

#include "glapi/glapi.h"

/* ugly renames to match glapi.h */
#define mapi_table _glapi_table

#ifdef GLX_USE_TLS
#define u_current_table _glapi_tls_Dispatch
#define u_current_context _glapi_tls_Context
#else
#define u_current_table _glapi_Dispatch
#define u_current_context _glapi_Context
#endif

#define u_current_get_table_internal _glapi_get_dispatch
#define u_current_get_context_internal _glapi_get_context

#define u_current_table_tsd _gl_DispatchTSD

#else /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */

struct mapi_table;

#ifdef GLX_USE_TLS

extern __thread struct mapi_table *u_current_table
    __attribute__((tls_model("initial-exec")));

extern __thread void *u_current_context
    __attribute__((tls_model("initial-exec")));

#else /* GLX_USE_TLS */

extern struct mapi_table *u_current_table;
extern void *u_current_context;

#endif /* GLX_USE_TLS */

#endif /* MAPI_MODE_UTIL || MAPI_MODE_GLAPI || MAPI_MODE_BRIDGE */

void
u_current_init(void);

void
u_current_destroy(void);

void
u_current_set_table(const struct mapi_table *tbl);

struct mapi_table *
u_current_get_table_internal(void);

void
u_current_set_context(const void *ptr);

void *
u_current_get_context_internal(void);

static inline const struct mapi_table *
u_current_get_table(void)
{
#ifdef GLX_USE_TLS
   return u_current_table;
#else
   return (likely(u_current_table) ?
         u_current_table : u_current_get_table_internal());
#endif
}

static inline const void *
u_current_get_context(void)
{
#ifdef GLX_USE_TLS
   return u_current_context;
#else
   return likely(u_current_context) ? u_current_context : u_current_get_context_internal();
#endif
}

#endif /* _U_CURRENT_H_ */