mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 18:15:10 +00:00
TLS key cleanup.
This commit is contained in:
parent
6b7f5671f8
commit
4a2a00766c
@ -33,6 +33,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
// This is the only glXGetProcAddress variant not declared by glxext.h
|
||||
@ -44,20 +45,6 @@ void (*glXGetProcAddressEXT(const GLubyte* procName))();
|
||||
#endif
|
||||
|
||||
|
||||
// Thread local storage attribute macro
|
||||
//
|
||||
#if defined(__GNUC__)
|
||||
#define _GLFW_TLS __thread
|
||||
#else
|
||||
#define _GLFW_TLS
|
||||
#endif
|
||||
|
||||
|
||||
// The per-thread current context/window pointer
|
||||
//
|
||||
static _GLFW_TLS _GLFWwindow* _glfwCurrentWindow = NULL;
|
||||
|
||||
|
||||
// Error handler used when creating a context
|
||||
//
|
||||
static int errorHandler(Display *display, XErrorEvent* event)
|
||||
@ -124,6 +111,13 @@ int _glfwInitContextAPI(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (pthread_key_create(&_glfw.glx.current, NULL) != 0)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"GLX: Failed to create context TLS");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// Check if GLX is supported on this display
|
||||
if (!glXQueryExtension(_glfw.x11.display,
|
||||
&_glfw.glx.errorBase,
|
||||
@ -228,6 +222,8 @@ void _glfwTerminateContextAPI(void)
|
||||
_glfw.glx.libGL = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
pthread_key_delete(_glfw.glx.current);
|
||||
}
|
||||
|
||||
#define setGLXattrib(attribName, attribValue) \
|
||||
@ -529,12 +525,12 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
|
||||
else
|
||||
glXMakeCurrent(_glfw.x11.display, None, NULL);
|
||||
|
||||
_glfwCurrentWindow = window;
|
||||
pthread_setspecific(_glfw.glx.current, window);
|
||||
}
|
||||
|
||||
_GLFWwindow* _glfwPlatformGetCurrentContext(void)
|
||||
{
|
||||
return _glfwCurrentWindow;
|
||||
return (_GLFWwindow*) pthread_getspecific(_glfw.glx.current);
|
||||
}
|
||||
|
||||
void _glfwPlatformSwapBuffers(_GLFWwindow* window)
|
||||
@ -544,7 +540,7 @@ void _glfwPlatformSwapBuffers(_GLFWwindow* window)
|
||||
|
||||
void _glfwPlatformSwapInterval(int interval)
|
||||
{
|
||||
_GLFWwindow* window = _glfwCurrentWindow;
|
||||
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
|
||||
|
||||
if (_glfw.glx.EXT_swap_control)
|
||||
{
|
||||
|
@ -93,6 +93,9 @@ typedef struct _GLFWlibraryGLX
|
||||
int eventBase;
|
||||
int errorBase;
|
||||
|
||||
// TLS key for per-thread current context/window
|
||||
pthread_key_t current;
|
||||
|
||||
// GLX error code received by Xlib error callback
|
||||
int errorCode;
|
||||
|
||||
|
@ -32,11 +32,6 @@
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
// The per-thread current context/window pointer
|
||||
//
|
||||
static pthread_key_t _glfwCurrentTLS;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -45,7 +40,7 @@ static pthread_key_t _glfwCurrentTLS;
|
||||
//
|
||||
int _glfwInitContextAPI(void)
|
||||
{
|
||||
if (pthread_key_create(&_glfwCurrentTLS, NULL) != 0)
|
||||
if (pthread_key_create(&_glfw.nsgl.current, NULL) != 0)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"NSOpenGL: Failed to create context TLS");
|
||||
@ -59,7 +54,7 @@ int _glfwInitContextAPI(void)
|
||||
//
|
||||
void _glfwTerminateContextAPI(void)
|
||||
{
|
||||
pthread_key_delete(_glfwCurrentTLS);
|
||||
pthread_key_delete(_glfw.nsgl.current);
|
||||
}
|
||||
|
||||
// Create the OpenGL context
|
||||
@ -242,12 +237,12 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
|
||||
else
|
||||
[NSOpenGLContext clearCurrentContext];
|
||||
|
||||
pthread_setspecific(_glfwCurrentTLS, window);
|
||||
pthread_setspecific(_glfw.nsgl.current, window);
|
||||
}
|
||||
|
||||
_GLFWwindow* _glfwPlatformGetCurrentContext(void)
|
||||
{
|
||||
return (_GLFWwindow*) pthread_getspecific(_glfwCurrentTLS);
|
||||
return (_GLFWwindow*) pthread_getspecific(_glfw.nsgl.current);
|
||||
}
|
||||
|
||||
void _glfwPlatformSwapBuffers(_GLFWwindow* window)
|
||||
|
@ -55,7 +55,11 @@ typedef struct _GLFWcontextNSGL
|
||||
typedef struct _GLFWlibraryNSGL
|
||||
{
|
||||
// dlopen handle for dynamically loading OpenGL extension entry points
|
||||
void* framework;
|
||||
void* framework;
|
||||
|
||||
// TLS key for per-thread current context/window
|
||||
pthread_key_t current;
|
||||
|
||||
} _GLFWlibraryNSGL;
|
||||
|
||||
|
||||
|
@ -133,8 +133,8 @@ static void initWGLExtensions(_GLFWwindow* window)
|
||||
//
|
||||
int _glfwInitContextAPI(void)
|
||||
{
|
||||
_glfw.wgl.tls = TlsAlloc();
|
||||
if (_glfw.wgl.tls == TLS_OUT_OF_INDEXES)
|
||||
_glfw.wgl.current = TlsAlloc();
|
||||
if (_glfw.wgl.current == TLS_OUT_OF_INDEXES)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"WGL: Failed to allocate TLS index");
|
||||
@ -151,7 +151,7 @@ int _glfwInitContextAPI(void)
|
||||
void _glfwTerminateContextAPI(void)
|
||||
{
|
||||
if (_glfw.wgl.hasTLS)
|
||||
TlsFree(_glfw.wgl.tls);
|
||||
TlsFree(_glfw.wgl.current);
|
||||
}
|
||||
|
||||
#define setWGLattrib(attribName, attribValue) \
|
||||
@ -512,12 +512,12 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
|
||||
else
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
|
||||
TlsSetValue(_glfw.wgl.tls, window);
|
||||
TlsSetValue(_glfw.wgl.current, window);
|
||||
}
|
||||
|
||||
_GLFWwindow* _glfwPlatformGetCurrentContext(void)
|
||||
{
|
||||
return TlsGetValue(_glfw.wgl.tls);
|
||||
return TlsGetValue(_glfw.wgl.current);
|
||||
}
|
||||
|
||||
void _glfwPlatformSwapBuffers(_GLFWwindow* window)
|
||||
|
@ -77,7 +77,7 @@ typedef struct _GLFWcontextWGL
|
||||
typedef struct _GLFWlibraryWGL
|
||||
{
|
||||
GLboolean hasTLS;
|
||||
DWORD tls;
|
||||
DWORD current;
|
||||
|
||||
} _GLFWlibraryWGL;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user