aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32/event.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-18 18:04:27 -0800
committerChris Robinson <[email protected]>2018-11-18 18:04:27 -0800
commitb10e7d08c34bc6d46aaf61ef2a0183e7841b75f3 (patch)
tree52ec62d347eab96dc64beef40fcbfa6bdf7db905 /OpenAL32/event.cpp
parentef7995cfd086dd1b32d85bf214b66da37e6550c5 (diff)
Use a std::thread for the event thread
Diffstat (limited to 'OpenAL32/event.cpp')
-rw-r--r--OpenAL32/event.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/OpenAL32/event.cpp b/OpenAL32/event.cpp
index 67a10645..e4b5eee0 100644
--- a/OpenAL32/event.cpp
+++ b/OpenAL32/event.cpp
@@ -15,10 +15,8 @@
#include "threads.h"
-int EventThread(void *arg)
+static int EventThread(ALCcontext *context)
{
- auto context = static_cast<ALCcontext*>(arg);
-
bool quitnow{false};
while(LIKELY(!quitnow))
{
@@ -50,6 +48,29 @@ int EventThread(void *arg)
return 0;
}
+void StartEventThrd(ALCcontext *ctx)
+{
+ try {
+ ctx->EventThread = std::thread(EventThread, ctx);
+ }
+ catch(std::exception& e) {
+ ERR("Failed to start event thread: %s\n", e.what());
+ }
+ catch(...) {
+ ERR("Failed to start event thread! Expect problems.\n");
+ }
+}
+
+void StopEventThrd(ALCcontext *ctx)
+{
+ static constexpr AsyncEvent kill_evt = ASYNC_EVENT(EventType_KillThread);
+ while(ll_ringbuffer_write(ctx->AsyncEvents, (const char*)&kill_evt, 1) == 0)
+ althrd_yield();
+ alsem_post(&ctx->EventSem);
+ if(ctx->EventThread.joinable())
+ ctx->EventThread.join();
+}
+
AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, ALboolean enable)
{
ContextRef context{GetContextRef()};