Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

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