Add support for the in-progress ALC_EXT_thread_local_context extension
This commit is contained in:
parent
b444dea63b
commit
59ed9338d8
84
Alc/ALc.c
84
Alc/ALc.c
@ -111,6 +111,10 @@ static ALCfunction alcFunctions[] = {
|
|||||||
{ "alcCaptureStart", (ALvoid *) alcCaptureStart },
|
{ "alcCaptureStart", (ALvoid *) alcCaptureStart },
|
||||||
{ "alcCaptureStop", (ALvoid *) alcCaptureStop },
|
{ "alcCaptureStop", (ALvoid *) alcCaptureStop },
|
||||||
{ "alcCaptureSamples", (ALvoid *) alcCaptureSamples },
|
{ "alcCaptureSamples", (ALvoid *) alcCaptureSamples },
|
||||||
|
|
||||||
|
{ "alcMakeCurrent", (ALvoid *) alcMakeCurrent },
|
||||||
|
{ "alcGetThreadContext", (ALvoid *) alcGetThreadContext },
|
||||||
|
|
||||||
{ NULL, (ALvoid *) NULL }
|
{ NULL, (ALvoid *) NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -175,7 +179,7 @@ static ALCchar *alcDefaultAllDeviceSpecifier;
|
|||||||
static ALCchar *alcCaptureDefaultDeviceSpecifier;
|
static ALCchar *alcCaptureDefaultDeviceSpecifier;
|
||||||
|
|
||||||
|
|
||||||
static ALCchar alcExtensionList[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_disconnect ALC_EXT_EFX";
|
static ALCchar alcExtensionList[] = "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_disconnect ALC_EXT_EFX ALC_EXTX_thread_local_context";
|
||||||
static ALCint alcMajorVersion = 1;
|
static ALCint alcMajorVersion = 1;
|
||||||
static ALCint alcMinorVersion = 1;
|
static ALCint alcMinorVersion = 1;
|
||||||
|
|
||||||
@ -197,6 +201,9 @@ static CRITICAL_SECTION g_csMutex;
|
|||||||
static ALCcontext *g_pContextList = NULL;
|
static ALCcontext *g_pContextList = NULL;
|
||||||
static ALCuint g_ulContextCount = 0;
|
static ALCuint g_ulContextCount = 0;
|
||||||
|
|
||||||
|
// Thread-local current context
|
||||||
|
static tls_type LocalContext;
|
||||||
|
|
||||||
// Context Error
|
// Context Error
|
||||||
static ALCenum g_eLastContextError = ALC_NO_ERROR;
|
static ALCenum g_eLastContextError = ALC_NO_ERROR;
|
||||||
|
|
||||||
@ -229,6 +236,8 @@ BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
|
|||||||
for(i = 0;BackendList[i].Deinit;i++)
|
for(i = 0;BackendList[i].Deinit;i++)
|
||||||
BackendList[i].Deinit();
|
BackendList[i].Deinit();
|
||||||
|
|
||||||
|
tls_delete(LocalContext);
|
||||||
|
|
||||||
FreeALConfig();
|
FreeALConfig();
|
||||||
ALTHUNK_EXIT();
|
ALTHUNK_EXIT();
|
||||||
DeleteCriticalSection(&g_csMutex);
|
DeleteCriticalSection(&g_csMutex);
|
||||||
@ -252,6 +261,8 @@ static void my_deinit()
|
|||||||
for(i = 0;BackendList[i].Deinit;i++)
|
for(i = 0;BackendList[i].Deinit;i++)
|
||||||
BackendList[i].Deinit();
|
BackendList[i].Deinit();
|
||||||
|
|
||||||
|
tls_delete(LocalContext);
|
||||||
|
|
||||||
FreeALConfig();
|
FreeALConfig();
|
||||||
ALTHUNK_EXIT();
|
ALTHUNK_EXIT();
|
||||||
DeleteCriticalSection(&g_csMutex);
|
DeleteCriticalSection(&g_csMutex);
|
||||||
@ -305,6 +316,8 @@ static void InitAL(void)
|
|||||||
ALTHUNK_INIT();
|
ALTHUNK_INIT();
|
||||||
ReadALConfig();
|
ReadALConfig();
|
||||||
|
|
||||||
|
tls_create(&LocalContext);
|
||||||
|
|
||||||
devs = GetConfigValue(NULL, "drivers", "");
|
devs = GetConfigValue(NULL, "drivers", "");
|
||||||
if(devs[0])
|
if(devs[0])
|
||||||
{
|
{
|
||||||
@ -509,10 +522,18 @@ ALCcontext *GetContextSuspended(void)
|
|||||||
|
|
||||||
SuspendContext(NULL);
|
SuspendContext(NULL);
|
||||||
|
|
||||||
pContext = g_pContextList;
|
pContext = tls_get(LocalContext);
|
||||||
while(pContext && !pContext->InUse)
|
if(pContext && !IsContext(pContext))
|
||||||
pContext = pContext->next;
|
{
|
||||||
|
tls_set(LocalContext, NULL);
|
||||||
|
pContext = NULL;
|
||||||
|
}
|
||||||
|
if(!pContext)
|
||||||
|
{
|
||||||
|
pContext = g_pContextList;
|
||||||
|
while(pContext && !pContext->InUse)
|
||||||
|
pContext = pContext->next;
|
||||||
|
}
|
||||||
if(pContext)
|
if(pContext)
|
||||||
SuspendContext(pContext);
|
SuspendContext(pContext);
|
||||||
|
|
||||||
@ -1306,6 +1327,21 @@ ALCAPI ALCvoid ALCAPIENTRY alcDestroyContext(ALCcontext *context)
|
|||||||
Returns the currently active Context
|
Returns the currently active Context
|
||||||
*/
|
*/
|
||||||
ALCAPI ALCcontext * ALCAPIENTRY alcGetCurrentContext(ALCvoid)
|
ALCAPI ALCcontext * ALCAPIENTRY alcGetCurrentContext(ALCvoid)
|
||||||
|
{
|
||||||
|
ALCcontext *pContext;
|
||||||
|
|
||||||
|
if((pContext=GetContextSuspended()) != NULL)
|
||||||
|
ProcessContext(pContext);
|
||||||
|
|
||||||
|
return pContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
alcGetThreadContext
|
||||||
|
|
||||||
|
Returns the currently active thread-local Context
|
||||||
|
*/
|
||||||
|
ALCcontext * ALCAPIENTRY alcGetThreadContext(void)
|
||||||
{
|
{
|
||||||
ALCcontext *pContext = NULL;
|
ALCcontext *pContext = NULL;
|
||||||
|
|
||||||
@ -1313,9 +1349,12 @@ ALCAPI ALCcontext * ALCAPIENTRY alcGetCurrentContext(ALCvoid)
|
|||||||
|
|
||||||
SuspendContext(NULL);
|
SuspendContext(NULL);
|
||||||
|
|
||||||
pContext = g_pContextList;
|
pContext = tls_get(LocalContext);
|
||||||
while ((pContext) && (!pContext->InUse))
|
if(pContext && !IsContext(pContext))
|
||||||
pContext = pContext->next;
|
{
|
||||||
|
tls_set(LocalContext, NULL);
|
||||||
|
pContext = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ProcessContext(NULL);
|
ProcessContext(NULL);
|
||||||
|
|
||||||
@ -1374,6 +1413,8 @@ ALCAPI ALCboolean ALCAPIENTRY alcMakeContextCurrent(ALCcontext *context)
|
|||||||
ALContext->InUse=AL_TRUE;
|
ALContext->InUse=AL_TRUE;
|
||||||
ProcessContext(ALContext);
|
ProcessContext(ALContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tls_set(LocalContext, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1386,6 +1427,33 @@ ALCAPI ALCboolean ALCAPIENTRY alcMakeContextCurrent(ALCcontext *context)
|
|||||||
return bReturn;
|
return bReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
alcMakeCurrent
|
||||||
|
|
||||||
|
Makes the given Context the active Context for the current thread
|
||||||
|
*/
|
||||||
|
ALCboolean ALCAPIENTRY alcMakeCurrent(ALCcontext *context)
|
||||||
|
{
|
||||||
|
ALboolean bReturn = AL_TRUE;
|
||||||
|
|
||||||
|
InitAL();
|
||||||
|
|
||||||
|
SuspendContext(NULL);
|
||||||
|
|
||||||
|
// context must be a valid Context or NULL
|
||||||
|
if(context == NULL || IsContext(context))
|
||||||
|
tls_set(LocalContext, context);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetALCError(ALC_INVALID_CONTEXT);
|
||||||
|
bReturn = AL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProcessContext(NULL);
|
||||||
|
|
||||||
|
return bReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static ALenum GetFormatFromString(const char *str)
|
static ALenum GetFormatFromString(const char *str)
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,12 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
typedef DWORD tls_type;
|
||||||
|
#define tls_create(x) (*(x) = TlsAlloc())
|
||||||
|
#define tls_delete(x) TlsFree((x))
|
||||||
|
#define tls_get(x) TlsGetValue((x))
|
||||||
|
#define tls_set(x, a) TlsSetValue((x), (a))
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -33,6 +39,12 @@
|
|||||||
|
|
||||||
#define IsBadWritePtr(a,b) (0)
|
#define IsBadWritePtr(a,b) (0)
|
||||||
|
|
||||||
|
typedef pthread_key_t tls_type;
|
||||||
|
#define tls_create(x) pthread_key_create((x), NULL)
|
||||||
|
#define tls_delete(x) pthread_key_delete((x))
|
||||||
|
#define tls_get(x) pthread_getspecific((x))
|
||||||
|
#define tls_set(x, a) pthread_setspecific((x), (a))
|
||||||
|
|
||||||
typedef pthread_mutex_t CRITICAL_SECTION;
|
typedef pthread_mutex_t CRITICAL_SECTION;
|
||||||
static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
|
static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
|
||||||
{
|
{
|
||||||
@ -314,6 +326,9 @@ const char *GetConfigValue(const char *blockName, const char *keyName, const cha
|
|||||||
int GetConfigValueInt(const char *blockName, const char *keyName, int def);
|
int GetConfigValueInt(const char *blockName, const char *keyName, int def);
|
||||||
float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
|
float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
|
||||||
|
|
||||||
|
ALCboolean ALCAPIENTRY alcMakeCurrent(ALCcontext *context);
|
||||||
|
ALCcontext* ALCAPIENTRY alcGetThreadContext(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -144,6 +144,12 @@ typedef ALvoid (AL_APIENTRY*PFNALUNMAPDATABUFFEREXTPROC)(ALuint uiBuffer);
|
|||||||
#define ALC_CONNECTED 0x313
|
#define ALC_CONNECTED 0x313
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ALC_EXT_thread_local_context
|
||||||
|
#define ALC_EXT_thread_local_context 1
|
||||||
|
typedef ALCboolean (ALCAPIENTRY*PFNALCMAKECURRENTPROC)(ALCcontext *context);
|
||||||
|
typedef ALCcontext* (ALCAPIENTRY*PFNALCGETTHREADCONTEXTPROC)(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user