|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85784 - trunk/boost/sync/detail/event
From: tim_at_[hidden]
Date: 2013-09-19 04:15:37
Author: timblechmann
Date: 2013-09-19 04:15:37 EDT (Thu, 19 Sep 2013)
New Revision: 85784
URL: http://svn.boost.org/trac/boost/changeset/85784
Log:
sync: event - cv emulation should use shared locking to allow multiple waiters
Text files modified:
trunk/boost/sync/detail/event/event_emulation.hpp | 31 ++++++++++++++++---------------
1 files changed, 16 insertions(+), 15 deletions(-)
Modified: trunk/boost/sync/detail/event/event_emulation.hpp
==============================================================================
--- trunk/boost/sync/detail/event/event_emulation.hpp Thu Sep 19 02:01:46 2013 (r85783)
+++ trunk/boost/sync/detail/event/event_emulation.hpp 2013-09-19 04:15:37 EDT (Thu, 19 Sep 2013) (r85784)
@@ -10,7 +10,7 @@
#define BOOST_SYNC_DETAIL_EVENT_EVENT_EMULATION_HPP_INCLUDED_
#include <boost/thread/condition_variable.hpp>
-#include <boost/thread/mutex.hpp>
+#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/sync/detail/config.hpp>
@@ -36,7 +36,7 @@
void post()
{
- unique_lock<mutex> lock(m_mutex);
+ unique_lock<upgrade_mutex> lock(m_mutex);
bool already_signaled = m_is_set;
m_is_set = true;
if (m_auto_reset) {
@@ -48,24 +48,26 @@
void wait()
{
- unique_lock<mutex> lock(m_mutex);
+ upgrade_lock<upgrade_mutex> lock(m_mutex);
while (!m_is_set)
m_cond.wait(lock);
- if (m_auto_reset)
+ if (m_auto_reset) {
+ upgrade_to_unique_lock<upgrade_mutex> unique_lock(lock);
m_is_set = false;
+ }
}
void reset()
{
- lock_guard<mutex> lock(m_mutex);
+ lock_guard<upgrade_mutex> lock(m_mutex);
m_is_set = false;
}
bool try_wait()
{
- lock_guard<mutex> lock(m_mutex);
+ lock_guard<upgrade_mutex> lock(m_mutex);
const bool res = m_is_set;
if (res && m_auto_reset)
m_is_set = false;
@@ -81,27 +83,26 @@
template <class Clock, class Duration>
bool try_wait_until(const chrono::time_point<Clock, Duration> & timeout)
{
- unique_lock<mutex> lock(m_mutex);
+ upgrade_lock<upgrade_mutex> lock(m_mutex);
- while (!m_is_set)
- {
- if (m_cond.wait_until(lock, timeout) == cv_status::timeout)
- {
+ while (!m_is_set) {
+ if (m_cond.wait_until(lock, timeout) == cv_status::timeout) {
if (!m_is_set)
return false;
break;
}
}
- if (m_auto_reset)
+ if (m_auto_reset) {
+ upgrade_to_unique_lock<upgrade_mutex> unique_lock(lock);
m_is_set = false;
-
+ }
return true;
}
private:
- mutex m_mutex;
- condition_variable m_cond;
+ upgrade_mutex m_mutex;
+ condition_variable_any m_cond;
const bool m_auto_reset;
bool m_is_set;
};
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk