Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51237 - in sandbox/synchro/boost/synchro: . lockers
From: vicente.botet_at_[hidden]
Date: 2009-02-13 05:07:39


Author: viboes
Date: 2009-02-13 05:07:38 EST (Fri, 13 Feb 2009)
New Revision: 51237
URL: http://svn.boost.org/trac/boost/changeset/51237

Log:
Boost.Synchro V0.0.0
Added:
   sandbox/synchro/boost/synchro/condition_backdoor.hpp (contents, props changed)
   sandbox/synchro/boost/synchro/condition_safe.hpp (contents, props changed)
   sandbox/synchro/boost/synchro/lockers/nested_reverse_locker.hpp (contents, props changed)
   sandbox/synchro/boost/synchro/lockers/reverse_locker.hpp (contents, props changed)
   sandbox/synchro/boost/synchro/thread_synchronization_family.hpp (contents, props changed)

Added: sandbox/synchro/boost/synchro/condition_backdoor.hpp
==============================================================================
--- (empty file)
+++ sandbox/synchro/boost/synchro/condition_backdoor.hpp 2009-02-13 05:07:38 EST (Fri, 13 Feb 2009)
@@ -0,0 +1,62 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. 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)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHRO_CONDITION_BACKDOOR__HPP
+#define BOOST_SYNCHRO_CONDITION_BACKDOOR__HPP
+
+#include <boost/synchro/lockable_concepts.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/synchro/thread/mutex.hpp>
+#include <boost/synchro/condition_safe.hpp>
+
+namespace boost { namespace synchro {
+
+template <
+ class Condition
+>
+struct condition_backdoor {
+ condition_backdoor(condition_safe<Condition>&cnd): that_(cnd) {}
+ template <typename Locker, typename Predicate>
+ void wait_when(Locker& lock, Predicate pred){
+ that_.wait_when(lock, pred);
+ }
+ template <typename Locker>
+ void wait(Locker& lock) {
+ that_.wait(lock);
+ }
+ template <typename Locker>
+ bool wait_until(Locker& lock, boost::system_time const& abs_time) {
+ return that_.wait_until(lock, abs_time);
+ }
+
+ template<typename Locker, typename duration_type>
+ bool wait_for(Locker& lock, duration_type const& rel_time) {
+ return that_.wait_for(lock, rel_time);
+ }
+
+ template<typename Locker, typename predicate_type>
+ bool wait_when_until(Locker& lock, predicate_type pred, boost::system_time const& abs_time) {
+ return that_.timed_wait(lock, pred, abs_time);
+ }
+ template <typename Locker>
+ void notify_one(Locker& lock) {
+ that_.notify_one(lock);
+ }
+ template <typename Locker>
+ void notify_all(Locker& lock) {
+ that_.notify_all(lock);
+ }
+private:
+ condition_safe<Condition>& that_;
+};
+
+}
+}
+#endif

Added: sandbox/synchro/boost/synchro/condition_safe.hpp
==============================================================================
--- (empty file)
+++ sandbox/synchro/boost/synchro/condition_safe.hpp 2009-02-13 05:07:38 EST (Fri, 13 Feb 2009)
@@ -0,0 +1,74 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. 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)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHRO_CONDITION_SAFE__HPP
+#define BOOST_SYNCHRO_CONDITION_SAFE__HPP
+
+#include <boost/synchro/lockable_concepts.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/synchro/thread/mutex.hpp>
+
+namespace boost { namespace synchro {
+
+template <
+ class Condition
+>
+class condition_backdoor;
+
+template <
+ class Condition
+>
+class condition_safe {
+public:
+ typedef Condition condition;
+ typedef condition_backdoor<Condition> backdoor;
+ void notify_one() { cond_.notify_one(); }
+ void notify_all() { cond_.notify_all(); }
+private:
+ friend class condition_backdoor<Condition>;
+ template <typename Locker, typename Predicate>
+ void wait_when(Locker& lock, Predicate pred) {
+ cond_.wait(lock, pred);
+ }
+ template <typename Locker>
+ void wait(Locker& lock) {
+ cond_.wait(lock);
+ }
+
+ template <typename Locker>
+ bool wait_until(Locker& lock, boost::system_time const& abs_time) {
+ return cond_.timed_wait(lock);;
+ }
+
+ template<typename Locker, typename duration_type>
+ bool wait_for(Locker& lock,duration_type const& rel_time) {
+ return cond_.timed_wait(lock);
+ }
+
+// template<typename Locker, typename predicate_type>
+// bool wait_when(Locker& lock, predicate_type pred) {
+// return cond_.wait(lock, pred);
+// }
+ template<typename Locker, typename predicate_type>
+ bool wait_when_until(Locker& lock, predicate_type pred, boost::system_time const& abs_time) {
+ return cond_.timed_wait(lock, pred, abs_time);
+ }
+ template<typename Locker, typename duration_type, typename predicate_type>
+ bool wait_when_for(Locker& lock, predicate_type pred, duration_type const& rel_time) {
+ return cond_.timed_wait(lock, pred, rel_time);
+ }
+private:
+ Condition cond_;
+};
+
+
+}
+}
+#endif

Added: sandbox/synchro/boost/synchro/lockers/nested_reverse_locker.hpp
==============================================================================
--- (empty file)
+++ sandbox/synchro/boost/synchro/lockers/nested_reverse_locker.hpp 2009-02-13 05:07:38 EST (Fri, 13 Feb 2009)
@@ -0,0 +1,73 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. 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)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHRO_NESTED_REVERSE_LOCKER__HPP
+#define BOOST_SYNCHRO_NESTED_REVERSE_LOCKER__HPP
+
+#include <boost/mpl/bool.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/synchro/lockable_traits.hpp>
+#include <boost/synchro/locker_concepts.hpp>
+
+namespace boost { namespace synchro {
+
+/*
+ *
+ * unique_lock<mutex> lock(smtx);
+ * // ... some read operations
+ * { // non locked block
+ * nested_reverse_locker<unique_lock<mutex> > rlock(lock);
+ * // ... some code not needing
+ * } // locked again
+ * // ...
+ */
+
+template <typename Locker>
+class nested_reverse_locker : boost::noncopyable
+{
+// BOOST_CONCEPT_ASSERT((MovableLockConcept<Locker>));
+ typedef typename lock_error_type<typename lockable_type<Locker>::type >::type lock_error;
+
+public:
+ explicit nested_reverse_locker(Locker& locker)
+ : locker_(locker) /*< Store reference to locker >*/
+ , tmp_locker_(locker.move()) /*< Move ownership to temporaty locker >*/
+ , was_locked_(false)
+ {
+#ifndef BOOST_SYNCHRO_NESTED_REVERSE_LOCKER_DONT_CHECK_OWNERSHIP /*< Define BOOST_SYNCHRO_NESTED_REVERSE_LOCKER_DONT_CHECK_OWNERSHIP if you don't want to check locker ownership >*/
+ if (tmp_locker_.mutex()==0) {
+ locker_=tmp_locker_.move(); /*< Rollback for coherency purposes >*/
+ throw lock_error();
+ }
+#endif
+ if (tmp_locker_) { /*< ensures it is unlocked >*/
+ tmp_locker_.unlock();
+ was_locked_=true;
+ }
+ }
+ ~nested_reverse_locker() {
+ if (was_locked_) {
+ tmp_locker_.lock();
+ }
+ locker_=tmp_locker_.move(); /*< Move ownership to nesting locker >*/
+ }
+
+protected:
+ Locker& locker_;
+ Locker tmp_locker_;
+ bool was_locked_;
+ nested_reverse_locker();
+};
+
+}
+}
+
+#endif

Added: sandbox/synchro/boost/synchro/lockers/reverse_locker.hpp
==============================================================================
--- (empty file)
+++ sandbox/synchro/boost/synchro/lockers/reverse_locker.hpp 2009-02-13 05:07:38 EST (Fri, 13 Feb 2009)
@@ -0,0 +1,49 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. 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)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHRO_REVERSE_LOCKER__HPP
+#define BOOST_SYNCHRO_REVERSE_LOCKER__HPP
+
+#include <boost/mpl/bool.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/synchro/lockable_traits.hpp>
+#include <boost/synchro/locker_concepts.hpp>
+
+namespace boost { namespace synchro {
+
+
+
+/*
+ *
+ * mutex mtx;
+ * // ... some read operations
+ * { // non locked block
+ * reverse_locker<boost::mutex> > rlock(mutex);
+ * // ... some code not needing
+ * } // locked again
+ * // ...
+ */
+
+template <typename Lockable>
+class reverse_locker
+{
+ reverse_locker(Lockable& mtx): mtx_(mtx) {mtx_.unlock();}
+ ~reverse_locker() {mtx_.lock();}
+
+protected:
+ Lockable& mtx_;
+};
+
+
+}
+}
+
+#endif

Added: sandbox/synchro/boost/synchro/thread_synchronization_family.hpp
==============================================================================
--- (empty file)
+++ sandbox/synchro/boost/synchro/thread_synchronization_family.hpp 2009-02-13 05:07:38 EST (Fri, 13 Feb 2009)
@@ -0,0 +1,42 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. 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)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHRO_THREAD_SYNCHROHRONIZATION_FAMILY__HPP
+#define BOOST_SYNCHRO_THREAD_SYNCHROHRONIZATION_FAMILY__HPP
+
+#include <boost/synchro/thread/mutex.hpp>
+#include <boost/synchro/thread/recursive_mutex.hpp>
+#include <boost/synchro/thread/shared_mutex.hpp>
+#include <boost/thread/condition_variable.hpp>
+
+namespace boost {
+namespace synchro {
+
+//!\file
+//!Describes thread synchronization family to use with Sync framework
+//!based on boost synchronization objects.
+//[thread_synchronization_family
+struct thread_synchronization_family
+{
+ typedef thread_mutex mutex_type;
+ typedef thread_recursive_mutex recursive_mutex_type;
+ typedef thread_timed_mutex timed_mutex_type;
+ typedef thread_recursive_timed_mutex recursive_timed_mutex_type;
+ typedef thread_shared_mutex shared_mutex_type;
+ typedef boost::condition_variable condition_type;
+ typedef boost::condition_variable_any condition_type_any;
+};
+//]
+
+
+}
+}
+
+#endif


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