From 0330fa9e87e7d565d8a5b9fe3f75dc4a6a5e4ce1 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 7 Nov 2004 22:56:03 +0000 Subject: [PATCH] untested pthreads event implementation --- .../src/arch/Threads/Threads_Pthreads.cpp | 33 +++++++++++++++++++ stepmania/src/arch/Threads/Threads_Pthreads.h | 19 ++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/stepmania/src/arch/Threads/Threads_Pthreads.cpp b/stepmania/src/arch/Threads/Threads_Pthreads.cpp index ed2d302f41..2d627821fe 100644 --- a/stepmania/src/arch/Threads/Threads_Pthreads.cpp +++ b/stepmania/src/arch/Threads/Threads_Pthreads.cpp @@ -204,6 +204,39 @@ MutexImpl *MakeMutex( RageMutex *pParent ) return new MutexImpl_Pthreads( pParent ); } +EventImpl_Pthreads::EventImpl_Pthreads( MutexImpl_Pthreads *pParent ) +{ + m_pParent = pParent; + pthread_cond_init( &m_Cond, NULL ); +} + +EventImpl_Pthreads::~EventImpl_Pthreads() +{ + pthread_cond_destroy( &m_Cond ); +} + +void EventImpl_Pthreads::Wait() +{ + pthread_cond_wait( &m_Cond, &m_pParent->mutex ); +} + +void EventImpl_Pthreads::Signal() +{ + pthread_cond_signal( &m_Cond ); +} + +void EventImpl_Pthreads::Broadcast() +{ + pthread_cond_broadcast( &m_Cond ); +} + +EventImpl *MakeEvent( MutexImpl *pMutex ) +{ + MutexImpl_Pthreads *pPthreadsMutex = (MutexImpl_Pthreads *) pMutex; + + return new EventImpl_Pthreads( pPthreadsMutex ); +} + #if 0 SemaImpl_Pthreads::SemaImpl_Pthreads( int iInitialValue ) { diff --git a/stepmania/src/arch/Threads/Threads_Pthreads.h b/stepmania/src/arch/Threads/Threads_Pthreads.h index 263bc0073b..3983fcd9ab 100644 --- a/stepmania/src/arch/Threads/Threads_Pthreads.h +++ b/stepmania/src/arch/Threads/Threads_Pthreads.h @@ -32,6 +32,8 @@ public: class MutexImpl_Pthreads: public MutexImpl { + friend class EventImpl_Pthreads; + public: MutexImpl_Pthreads( RageMutex *parent ); ~MutexImpl_Pthreads(); @@ -40,10 +42,25 @@ public: bool TryLock(); void Unlock(); -private: +protected: pthread_mutex_t mutex; }; +class EventImpl_Pthreads: public EventImpl +{ +public: + EventImpl_Pthreads( MutexImpl_Pthreads *pParent ); + ~EventImpl_Pthreads(); + + void Wait(); + void Signal(); + void Broadcast(); + +private: + MutexImpl_Pthreads *m_pParent; + pthread_cond_t m_Cond; +}; + #if 0 class SemaImpl_Pthreads: public SemaImpl {