Common/Event: Replace poll event with lock/condvar

This commit is contained in:
Connor McLaughlin
2020-10-25 19:47:22 +10:00
parent 9f3e8bed86
commit dc53209565
2 changed files with 191 additions and 56 deletions

View File

@ -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
};