[GLX] Fix-up TSD context key initialization code

- Do some renaming to reduce confusion:

  threadDestroyKey -> tsdContextKey
  threadDestroyKeyInitialized -> tsdContextKeyInitialized
  threadInitOnceControl -> threadCreateTSDContextOnceControl
  ThreadInitOnce -> ThreadCreateTSDContextOnce

- Delete __glXInitThreads().  Instead the TSD context key is initialized
  when TrackCurrentContext() is first called.

- XGLVRegisterCloseDisplayCallback(DisplayClosed) is called by
  __glXInit() now instead of ThreadInitOnce().

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
Reviewed-by: Aaron Plattner <aplattner@nvidia.com>
This commit is contained in:
Brian Nguyen 2013-11-26 13:05:00 -08:00 committed by brnguyen
parent 59efa7e0a1
commit 39d839d14f
3 changed files with 18 additions and 29 deletions

View file

@ -52,9 +52,9 @@
GLVNDPthreadFuncs __glXPthreadFuncs;
static glvnd_key_t threadDestroyKey;
static Bool threadDestroyKeyInitialized;
static glvnd_once_t threadInitOnceControl = GLVND_ONCE_INIT;
static glvnd_key_t tsdContextKey;
static Bool tsdContextKeyInitialized;
static glvnd_once_t threadCreateTSDContextOnceControl = GLVND_ONCE_INIT;
static void UntrackCurrentContext(GLXContext ctx);
@ -72,8 +72,6 @@ typedef struct __GLXcurrentContextHashRec {
static DEFINE_INITIALIZED_LKDHASH(__GLXcurrentContextHash,
__glXCurrentContextHash);
static void ThreadDestroyed(void *tsdCtx)
{
/*
@ -88,20 +86,12 @@ static void ThreadDestroyed(void *tsdCtx)
LKDHASH_UNLOCK(__glXPthreadFuncs, __glXCurrentContextHash);
}
static void DisplayClosed(Display *dpy);
static void ThreadInitOnce(void)
static void ThreadCreateTSDContextOnce(void)
{
int ret = __glXPthreadFuncs.key_create(&threadDestroyKey, ThreadDestroyed);
int ret = __glXPthreadFuncs.key_create(&tsdContextKey, ThreadDestroyed);
assert(!ret);
threadDestroyKeyInitialized = True;
XGLVRegisterCloseDisplayCallback(DisplayClosed);
}
void __glXInitThreads(void)
{
__glXPthreadFuncs.once(&threadInitOnceControl, ThreadInitOnce);
tsdContextKeyInitialized = True;
}
PUBLIC XVisualInfo* glXChooseVisual(Display *dpy, int screen, int *attrib_list)
@ -319,11 +309,15 @@ static Bool TrackCurrentContext(GLXContext ctx)
__GLXcurrentContextHash *pEntry = NULL;
GLXContext tsdCtx;
assert(threadDestroyKeyInitialized);
// Initialize the TSD entry (if we haven't already)
__glXPthreadFuncs.once(&threadCreateTSDContextOnceControl,
ThreadCreateTSDContextOnce);
assert(tsdContextKeyInitialized);
// Update the TSD entry to reflect the correct current context
tsdCtx = (GLXContext)__glXPthreadFuncs.getspecific(threadDestroyKey);
__glXPthreadFuncs.setspecific(threadDestroyKey, ctx);
tsdCtx = (GLXContext)__glXPthreadFuncs.getspecific(tsdContextKey);
__glXPthreadFuncs.setspecific(tsdContextKey, ctx);
if (!ctx) {
// Don't track NULL contexts
@ -337,7 +331,7 @@ static Bool TrackCurrentContext(GLXContext ctx)
pEntry = malloc(sizeof(*pEntry));
if (!pEntry) {
// Restore the original TSD entry
__glXPthreadFuncs.setspecific(threadDestroyKey, tsdCtx);
__glXPthreadFuncs.setspecific(tsdContextKey, tsdCtx);
return False;
}
@ -388,7 +382,7 @@ static void UntrackCurrentContext(GLXContext ctx)
free(pEntry);
// Clear the TSD entry
__glXPthreadFuncs.setspecific(threadDestroyKey, NULL);
__glXPthreadFuncs.setspecific(tsdContextKey, NULL);
if (needsUnmap) {
__glXRemoveScreenContextMapping(ctx);
@ -1231,6 +1225,9 @@ void __attribute__ ((constructor)) __glXInit(void)
}
}
/* Register our XCloseDisplay() callback */
XGLVRegisterCloseDisplayCallback(DisplayClosed);
DBG_PRINTF(0, "Loading GLX...\n");
}

View file

@ -420,12 +420,6 @@ __GLXvendorInfo *__glXLookupVendorByScreen(Display *dpy, const int screen)
return NULL;
}
/*
* This is the first thing done by most vendor-neutral GLX entrypoints, and
* hence a good time to do any necessary per-thread initialization.
*/
__glXInitThreads();
memset(&key, 0, sizeof(key));
key.dpy = dpy;

View file

@ -34,6 +34,4 @@
extern GLVNDPthreadFuncs __glXPthreadFuncs;
void __glXInitThreads(void);
#endif