Thread safety for Win32. SourceForge bug #1507315.
This commit is contained in:
32
src/mesa/drivers/windows/gdi/InitCritSections.cpp
Normal file
32
src/mesa/drivers/windows/gdi/InitCritSections.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "glapi.h"
|
||||||
|
#include "glThread.h"
|
||||||
|
|
||||||
|
#ifdef WIN32_THREADS
|
||||||
|
extern "C" _glthread_Mutex OneTimeLock;
|
||||||
|
extern "C" _glthread_Mutex GenTexturesLock;
|
||||||
|
|
||||||
|
extern "C" void FreeAllTSD(void);
|
||||||
|
|
||||||
|
class _CriticalSectionInit
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static _CriticalSectionInit m_inst;
|
||||||
|
|
||||||
|
_CriticalSectionInit()
|
||||||
|
{
|
||||||
|
_glthread_INIT_MUTEX(OneTimeLock);
|
||||||
|
_glthread_INIT_MUTEX(GenTexturesLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
~_CriticalSectionInit()
|
||||||
|
{
|
||||||
|
_glthread_DESTROY_MUTEX(OneTimeLock);
|
||||||
|
_glthread_DESTROY_MUTEX(GenTexturesLock);
|
||||||
|
FreeAllTSD();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_CriticalSectionInit _CriticalSectionInit::m_inst;
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@@ -185,6 +185,15 @@ static GLboolean ThreadSafe = GL_FALSE; /**< In thread-safe mode? */
|
|||||||
_glthread_TSD _gl_DispatchTSD; /**< Per-thread dispatch pointer */
|
_glthread_TSD _gl_DispatchTSD; /**< Per-thread dispatch pointer */
|
||||||
static _glthread_TSD ContextTSD; /**< Per-thread context pointer */
|
static _glthread_TSD ContextTSD; /**< Per-thread context pointer */
|
||||||
|
|
||||||
|
#if defined(WIN32_THREADS)
|
||||||
|
void FreeTSD(_glthread_TSD *p);
|
||||||
|
void FreeAllTSD(void)
|
||||||
|
{
|
||||||
|
FreeTSD(&_gl_DispatchTSD);
|
||||||
|
FreeTSD(&ContextTSD);
|
||||||
|
}
|
||||||
|
#endif /* defined(WIN32_THREADS) */
|
||||||
|
|
||||||
#endif /* defined(THREADS) */
|
#endif /* defined(THREADS) */
|
||||||
|
|
||||||
PUBLIC struct _glapi_table *_glapi_Dispatch =
|
PUBLIC struct _glapi_table *_glapi_Dispatch =
|
||||||
|
@@ -1,9 +1,8 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Mesa 3-D graphics library
|
* Mesa 3-D graphics library
|
||||||
* Version: 4.1
|
* Version: 6.5.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
|
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -186,11 +185,23 @@ _glthread_SetTSD(_glthread_TSD *tsd, void *ptr)
|
|||||||
*/
|
*/
|
||||||
#ifdef WIN32_THREADS
|
#ifdef WIN32_THREADS
|
||||||
|
|
||||||
|
void FreeTSD(_glthread_TSD *p)
|
||||||
|
{
|
||||||
|
if (p->initMagic==INIT_MAGIC) {
|
||||||
|
TlsFree(p->key);
|
||||||
|
p->initMagic=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InsteadOf_exit(int nCode)
|
||||||
|
{
|
||||||
|
DWORD dwErr=GetLastError();
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long
|
unsigned long
|
||||||
_glthread_GetID(void)
|
_glthread_GetID(void)
|
||||||
{
|
{
|
||||||
abort(); /* XXX not implemented yet */
|
return GetCurrentThreadId();
|
||||||
return (unsigned long) 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -198,11 +209,9 @@ void
|
|||||||
_glthread_InitTSD(_glthread_TSD *tsd)
|
_glthread_InitTSD(_glthread_TSD *tsd)
|
||||||
{
|
{
|
||||||
tsd->key = TlsAlloc();
|
tsd->key = TlsAlloc();
|
||||||
if (tsd->key == 0xffffffff) {
|
if (tsd->key == TLS_OUT_OF_INDEXES) {
|
||||||
/* Can Windows handle stderr messages for non-console
|
perror("Mesa:_glthread_InitTSD");
|
||||||
applications? Does Windows have perror? */
|
InsteadOf_exit(-1);
|
||||||
/* perror(SET_INIT_ERROR);*/
|
|
||||||
exit(-1);
|
|
||||||
}
|
}
|
||||||
tsd->initMagic = INIT_MAGIC;
|
tsd->initMagic = INIT_MAGIC;
|
||||||
}
|
}
|
||||||
@@ -227,10 +236,8 @@ _glthread_SetTSD(_glthread_TSD *tsd, void *ptr)
|
|||||||
_glthread_InitTSD(tsd);
|
_glthread_InitTSD(tsd);
|
||||||
}
|
}
|
||||||
if (TlsSetValue(tsd->key, ptr) == 0) {
|
if (TlsSetValue(tsd->key, ptr) == 0) {
|
||||||
/* Can Windows handle stderr messages for non-console
|
perror("Mesa:_glthread_SetTSD");
|
||||||
applications? Does Windows have perror? */
|
InsteadOf_exit(-1);
|
||||||
/* perror(SET_TSD_ERROR);*/
|
|
||||||
exit(-1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Mesa 3-D graphics library
|
* Mesa 3-D graphics library
|
||||||
* Version: 6.3
|
* Version: 6.5.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
|
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -163,12 +163,11 @@ typedef HANDLE _glthread_Thread;
|
|||||||
|
|
||||||
typedef CRITICAL_SECTION _glthread_Mutex;
|
typedef CRITICAL_SECTION _glthread_Mutex;
|
||||||
|
|
||||||
/* XXX need to really implement mutex-related macros */
|
#define _glthread_DECLARE_STATIC_MUTEX(name) /*static*/ _glthread_Mutex name = {0,0,0,0,0,0}
|
||||||
#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = 0
|
#define _glthread_INIT_MUTEX(name) InitializeCriticalSection(&name)
|
||||||
#define _glthread_INIT_MUTEX(name) (void) name
|
#define _glthread_DESTROY_MUTEX(name) DeleteCriticalSection(&name)
|
||||||
#define _glthread_DESTROY_MUTEX(name) (void) name
|
#define _glthread_LOCK_MUTEX(name) EnterCriticalSection(&name)
|
||||||
#define _glthread_LOCK_MUTEX(name) (void) name
|
#define _glthread_UNLOCK_MUTEX(name) LeaveCriticalSection(&name)
|
||||||
#define _glthread_UNLOCK_MUTEX(name) (void) name
|
|
||||||
|
|
||||||
#endif /* WIN32_THREADS */
|
#endif /* WIN32_THREADS */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user