30 namespace log4cplus {
namespace thread {
33 #define LOG4CPLUS_THROW_RTE(msg) \
34 do { detail::syncprims_throw_exception (msg, __FILE__, __LINE__); } while (0)
43 int ret = pthread_mutex_init (&mtx, 0);
45 LOG4CPLUS_THROW_RTE (
"Mutex::Mutex");
52 int ret = pthread_mutex_destroy (&mtx);
54 LOG4CPLUS_THROW_RTE (
"Mutex::~Mutex");
62 int ret = pthread_mutex_lock (&mtx);
64 LOG4CPLUS_THROW_RTE (
"Mutex::lock");
70 Mutex::unlock ()
const
72 int ret = pthread_mutex_unlock (&mtx);
74 LOG4CPLUS_THROW_RTE (
"Mutex::unlock");
83 Semaphore::Semaphore (
unsigned max,
unsigned initial)
85 int ret = sem_init (&sem, max, initial);
87 LOG4CPLUS_THROW_RTE (
"Semaphore::Semaphore");
92 Semaphore::~Semaphore ()
95 int ret = sem_destroy (&sem);
97 LOG4CPLUS_THROW_RTE (
"Semaphore::~Semaphore");
105 Semaphore::unlock ()
const
107 int ret = sem_post (&sem);
109 LOG4CPLUS_THROW_RTE (
"Semaphore::unlock");
115 Semaphore::lock ()
const
117 int ret = sem_wait (&sem);
119 LOG4CPLUS_THROW_RTE (
"Semaphore::lock");
128 ManualResetEvent::ManualResetEvent (
bool sig)
132 int ret = pthread_cond_init (&cv, 0);
134 LOG4CPLUS_THROW_RTE (
"ManualResetEvent::ManualResetEvent");
139 ManualResetEvent::~ManualResetEvent ()
142 int ret = pthread_cond_destroy (&cv);
144 LOG4CPLUS_THROW_RTE (
"ManualResetEvent::~ManualResetEvent");
152 ManualResetEvent::signal ()
const
154 MutexGuard mguard (mtx);
158 int ret = pthread_cond_broadcast (&cv);
160 LOG4CPLUS_THROW_RTE (
"ManualResetEVent::signal");
167 ManualResetEvent::wait ()
const
169 MutexGuard mguard (mtx);
173 unsigned prev_count = sigcount;
176 int ret = pthread_cond_wait (&cv, &mtx.mtx);
181 LOG4CPLUS_THROW_RTE (
"ManualResetEvent::wait");
184 while (prev_count == sigcount);
191 ManualResetEvent::timed_wait (
unsigned long msec)
const
193 MutexGuard mguard (mtx);
198 + helpers::Time (msec / 1000, (msec % 1000) * 1000));
199 struct timespec const ts = {wakeup_time.sec (),
200 wakeup_time.usec () * 1000};
201 unsigned prev_count = sigcount;
204 int ret = pthread_cond_timedwait (&cv, &mtx.mtx, &ts);
216 LOG4CPLUS_THROW_RTE (
"ManualResetEvent::timed_wait");
219 while (prev_count == sigcount);
228 ManualResetEvent::reset ()
const
230 MutexGuard mguard (mtx);
236 #undef LOG4CPLUS_THROW_RTE