aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--router/al.cpp26
-rw-r--r--router/alc.cpp142
-rw-r--r--router/router.cpp6
-rw-r--r--router/router.h11
4 files changed, 86 insertions, 99 deletions
diff --git a/router/al.cpp b/router/al.cpp
index 1b4f413f..4c8b0006 100644
--- a/router/al.cpp
+++ b/router/al.cpp
@@ -7,36 +7,36 @@
#include "router.h"
-atomic_DriverIfacePtr CurrentCtxDriver = ATOMIC_INIT_STATIC(NULL);
+std::atomic<DriverIface*> CurrentCtxDriver{nullptr};
#define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) \
{ \
- DriverIface *iface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));\
- if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ DriverIface *iface = ThreadCtxDriver; \
+ if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
return iface->n(a); \
}
#define DECL_THUNK2(R,n,T1,T2) AL_API R AL_APIENTRY n(T1 a, T2 b) \
{ \
- DriverIface *iface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));\
- if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ DriverIface *iface = ThreadCtxDriver; \
+ if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
return iface->n(a, b); \
}
#define DECL_THUNK3(R,n,T1,T2,T3) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c) \
{ \
- DriverIface *iface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));\
- if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ DriverIface *iface = ThreadCtxDriver; \
+ if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
return iface->n(a, b, c); \
}
#define DECL_THUNK4(R,n,T1,T2,T3,T4) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d) \
{ \
- DriverIface *iface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));\
- if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ DriverIface *iface = ThreadCtxDriver; \
+ if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
return iface->n(a, b, c, d); \
}
#define DECL_THUNK5(R,n,T1,T2,T3,T4,T5) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d, T5 e) \
{ \
- DriverIface *iface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));\
- if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ DriverIface *iface = ThreadCtxDriver; \
+ if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
return iface->n(a, b, c, d, e); \
}
@@ -46,8 +46,8 @@ atomic_DriverIfacePtr CurrentCtxDriver = ATOMIC_INIT_STATIC(NULL);
*/
AL_API ALenum AL_APIENTRY alGetError(void)
{
- DriverIface *iface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));
- if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);
+ DriverIface *iface = ThreadCtxDriver;
+ if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire);
return iface ? iface->alGetError() : AL_NO_ERROR;
}
diff --git a/router/alc.cpp b/router/alc.cpp
index 36275440..b738f339 100644
--- a/router/alc.cpp
+++ b/router/alc.cpp
@@ -6,6 +6,8 @@
#include <string.h>
#include <stdio.h>
+#include <mutex>
+
#include "AL/alc.h"
#include "router.h"
#include "almalloc.h"
@@ -245,10 +247,10 @@ static const ALCint alcMajorVersion = 1;
static const ALCint alcMinorVersion = 1;
-static almtx_t EnumerationLock;
-static almtx_t ContextSwitchLock;
+static std::mutex EnumerationLock;
+static std::mutex ContextSwitchLock;
-static ATOMIC(ALCenum) LastError = ATOMIC_INIT_STATIC(ALC_NO_ERROR);
+static std::atomic<ALCenum> LastError{ALC_NO_ERROR};
static PtrIntMap DeviceIfaceMap = PTRINTMAP_STATIC_INITIALIZE;
static PtrIntMap ContextIfaceMap = PTRINTMAP_STATIC_INITIALIZE;
@@ -330,8 +332,6 @@ static ALint GetDriverIndexForName(const EnumeratedList *list, const ALCchar *na
void InitALC(void)
{
- almtx_init(&EnumerationLock, almtx_recursive);
- almtx_init(&ContextSwitchLock, almtx_plain);
}
void ReleaseALC(void)
@@ -342,9 +342,6 @@ void ReleaseALC(void)
ResetPtrIntMap(&ContextIfaceMap);
ResetPtrIntMap(&DeviceIfaceMap);
-
- almtx_destroy(&ContextSwitchLock);
- almtx_destroy(&EnumerationLock);
}
@@ -364,20 +361,21 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename)
devicename = nullptr;
if(devicename)
{
- almtx_lock(&EnumerationLock);
- if(!DevicesList.Names)
- (void)alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
- idx = GetDriverIndexForName(&DevicesList, devicename);
- if(idx < 0)
- {
- if(!AllDevicesList.Names)
- (void)alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
- idx = GetDriverIndexForName(&AllDevicesList, devicename);
+ { std::lock_guard<std::mutex> _{EnumerationLock};
+ if(!DevicesList.Names)
+ (void)alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
+ idx = GetDriverIndexForName(&DevicesList, devicename);
+ if(idx < 0)
+ {
+ if(!AllDevicesList.Names)
+ (void)alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
+ idx = GetDriverIndexForName(&AllDevicesList, devicename);
+ }
}
- almtx_unlock(&EnumerationLock);
+
if(idx < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
+ LastError.store(ALC_INVALID_VALUE);
TRACE("Failed to find driver for name \"%s\"\n", devicename);
return nullptr;
}
@@ -418,7 +416,7 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
if(!device || (idx=LookupPtrIntMapKey(&DeviceIfaceMap, device)) < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ LastError.store(ALC_INVALID_DEVICE);
return ALC_FALSE;
}
if(!DriverList[idx].alcCloseDevice(device))
@@ -435,8 +433,8 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
if(!device || (idx=LookupPtrIntMapKey(&DeviceIfaceMap, device)) < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
- return ALC_FALSE;
+ LastError.store(ALC_INVALID_DEVICE);
+ return nullptr;
}
context = DriverList[idx].alcCreateContext(device, attrlist);
if(context)
@@ -455,21 +453,17 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
{
ALint idx = -1;
- almtx_lock(&ContextSwitchLock);
+ std::lock_guard<std::mutex> _{ContextSwitchLock};
if(context)
{
idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
if(idx < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
- almtx_unlock(&ContextSwitchLock);
+ LastError.store(ALC_INVALID_CONTEXT);
return ALC_FALSE;
}
if(!DriverList[idx].alcMakeContextCurrent(context))
- {
- almtx_unlock(&ContextSwitchLock);
return ALC_FALSE;
- }
}
/* Unset the context from the old driver if it's different from the new
@@ -477,24 +471,21 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
*/
if(idx < 0)
{
- DriverIface *oldiface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));
+ DriverIface *oldiface = ThreadCtxDriver;
if(oldiface) oldiface->alcSetThreadContext(nullptr);
- oldiface = reinterpret_cast<DriverIface*>(
- ATOMIC_EXCHANGE_PTR_SEQ(&CurrentCtxDriver, (DriverIface*){nullptr}));
+ oldiface = CurrentCtxDriver.exchange(nullptr);
if(oldiface) oldiface->alcMakeContextCurrent(nullptr);
}
else
{
- DriverIface *oldiface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));
+ DriverIface *oldiface = ThreadCtxDriver;
if(oldiface && oldiface != &DriverList[idx])
oldiface->alcSetThreadContext(nullptr);
- oldiface = reinterpret_cast<DriverIface*>(
- ATOMIC_EXCHANGE_PTR_SEQ(&CurrentCtxDriver, &DriverList[idx]));
+ oldiface = CurrentCtxDriver.exchange(&DriverList[idx]);
if(oldiface && oldiface != &DriverList[idx])
oldiface->alcMakeContextCurrent(nullptr);
}
- almtx_unlock(&ContextSwitchLock);
- altss_set(ThreadCtxDriver, nullptr);
+ ThreadCtxDriver = nullptr;
return ALC_TRUE;
}
@@ -507,7 +498,7 @@ ALC_API void ALC_APIENTRY alcProcessContext(ALCcontext *context)
if(idx >= 0)
return DriverList[idx].alcProcessContext(context);
}
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
+ LastError.store(ALC_INVALID_CONTEXT);
}
ALC_API void ALC_APIENTRY alcSuspendContext(ALCcontext *context)
@@ -518,7 +509,7 @@ ALC_API void ALC_APIENTRY alcSuspendContext(ALCcontext *context)
if(idx >= 0)
return DriverList[idx].alcSuspendContext(context);
}
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
+ LastError.store(ALC_INVALID_CONTEXT);
}
ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context)
@@ -527,7 +518,7 @@ ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context)
if(!context || (idx=LookupPtrIntMapKey(&ContextIfaceMap, context)) < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
+ LastError.store(ALC_INVALID_CONTEXT);
return;
}
@@ -537,8 +528,8 @@ ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context)
ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void)
{
- DriverIface *iface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));
- if(!iface) iface = ATOMIC_LOAD_SEQ(&CurrentCtxDriver);
+ DriverIface *iface = ThreadCtxDriver;
+ if(!iface) iface = CurrentCtxDriver.load();
return iface ? iface->alcGetCurrentContext() : nullptr;
}
@@ -550,7 +541,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *context)
if(idx >= 0)
return DriverList[idx].alcGetContextsDevice(context);
}
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
+ LastError.store(ALC_INVALID_CONTEXT);
return nullptr;
}
@@ -563,7 +554,7 @@ ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
if(idx < 0) return ALC_INVALID_DEVICE;
return DriverList[idx].alcGetError(device);
}
- return ATOMIC_EXCHANGE_SEQ(&LastError, ALC_NO_ERROR);
+ return LastError.exchange(ALC_NO_ERROR);
}
ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extname)
@@ -576,7 +567,7 @@ ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const A
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
if(idx < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ LastError.store(ALC_INVALID_DEVICE);
return ALC_FALSE;
}
return DriverList[idx].alcIsExtensionPresent(device, extname);
@@ -607,7 +598,7 @@ ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *f
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
if(idx < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ LastError.store(ALC_INVALID_DEVICE);
return nullptr;
}
return DriverList[idx].alcGetProcAddress(device, funcname);
@@ -630,7 +621,7 @@ ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *e
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
if(idx < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ LastError.store(ALC_INVALID_DEVICE);
return 0;
}
return DriverList[idx].alcGetEnumValue(device, enumname);
@@ -653,7 +644,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
if(idx < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ LastError.store(ALC_INVALID_DEVICE);
return nullptr;
}
return DriverList[idx].alcGetString(device, param);
@@ -677,7 +668,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
return alcExtensionList;
case ALC_DEVICE_SPECIFIER:
- almtx_lock(&EnumerationLock);
+ { std::lock_guard<std::mutex> _{EnumerationLock};
ClearDeviceList(&DevicesList);
for(i = 0;i < DriverListSize;i++)
{
@@ -688,11 +679,11 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
DriverList[i].alcGetString(nullptr, ALC_DEVICE_SPECIFIER), i
);
}
- almtx_unlock(&EnumerationLock);
return DevicesList.Names;
+ }
case ALC_ALL_DEVICES_SPECIFIER:
- almtx_lock(&EnumerationLock);
+ { std::lock_guard<std::mutex> _{EnumerationLock};
ClearDeviceList(&AllDevicesList);
for(i = 0;i < DriverListSize;i++)
{
@@ -709,11 +700,11 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
DriverList[i].alcGetString(nullptr, ALC_DEVICE_SPECIFIER), i
);
}
- almtx_unlock(&EnumerationLock);
return AllDevicesList.Names;
+ }
case ALC_CAPTURE_DEVICE_SPECIFIER:
- almtx_lock(&EnumerationLock);
+ { std::lock_guard<std::mutex> _{EnumerationLock};
ClearDeviceList(&CaptureDevicesList);
for(i = 0;i < DriverListSize;i++)
{
@@ -723,8 +714,8 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
DriverList[i].alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER), i
);
}
- almtx_unlock(&EnumerationLock);
return CaptureDevicesList.Names;
+ }
case ALC_DEFAULT_DEVICE_SPECIFIER:
for(i = 0;i < DriverListSize;i++)
@@ -753,7 +744,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
return "";
default:
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_ENUM);
+ LastError.store(ALC_INVALID_ENUM);
break;
}
return nullptr;
@@ -766,7 +757,7 @@ ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsi
ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
if(idx < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ LastError.store(ALC_INVALID_DEVICE);
return;
}
return DriverList[idx].alcGetIntegerv(device, param, size, values);
@@ -774,7 +765,7 @@ ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsi
if(size <= 0 || values == nullptr)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
+ LastError.store(ALC_INVALID_VALUE);
return;
}
@@ -793,7 +784,7 @@ ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsi
values[0] = alcMinorVersion;
return;
}
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
+ LastError.store(ALC_INVALID_VALUE);
return;
case ALC_ATTRIBUTES_SIZE:
@@ -804,11 +795,11 @@ ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsi
case ALC_MONO_SOURCES:
case ALC_STEREO_SOURCES:
case ALC_CAPTURE_SAMPLES:
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ LastError.store(ALC_INVALID_DEVICE);
return;
default:
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_ENUM);
+ LastError.store(ALC_INVALID_ENUM);
return;
}
}
@@ -823,14 +814,15 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename,
devicename = nullptr;
if(devicename)
{
- almtx_lock(&EnumerationLock);
- if(!CaptureDevicesList.Names)
- (void)alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER);
- idx = GetDriverIndexForName(&CaptureDevicesList, devicename);
- almtx_unlock(&EnumerationLock);
+ { std::lock_guard<std::mutex> _{EnumerationLock};
+ if(!CaptureDevicesList.Names)
+ (void)alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER);
+ idx = GetDriverIndexForName(&CaptureDevicesList, devicename);
+ }
+
if(idx < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
+ LastError.store(ALC_INVALID_VALUE);
TRACE("Failed to find driver for name \"%s\"\n", devicename);
return nullptr;
}
@@ -875,7 +867,7 @@ ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device)
if(!device || (idx=LookupPtrIntMapKey(&DeviceIfaceMap, device)) < 0)
{
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ LastError.store(ALC_INVALID_DEVICE);
return ALC_FALSE;
}
if(!DriverList[idx].alcCaptureCloseDevice(device))
@@ -892,7 +884,7 @@ ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
if(idx >= 0)
return DriverList[idx].alcCaptureStart(device);
}
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ LastError.store(ALC_INVALID_DEVICE);
}
ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
@@ -903,7 +895,7 @@ ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
if(idx >= 0)
return DriverList[idx].alcCaptureStop(device);
}
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ LastError.store(ALC_INVALID_DEVICE);
}
ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
@@ -914,7 +906,7 @@ ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer,
if(idx >= 0)
return DriverList[idx].alcCaptureSamples(device, buffer, samples);
}
- ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ LastError.store(ALC_INVALID_DEVICE);
}
@@ -925,10 +917,10 @@ ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
if(!context)
{
- DriverIface *oldiface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));
+ DriverIface *oldiface = ThreadCtxDriver;
if(oldiface && !oldiface->alcSetThreadContext(nullptr))
return ALC_FALSE;
- altss_set(ThreadCtxDriver, nullptr);
+ ThreadCtxDriver = nullptr;
return ALC_TRUE;
}
@@ -937,23 +929,23 @@ ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
{
if(DriverList[idx].alcSetThreadContext(context))
{
- DriverIface *oldiface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));
+ DriverIface *oldiface = ThreadCtxDriver;
if(oldiface != &DriverList[idx])
{
- altss_set(ThreadCtxDriver, &DriverList[idx]);
+ ThreadCtxDriver = &DriverList[idx];
if(oldiface) oldiface->alcSetThreadContext(nullptr);
}
return ALC_TRUE;
}
err = DriverList[idx].alcGetError(nullptr);
}
- ATOMIC_STORE_SEQ(&LastError, err);
+ LastError.store(err);
return ALC_FALSE;
}
ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
{
- DriverIface *iface = reinterpret_cast<DriverIface*>(altss_get(ThreadCtxDriver));
+ DriverIface *iface = ThreadCtxDriver;
if(iface) return iface->alcGetThreadContext();
return nullptr;
}
diff --git a/router/router.cpp b/router/router.cpp
index 13cd3c69..95c0101d 100644
--- a/router/router.cpp
+++ b/router/router.cpp
@@ -18,7 +18,7 @@ DriverIface *DriverList = nullptr;
int DriverListSize = 0;
static int DriverListSizeMax = 0;
-altss_t ThreadCtxDriver;
+thread_local DriverIface *ThreadCtxDriver;
enum LogLevel LogLevel = LogLevel_Error;
FILE *LogFile;
@@ -59,19 +59,16 @@ BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reser
TRACE("Initializing router v0.1-%s %s\n", ALSOFT_GIT_COMMIT_HASH, ALSOFT_GIT_BRANCH);
LoadDriverList();
- altss_create(&ThreadCtxDriver, nullptr);
InitALC();
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
- althrd_thread_detach();
break;
case DLL_PROCESS_DETACH:
ReleaseALC();
- altss_delete(ThreadCtxDriver);
for(i = 0;i < DriverListSize;i++)
{
@@ -87,7 +84,6 @@ BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reser
fclose(LogFile);
LogFile = nullptr;
- althrd_deinit();
break;
}
return TRUE;
diff --git a/router/router.h b/router/router.h
index 36c825d4..1a86da02 100644
--- a/router/router.h
+++ b/router/router.h
@@ -7,12 +7,12 @@
#include <stdio.h>
+#include <atomic>
+
#include "AL/alc.h"
#include "AL/al.h"
#include "AL/alext.h"
-#include "atomic.h"
#include "rwlock.h"
-#include "threads.h"
#ifdef __cplusplus
@@ -140,9 +140,8 @@ typedef struct DriverIface {
extern DriverIface *DriverList;
extern int DriverListSize;
-extern altss_t ThreadCtxDriver;
-typedef ATOMIC(DriverIface*) atomic_DriverIfacePtr;
-extern atomic_DriverIfacePtr CurrentCtxDriver;
+extern thread_local DriverIface *ThreadCtxDriver;
+extern std::atomic<DriverIface*> CurrentCtxDriver;
typedef struct PtrIntMap {
@@ -154,7 +153,7 @@ typedef struct PtrIntMap {
ALsizei capacity;
RWLock lock;
} PtrIntMap;
-#define PTRINTMAP_STATIC_INITIALIZE { NULL, NULL, 0, 0, RWLOCK_STATIC_INITIALIZE }
+#define PTRINTMAP_STATIC_INITIALIZE { nullptr, nullptr, 0, 0, RWLOCK_STATIC_INITIALIZE }
void InitPtrIntMap(PtrIntMap *map);
void ResetPtrIntMap(PtrIntMap *map);