/*
* This file is part of the libCEC(R) library.
*
- * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
* libCEC(R) is an original work, containing original code.
*
* libCEC(R) is a trademark of Pulse-Eight Limited.
#define MutexTryLock(mutex) (pthread_mutex_trylock(&mutex) == 0)
#define MutexUnlock(mutex) pthread_mutex_unlock(&mutex)
- typedef pthread_cond_t condition_t;
- #define ConditionCreate(cond) pthread_cond_init(&cond, NULL)
- #define ConditionDelete(cond) pthread_cond_destroy(&cond)
- #define ConditionSignal(cond) pthread_cond_signal(&cond)
- #define ConditionBroadcast(cond) pthread_cond_broadcast(&cond)
- inline bool ConditionWait(condition_t &cond, mutex_t &mutex, uint32_t iTimeout)
+ class CConditionImpl
{
- sched_yield();
- if (iTimeout > 0)
+ public:
+ CConditionImpl(void)
{
- struct timespec timeout = GetAbsTime(iTimeout);
- return (pthread_cond_timedwait(&cond, &mutex, &timeout) == 0);
+ pthread_cond_init(&m_condition, NULL);
}
- return (pthread_cond_wait(&cond, &mutex) == 0);
- }
+
+ virtual ~CConditionImpl(void)
+ {
+ pthread_cond_destroy(&m_condition);
+ }
+
+ void Signal(void)
+ {
+ pthread_cond_signal(&m_condition);
+ }
+
+ void Broadcast(void)
+ {
+ pthread_cond_broadcast(&m_condition);
+ }
+
+ bool Wait(mutex_t &mutex, uint32_t iTimeoutMs)
+ {
+ sched_yield();
+ if (iTimeoutMs > 0)
+ {
+ struct timespec timeout = GetAbsTime(iTimeoutMs);
+ return (pthread_cond_timedwait(&m_condition, &mutex, &timeout) == 0);
+ }
+ return (pthread_cond_wait(&m_condition, &mutex) == 0);
+ }
+
+ pthread_cond_t m_condition;
+ };
}