Files
mesa/src/mapi/u_current.h
Erik Faye-Lund 61d40ae4d0 mapi: do not call thread-unsafe dispatch getter
When not using the USE_ELF_TLS code-path, this function is
thread-unsafe, because it returns u_current_table if set without
consulting the ThreadSafe variable in u_current.c.

There's a short period where this can cause problems, if a program uses
multiple threads, but only have made a single context current so far. If
the program issues OpenGL commands from the initialized thread while a
new thread is setting u_current_table to __glapi_noop_table, we will
return the wrong table here.

It doesn't seem right to have two versions of the code that does the
same anyway, so let's use the version that doesn't have this problem
instead.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7280>
2020-10-26 12:35:21 +00:00

66 lines
1.3 KiB
C

#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"
#ifdef USE_ELF_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 _glapi_table;
#ifdef USE_ELF_TLS
extern __thread struct _glapi_table *u_current_table
__attribute__((tls_model("initial-exec")));
extern __thread void *u_current_context
__attribute__((tls_model("initial-exec")));
#else /* USE_ELF_TLS */
extern struct _glapi_table *u_current_table;
extern void *u_current_context;
#endif /* USE_ELF_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 _glapi_table *tbl);
struct _glapi_table *
u_current_get_table_internal(void);
void
u_current_set_context(const void *ptr);
void *
u_current_get_context_internal(void);
#endif /* _U_CURRENT_H_ */