Common/Event: Replace poll event with lock/condvar
This commit is contained in:
@ -1,6 +1,20 @@
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
|
||||
// #define USE_WIN32_EVENT_OBJECTS 1
|
||||
|
||||
#if defined(WIN32) && !defined(USE_WIN32_EVENT_OBJECTS)
|
||||
#include "windows_headers.h"
|
||||
#include <atomic>
|
||||
#elif defined(__linux__) || defined(__APPLE__) || defined(__HAIKU__)
|
||||
#include <atomic>
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#endif
|
||||
|
||||
namespace Common {
|
||||
|
||||
class Event
|
||||
@ -17,13 +31,26 @@ public:
|
||||
static void WaitForMultiple(Event** events, u32 num_events);
|
||||
|
||||
private:
|
||||
#ifdef WIN32
|
||||
#if defined(WIN32) && defined(USE_WIN32_EVENT_OBJECTS)
|
||||
void* m_event_handle;
|
||||
#elif defined(WIN32)
|
||||
CRITICAL_SECTION m_cs;
|
||||
CONDITION_VARIABLE m_cv;
|
||||
std::atomic_uint32_t m_waiters{0};
|
||||
std::atomic_bool m_signaled{false};
|
||||
bool m_auto_reset = false;
|
||||
#elif defined(__linux__) || defined(__APPLE__) || defined(__HAIKU__)
|
||||
int m_pipe_fds[2];
|
||||
bool m_auto_reset;
|
||||
pthread_mutex_t m_mutex;
|
||||
pthread_cond_t m_cv;
|
||||
std::atomic_uint32_t m_waiters{0};
|
||||
std::atomic_bool m_signaled{false};
|
||||
bool m_auto_reset = false;
|
||||
#else
|
||||
#error Unknown platform.
|
||||
std::mutex m_mutex;
|
||||
std::condition_variable m_cv;
|
||||
std::atomic_uint32_t m_waiters{0};
|
||||
std::atomic_bool m_signaled{false};
|
||||
bool m_auto_reset = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user