[Lldb-commits] [lldb] r123492 - /lldb/trunk/include/lldb/Host/Predicate.h
Greg Clayton
gclayton at apple.com
Fri Jan 14 15:37:51 PST 2011
Author: gclayton
Date: Fri Jan 14 17:37:51 2011
New Revision: 123492
URL: http://llvm.org/viewvc/llvm-project?rev=123492&view=rev
Log:
Added the ability to wait for a predicate value, and set it to a new value all in a thread safe fashion.
Modified:
lldb/trunk/include/lldb/Host/Predicate.h
Modified: lldb/trunk/include/lldb/Host/Predicate.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Predicate.h?rev=123492&r1=123491&r2=123492&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Predicate.h (original)
+++ lldb/trunk/include/lldb/Host/Predicate.h Fri Jan 14 17:37:51 2011
@@ -320,6 +320,38 @@
return m_value == value;
}
+ bool
+ WaitForValueEqualToAndSetValueTo (T wait_value, T new_value, const TimeValue *abstime = NULL, bool *timed_out = NULL)
+ {
+ int err = 0;
+ // pthread_cond_timedwait() or pthread_cond_wait() will atomically
+ // unlock the mutex and wait for the condition to be set. When either
+ // function returns, they will re-lock the mutex. We use an auto lock/unlock
+ // class (Mutex::Locker) to allow us to return at any point in this
+ // function and not have to worry about unlocking the mutex.
+ Mutex::Locker locker(m_mutex);
+
+#ifdef DB_PTHREAD_LOG_EVENTS
+ printf("%s (value = 0x%8.8x, abstime = %p), m_value = 0x%8.8x", __FUNCTION__, value, abstime, m_value);
+#endif
+ if (timed_out)
+ *timed_out = false;
+
+ while (err == 0 && m_value != wait_value)
+ {
+ err = m_condition.Wait (m_mutex.GetMutex(), abstime, timed_out);
+ }
+
+ if (m_value == wait_value)
+ {
+ m_value = new_value;
+ return true;
+ }
+
+ return false;
+ }
+
+
//------------------------------------------------------------------
/// Wait for \a m_value to not be equal to \a value.
///
More information about the lldb-commits
mailing list