diff options
| author | Greg Clayton <gclayton@apple.com> | 2011-01-14 23:37:51 +0000 |
|---|---|---|
| committer | Greg Clayton <gclayton@apple.com> | 2011-01-14 23:37:51 +0000 |
| commit | 714ab86491d2e8686b4d53fa98739e193f276d11 (patch) | |
| tree | 671e59182c5f5f56e7f477b640c54a9d7f4c104d | |
| parent | e92b6e436d15f65563973f1bc9354611ad9a316d (diff) | |
| download | bcm5719-llvm-714ab86491d2e8686b4d53fa98739e193f276d11.tar.gz bcm5719-llvm-714ab86491d2e8686b4d53fa98739e193f276d11.zip | |
Added the ability to wait for a predicate value, and set it to a new value all in a thread safe fashion.
llvm-svn: 123492
| -rw-r--r-- | lldb/include/lldb/Host/Predicate.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lldb/include/lldb/Host/Predicate.h b/lldb/include/lldb/Host/Predicate.h index 9b244dea849..0a81149a6bb 100644 --- a/lldb/include/lldb/Host/Predicate.h +++ b/lldb/include/lldb/Host/Predicate.h @@ -320,6 +320,38 @@ public: 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. /// |

