diff --git a/src/common/threading.cpp b/src/common/threading.cpp index 3ee9f4c94a..2012fcb229 100644 --- a/src/common/threading.cpp +++ b/src/common/threading.cpp @@ -610,10 +610,15 @@ Threading::KernelSemaphore::KernelSemaphore() { #ifdef _WIN32 m_sema = CreateSemaphore(nullptr, 0, LONG_MAX, nullptr); + if (m_sema == NULL) [[unlikely]] + Panic("CreateSemaphore() failed"); #elif defined(__APPLE__) - semaphore_create(mach_task_self(), &m_sema, SYNC_POLICY_FIFO, 0); + const kern_return_t kr = semaphore_create(mach_task_self(), &m_sema, SYNC_POLICY_FIFO, 0); + if (kr != KERN_SUCCESS) [[unlikely]] + Panic("CreateSemaphore() failed"); #else - sem_init(&m_sema, false, 0); + if (sem_init(&m_sema, false, 0) != 0) [[unlikely]] + Panic("sem_init() failed"); #endif } diff --git a/src/common/threading.h b/src/common/threading.h index 38dbe27faf..4b8934f40f 100644 --- a/src/common/threading.h +++ b/src/common/threading.h @@ -107,10 +107,21 @@ class Thread : public ThreadHandle u32 m_stack_size = 0; }; -/// A semaphore that may not have a fast userspace path -/// (Used in other semaphore-based algorithms where the semaphore is just used for its thread sleep/wake ability) +/// A semaphore that requires a system call to wake/sleep. class KernelSemaphore { +public: + KernelSemaphore(); + KernelSemaphore(const KernelSemaphore&) = delete; + ~KernelSemaphore(); + + KernelSemaphore& operator=(const KernelSemaphore&) = delete; + + void Post(); + void Wait(); + bool TryWait(); + +private: #if defined(_WIN32) void* m_sema; #elif defined(__APPLE__) @@ -118,12 +129,6 @@ class KernelSemaphore #else sem_t m_sema; #endif -public: - KernelSemaphore(); - ~KernelSemaphore(); - void Post(); - void Wait(); - bool TryWait(); }; } // namespace Threading \ No newline at end of file