From 1594c2bed927ae6f2745a90f1c86a6e9fd01cc28 Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 28 Apr 2016 17:29:27 +1000 Subject: [PATCH] [Common] Make SyncEvent.cpp more android friendly --- Source/Common/SyncEvent.cpp | 50 +++++++++++++++++++++++++++++++++---- Source/Common/SyncEvent.h | 4 +++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/Source/Common/SyncEvent.cpp b/Source/Common/SyncEvent.cpp index 34266a5a4..6a3d2dcce 100644 --- a/Source/Common/SyncEvent.cpp +++ b/Source/Common/SyncEvent.cpp @@ -1,29 +1,69 @@ #include "stdafx.h" -#include +#ifdef _WIN32 +#include +#endif SyncEvent::SyncEvent(bool bManualReset) { - m_Event = CreateEvent(NULL, bManualReset, false, NULL); +#ifdef _WIN32 + m_Event = CreateEvent(NULL, bManualReset, FALSE, NULL); +#else + m_signalled = false; + m_Event = new pthread_mutex_t; + m_cond = new pthread_cond_t; + pthread_mutex_init((pthread_mutex_t*)m_Event,NULL); + pthread_cond_init((pthread_cond_t*)m_cond, NULL); +#endif } SyncEvent::~SyncEvent() { +#ifdef _WIN32 CloseHandle(m_Event); +#else + pthread_mutex_destroy((pthread_mutex_t*)m_Event); + pthread_cond_destroy((pthread_cond_t*)m_cond); + delete (pthread_mutex_t*)m_Event; + delete (pthread_cond_t*)m_cond; +#endif } void SyncEvent::Trigger() { - SetEvent(m_Event); +#ifdef _WIN32 + SetEvent(m_Event); +#else + pthread_mutex_lock((pthread_mutex_t*)m_Event); + m_signalled = true; + pthread_mutex_unlock((pthread_mutex_t*)m_Event); + pthread_cond_signal((pthread_cond_t*)m_cond); +#endif } bool SyncEvent::IsTriggered(int32_t iWaitTime) { - return (WAIT_OBJECT_0 == WaitForSingleObject(m_Event,iWaitTime)); +#ifdef _WIN32 + return (WAIT_OBJECT_0 == WaitForSingleObject(m_Event,iWaitTime)); +#else + pthread_mutex_lock((pthread_mutex_t*)m_Event); + while (!m_signalled) + { + pthread_cond_wait((pthread_cond_t*)m_cond, (pthread_mutex_t*)m_Event); + } + m_signalled = false; + pthread_mutex_unlock((pthread_mutex_t*)m_Event); +#endif } void SyncEvent::Reset() { - ResetEvent(m_Event); +#ifdef _WIN32 + ResetEvent(m_Event); +#else +#ifdef tofix + pthread_mutex_unlock(&evt.m_mutex); +#endif +#endif } void * SyncEvent::GetHandle() diff --git a/Source/Common/SyncEvent.h b/Source/Common/SyncEvent.h index 3b95e8c77..f1aa332dd 100644 --- a/Source/Common/SyncEvent.h +++ b/Source/Common/SyncEvent.h @@ -18,4 +18,8 @@ protected: SyncEvent& operator=(const SyncEvent&); // Disable assignment void * m_Event; +#ifndef _WIN32 + void * m_cond; + bool m_signalled; +#endif }; \ No newline at end of file