diff options
author | Greg Clayton <gclayton@apple.com> | 2010-09-07 20:11:56 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2010-09-07 20:11:56 +0000 |
commit | 2bddd3442f7c40a6203bc85c5690e96858ae8e04 (patch) | |
tree | 61919ec0dcb54ad460c36b2bf7d226a983a9fd7a /lldb/source/Host/common/Condition.cpp | |
parent | 3c8019c94d5883fd35e665d64f4df3556849f1d5 (diff) | |
download | bcm5719-llvm-2bddd3442f7c40a6203bc85c5690e96858ae8e04.tar.gz bcm5719-llvm-2bddd3442f7c40a6203bc85c5690e96858ae8e04.zip |
Patch from Jay Cornwall that modifies the LLDB "Host" layer to reuse more
code between linux, darwin and BSD.
llvm-svn: 113263
Diffstat (limited to 'lldb/source/Host/common/Condition.cpp')
-rw-r--r-- | lldb/source/Host/common/Condition.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/lldb/source/Host/common/Condition.cpp b/lldb/source/Host/common/Condition.cpp new file mode 100644 index 00000000000..4e93db766db --- /dev/null +++ b/lldb/source/Host/common/Condition.cpp @@ -0,0 +1,106 @@ +//===-- Condition.cpp -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <errno.h> + +#include "lldb/Host/Condition.h" +#include "lldb/Host/TimeValue.h" + + +using namespace lldb_private; + +//---------------------------------------------------------------------- +// Default constructor +// +// The default constructor will initialize a new pthread condition +// and maintain the condition in the object state. +//---------------------------------------------------------------------- +Condition::Condition () : + m_condition() +{ + ::pthread_cond_init (&m_condition, NULL); +} + +//---------------------------------------------------------------------- +// Destructor +// +// Destroys the pthread condition that the object owns. +//---------------------------------------------------------------------- +Condition::~Condition () +{ + ::pthread_cond_destroy (&m_condition); +} + +//---------------------------------------------------------------------- +// Unblock all threads waiting for a condition variable +//---------------------------------------------------------------------- +int +Condition::Broadcast () +{ + return ::pthread_cond_broadcast (&m_condition); +} + +//---------------------------------------------------------------------- +// Get accessor to the pthread condition object +//---------------------------------------------------------------------- +pthread_cond_t * +Condition::GetCondition () +{ + return &m_condition; +} + +//---------------------------------------------------------------------- +// Unblocks one thread waiting for the condition variable +//---------------------------------------------------------------------- +int +Condition::Signal () +{ + return ::pthread_cond_signal (&m_condition); +} + +//---------------------------------------------------------------------- +// The Wait() function atomically blocks the current thread +// waiting on the owend condition variable, and unblocks the mutex +// specified by "mutex". The waiting thread unblocks only after +// another thread calls Signal(), or Broadcast() with the same +// condition variable, or if "abstime" is valid (non-NULL) this +// function will return when the system time reaches the time +// specified in "abstime". If "abstime" is NULL this function will +// wait for an infinite amount of time for the condition variable +// to be signaled or broadcasted. +// +// The current thread re-acquires the lock on "mutex". +//---------------------------------------------------------------------- +int +Condition::Wait (pthread_mutex_t *mutex, const TimeValue *abstime, bool *timed_out) +{ + int err = 0; + do + { + if (abstime && abstime->IsValid()) + { + struct timespec abstime_ts = abstime->GetAsTimeSpec(); + err = ::pthread_cond_timedwait (&m_condition, mutex, &abstime_ts); + } + else + err = ::pthread_cond_wait (&m_condition, mutex); + } while (err == EINTR); + + if (timed_out != NULL) + { + if (err == ETIMEDOUT) + *timed_out = true; + else + *timed_out = false; + } + + + return err; +} + |