mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 14:24:35 +00:00
Implemented TLS for all platforms.
This commit is contained in:
parent
c594bb4689
commit
18a5aba8f1
@ -103,6 +103,9 @@ int _glfwPlatformInit(void)
|
|||||||
|
|
||||||
_glfwInitJoysticks();
|
_glfwInitJoysticks();
|
||||||
|
|
||||||
|
if (!_glfwInitOpenGL())
|
||||||
|
return GL_FALSE;
|
||||||
|
|
||||||
_glfwLibrary.NS.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
_glfwLibrary.NS.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
if (!_glfwLibrary.NS.eventSource)
|
if (!_glfwLibrary.NS.eventSource)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
@ -143,6 +146,8 @@ int _glfwPlatformTerminate(void)
|
|||||||
|
|
||||||
_glfwTerminateJoysticks();
|
_glfwTerminateJoysticks();
|
||||||
|
|
||||||
|
_glfwTerminateOpenGL();
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,18 +29,46 @@
|
|||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// The per-thread current context/window pointer
|
// The per-thread current context/window pointer
|
||||||
// TODO: Implement pthreads TLS
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
_GLFWwindow* _glfwCurrentWindow = NULL;
|
static pthread_key_t _glfwCurrentTLS;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
////// GLFW platform API //////
|
////// GLFW platform API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Initialize OpenGL support
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
int _glfwInitOpenGL(void)
|
||||||
|
{
|
||||||
|
if (pthread_key_create(&_glfwCurrentTLS, NULL) != 0)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
|
"Cocoa/NSGL: Failed to create context TLS");
|
||||||
|
return GL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Terminate OpenGL support
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void _glfwTerminateOpenGL(void)
|
||||||
|
{
|
||||||
|
pthread_key_delete(_glfwCurrentTLS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Make the OpenGL context associated with the specified window current
|
// Make the OpenGL context associated with the specified window current
|
||||||
//========================================================================
|
//========================================================================
|
||||||
@ -52,7 +80,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
|
|||||||
else
|
else
|
||||||
[NSOpenGLContext clearCurrentContext];
|
[NSOpenGLContext clearCurrentContext];
|
||||||
|
|
||||||
_glfwCurrentWindow = window;
|
pthread_setspecific(_glfwCurrentTLS, window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -62,7 +90,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
|
|||||||
|
|
||||||
_GLFWwindow* _glfwPlatformGetCurrentContext(void)
|
_GLFWwindow* _glfwPlatformGetCurrentContext(void)
|
||||||
{
|
{
|
||||||
return _glfwCurrentWindow;
|
return (_GLFWwindow*) pthread_getspecific(_glfwCurrentTLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -83,7 +111,7 @@ void _glfwPlatformSwapBuffers(_GLFWwindow* window)
|
|||||||
|
|
||||||
void _glfwPlatformSwapInterval(int interval)
|
void _glfwPlatformSwapInterval(int interval)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = _glfwCurrentWindow;
|
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
|
||||||
|
|
||||||
GLint sync = interval;
|
GLint sync = interval;
|
||||||
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
|
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
|
||||||
|
@ -124,4 +124,8 @@ void _glfwTerminateJoysticks(void);
|
|||||||
GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate);
|
GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate);
|
||||||
void _glfwRestoreVideoMode(void);
|
void _glfwRestoreVideoMode(void);
|
||||||
|
|
||||||
|
// OpenGL support
|
||||||
|
int _glfwInitOpenGL(void);
|
||||||
|
void _glfwTerminateOpenGL(void);
|
||||||
|
|
||||||
#endif // _platform_h_
|
#endif // _platform_h_
|
||||||
|
@ -33,10 +33,22 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Thread local storage attribute macro
|
||||||
|
//========================================================================
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define _GLFW_TLS __declspec(thread)
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#define _GLFW_TLS __thread
|
||||||
|
#else
|
||||||
|
#define _GLFW_TLS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// The per-thread current context/window pointer
|
// The per-thread current context/window pointer
|
||||||
//========================================================================
|
//========================================================================
|
||||||
__declspec(thread) _GLFWwindow* _glfwCurrentWindow = NULL;
|
static _GLFW_TLS _GLFWwindow* _glfwCurrentWindow = NULL;
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -37,10 +37,21 @@
|
|||||||
// This is the only glXGetProcAddress variant not declared by glxext.h
|
// This is the only glXGetProcAddress variant not declared by glxext.h
|
||||||
void (*glXGetProcAddressEXT(const GLubyte* procName))();
|
void (*glXGetProcAddressEXT(const GLubyte* procName))();
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Thread local storage attribute macro
|
||||||
|
//========================================================================
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#define _GLFW_TLS __thread
|
||||||
|
#else
|
||||||
|
#define _GLFW_TLS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// The per-thread current context/window pointer
|
// The per-thread current context/window pointer
|
||||||
//========================================================================
|
//========================================================================
|
||||||
__thread _GLFWwindow* _glfwCurrentWindow = NULL;
|
static _GLFW_TLS _GLFWwindow* _glfwCurrentWindow = NULL;
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
Loading…
Reference in New Issue
Block a user