diff DEPENDENCIES/generic/include/boost/asio/detail/posix_event.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
line wrap: on
line diff
--- a/DEPENDENCIES/generic/include/boost/asio/detail/posix_event.hpp	Fri Sep 04 12:01:02 2015 +0100
+++ b/DEPENDENCIES/generic/include/boost/asio/detail/posix_event.hpp	Mon Sep 07 11:12:49 2015 +0100
@@ -2,7 +2,7 @@
 // detail/posix_event.hpp
 // ~~~~~~~~~~~~~~~~~~~~~~
 //
-// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
 //
 // Distributed under the Boost Software License, Version 1.0. (See accompanying
 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -42,24 +42,48 @@
     ::pthread_cond_destroy(&cond_);
   }
 
-  // Signal the event.
+  // Signal the event. (Retained for backward compatibility.)
   template <typename Lock>
   void signal(Lock& lock)
   {
+    this->signal_all(lock);
+  }
+
+  // Signal all waiters.
+  template <typename Lock>
+  void signal_all(Lock& lock)
+  {
     BOOST_ASIO_ASSERT(lock.locked());
     (void)lock;
-    signalled_ = true;
-    ::pthread_cond_signal(&cond_); // Ignore EINVAL.
+    state_ |= 1;
+    ::pthread_cond_broadcast(&cond_); // Ignore EINVAL.
   }
 
-  // Signal the event and unlock the mutex.
+  // Unlock the mutex and signal one waiter.
   template <typename Lock>
-  void signal_and_unlock(Lock& lock)
+  void unlock_and_signal_one(Lock& lock)
   {
     BOOST_ASIO_ASSERT(lock.locked());
-    signalled_ = true;
+    state_ |= 1;
+    bool have_waiters = (state_ > 1);
     lock.unlock();
-    ::pthread_cond_signal(&cond_); // Ignore EINVAL.
+    if (have_waiters)
+      ::pthread_cond_signal(&cond_); // Ignore EINVAL.
+  }
+
+  // If there's a waiter, unlock the mutex and signal it.
+  template <typename Lock>
+  bool maybe_unlock_and_signal_one(Lock& lock)
+  {
+    BOOST_ASIO_ASSERT(lock.locked());
+    state_ |= 1;
+    if (state_ > 1)
+    {
+      lock.unlock();
+      ::pthread_cond_signal(&cond_); // Ignore EINVAL.
+      return true;
+    }
+    return false;
   }
 
   // Reset the event.
@@ -68,7 +92,7 @@
   {
     BOOST_ASIO_ASSERT(lock.locked());
     (void)lock;
-    signalled_ = false;
+    state_ &= ~std::size_t(1);
   }
 
   // Wait for the event to become signalled.
@@ -76,13 +100,17 @@
   void wait(Lock& lock)
   {
     BOOST_ASIO_ASSERT(lock.locked());
-    while (!signalled_)
+    while ((state_ & 1) == 0)
+    {
+      state_ += 2;
       ::pthread_cond_wait(&cond_, &lock.mutex().mutex_); // Ignore EINVAL.
+      state_ -= 2;
+    }
   }
 
 private:
   ::pthread_cond_t cond_;
-  bool signalled_;
+  std::size_t state_;
 };
 
 } // namespace detail