Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81104 - trunk/boost/thread
From: vicente.botet_at_[hidden]
Date: 2012-10-29 15:13:33


Author: viboes
Date: 2012-10-29 15:13:32 EDT (Mon, 29 Oct 2012)
New Revision: 81104
URL: http://svn.boost.org/trac/boost/changeset/81104

Log:
Thread: Added polymorphic lockables
Added:
   trunk/boost/thread/poly_lockable.hpp (contents, props changed)
   trunk/boost/thread/poly_lockable_adapter.hpp (contents, props changed)
   trunk/boost/thread/poly_shared_lockable.hpp (contents, props changed)
   trunk/boost/thread/poly_shared_lockable_adapter.hpp (contents, props changed)

Added: trunk/boost/thread/poly_lockable.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/poly_lockable.hpp 2012-10-29 15:13:32 EDT (Mon, 29 Oct 2012)
@@ -0,0 +1,68 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009,2012. 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/thread for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_THREAD_POLY_LOCKABLE_HPP
+#define BOOST_THREAD_POLY_LOCKABLE_HPP
+
+#include <boost/thread/detail/delete.hpp>
+#include <boost/chrono/chrono.hpp>
+
+namespace boost
+{
+
+ //[basic_poly_lockable
+ class basic_poly_lockable
+ {
+ public:
+
+ virtual ~basic_poly_lockable() = 0;
+
+ virtual void lock() = 0;
+ virtual void unlock() = 0;
+
+ };
+ //]
+
+ //[poly_lockable
+ class poly_lockable : public basic_poly_lockable<Lockable>
+ {
+ public:
+
+ virtual ~poly_lockable() = 0;
+ virtual bool try_lock() = 0;
+ };
+ //]
+
+ //[timed_poly_lockable
+ class timed_poly_lockable: public poly_lockable<TimedLock>
+ {
+ public:
+ virtual ~timed_poly_lockable()=0;
+
+ virtual bool try_lock_until(chrono::system_clock::time_point const & abs_time)=0;
+ virtual bool try_lock_until(chrono::steady_clock::time_point const & abs_time)=0;
+ template <typename Clock, typename Duration>
+ bool try_lock_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return try_lock_until(time_point_cast<Clock::time_point>(abs_time));
+ }
+
+ virtual bool try_lock_for(chrono::nanoseconds const & relative_time)=0;
+ template <typename Rep, typename Period>
+ bool try_lock_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return try_lock_for(duration_cast<Clock::duration>(rel_time));
+ }
+
+ };
+ //]
+
+}
+#endif

Added: trunk/boost/thread/poly_lockable_adapter.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/poly_lockable_adapter.hpp 2012-10-29 15:13:32 EDT (Mon, 29 Oct 2012)
@@ -0,0 +1,89 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009,2012. 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/thread for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_THREAD_POLY_LOCKABLE_ADAPTER_HPP
+#define BOOST_THREAD_POLY_LOCKABLE_ADAPTER_HPP
+
+#include <boost/thread/poly_lockable.hpp>
+
+namespace boost
+{
+
+ //[poly_basic_lockable_adapter
+ template <typename Mutex, typename Base=poly_basic_lockable>
+ class poly_basic_lockable_adapter : public Base
+ {
+ public:
+ typedef Mutex mutex_type;
+
+ protected:
+ mutex_type& mtx() const
+ {
+ return mtx_;
+ }
+ mutable mutex_type mtx_; /*< mutable so that it can be modified by const functions >*/
+ public:
+
+ BOOST_THREAD_NO_COPYABLE( poly_basic_lockable_adapter) /*< no copyable >*/
+
+ poly_basic_lockable_adapter()
+ {}
+
+ void lock()
+ {
+ mtx().lock();
+ }
+ void unlock()
+ {
+ mtx().unlock();
+ }
+
+ };
+ //]
+
+ //[poly_lockable_adapter
+ template <typename Mutex, typename Base=poly_lockable>
+ class poly_lockable_adapter : public poly_basic_lockable_adapter<Mutex, Base>
+ {
+ public:
+ typedef Mutex mutex_type;
+
+ bool try_lock()
+ {
+ return this->mtx().try_lock();
+ }
+ };
+ //]
+
+ //[poly_timed_lockable_adapter
+ template <typename Mutex, typename Base=poly_timed_lockable>
+ class poly_timed_lockable_adapter: public poly_lockable_adapter<Mutex, Base>
+ {
+ public:
+ typedef Mutex mutex_type;
+
+ bool try_lock_until(chrono::system_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_lock_until(abs_time);
+ }
+ bool try_lock_until(chrono::steady_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_lock_until(abs_time);
+ }
+ bool try_lock_for(chrono::nanoseconds const & rel_time)
+ {
+ return this->mtx().try_lock_for(rel_time);
+ }
+
+ };
+ //]
+
+}
+#endif

Added: trunk/boost/thread/poly_shared_lockable.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/poly_shared_lockable.hpp 2012-10-29 15:13:32 EDT (Mon, 29 Oct 2012)
@@ -0,0 +1,135 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009,2012. 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/thread for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_THREAD_POLY_SHARED_LOCKABLE_HPP
+#define BOOST_THREAD_POLY_SHARED_LOCKABLE_HPP
+
+#include <boost/thread/poly_lockable.hpp>
+#include <boost/chrono/chrono.hpp>
+
+namespace boost
+{
+
+
+ //[shared_poly_lockable
+ class shared_poly_lockable: public timed_poly_lockable
+ {
+ public:
+ virtual ~shared_poly_lockable() = 0;
+
+ virtual void lock_shared() = 0;
+ virtual bool try_lock_shared() = 0;
+ virtual void unlock_shared() = 0;
+
+ virtual bool try_lock_shared_until(chrono::system_clock::time_point const & abs_time)=0;
+ virtual bool try_lock_shared_until(chrono::steady_clock::time_point const & abs_time)=0;
+ template <typename Clock, typename Duration>
+ bool try_lock_shared_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return try_lock_shared_until(time_point_cast<Clock::time_point>(abs_time));
+ }
+
+ virtual bool try_lock_shared_for(chrono::nanoseconds const & relative_time)=0;
+ template <typename Rep, typename Period>
+ bool try_lock_shared_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return try_lock_shared_for(duration_cast<Clock::duration>(rel_time));
+ }
+
+ };
+
+ //]
+
+ //[upgrade_poly_lockable
+ class upgrade_poly_lockable: public shared_poly_lockable
+ {
+ public:
+ virtual ~upgrade_poly_lockable() = 0;
+
+ virtual void lock_upgrade() = 0;
+ virtual bool try_lock_upgrade() = 0;
+ virtual void unlock_upgrade() = 0;
+
+ virtual bool try_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)=0;
+ virtual bool try_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)=0;
+ template <typename Clock, typename Duration>
+ bool try_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return try_lock_upgrade_until(time_point_cast<Clock::time_point>(abs_time));
+ }
+
+ virtual bool try_lock_upgrade_for(chrono::nanoseconds const & relative_time)=0;
+ template <typename Rep, typename Period>
+ bool try_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return try_lock_upgrade_for(duration_cast<Clock::duration>(rel_time));
+ }
+
+ virtual bool try_unlock_shared_and_lock() = 0;
+
+ virtual bool try_unlock_shared_and_lock_until(chrono::system_clock::time_point const & abs_time)=0;
+ virtual bool try_unlock_shared_and_lock_until(chrono::steady_clock::time_point const & abs_time)=0;
+ template <typename Clock, typename Duration>
+ bool try_unlock_shared_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return try_unlock_shared_and_lock_until(time_point_cast<Clock::time_point>(abs_time));
+ }
+
+ virtual bool try_unlock_shared_and_lock_for(chrono::nanoseconds const & relative_time)=0;
+ template <typename Rep, typename Period>
+ bool try_unlock_shared_and_lock_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return try_unlock_shared_and_lock_for(duration_cast<Clock::duration>(rel_time));
+ }
+
+ virtual void unlock_and_lock_shared() = 0;
+ virtual bool try_unlock_shared_and_lock_upgrade() = 0;
+
+ virtual bool try_unlock_shared_and_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)=0;
+ virtual bool try_unlock_shared_and_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)=0;
+ template <typename Clock, typename Duration>
+ bool try_unlock_shared_and_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return try_unlock_shared_and_lock_upgrade_until(time_point_cast<Clock::time_point>(abs_time));
+ }
+
+ virtual bool try_unlock_shared_and_lock_upgrade_for(chrono::nanoseconds const & relative_time)=0;
+ template <typename Rep, typename Period>
+ bool try_unlock_shared_and_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return try_unlock_shared_and_lock_upgrade_for(duration_cast<Clock::duration>(rel_time));
+ }
+
+ virtual void unlock_and_lock_upgrade() = 0;
+ virtual void unlock_upgrade_and_lock() = 0;
+ virtual bool try_unlock_upgrade_and_lock() = 0;
+
+ virtual bool try_unlock_upgrade_and_lock_until(chrono::system_clock::time_point const & abs_time)=0;
+ virtual bool try_unlock_upgrade_and_lock_until(chrono::steady_clock::time_point const & abs_time)=0;
+ template <typename Clock, typename Duration>
+ bool try_unlock_upgrade_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return try_unlock_upgrade_and_lock_until(time_point_cast<Clock::time_point>(abs_time));
+ }
+
+ virtual bool try_unlock_upgrade_and_lock_for(chrono::nanoseconds const & relative_time)=0;
+ template <typename Rep, typename Period>
+ bool try_unlock_upgrade_and_lock_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return try_unlock_upgrade_and_lock_for(duration_cast<Clock::duration>(rel_time));
+ }
+
+ virtual void unlock_upgrade_and_lock_shared() = 0;
+
+ };
+//]
+
+}
+#endif

Added: trunk/boost/thread/poly_shared_lockable_adapter.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/poly_shared_lockable_adapter.hpp 2012-10-29 15:13:32 EDT (Mon, 29 Oct 2012)
@@ -0,0 +1,170 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009,2012. 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/thread for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_THREAD_POLY_SHARED_LOCKABLE_ADAPTER_HPP
+#define BOOST_THREAD_POLY_SHARED_LOCKABLE_ADAPTER_HPP
+
+#include <boost/thread/poly_lockable_adapter.hpp>
+#include <boost/thread/poly_shared_lockable.hpp>
+
+namespace boost
+{
+
+ //[shared_lockable_adapter
+ template <typename Mutex, typename Base=poly_shared_lockable>
+ class poly_shared_lockable_adapter: public poly_timed_lockable_adapter<Mutex, Base>
+ {
+ public:
+ typedef Mutex mutex_type;
+
+ void lock_shared()
+ {
+ this->mtx().lock_shared();
+ }
+ bool try_lock_shared()
+ {
+ return this->mtx().try_lock_shared();
+ }
+ void unlock_shared()
+ {
+ this->mtx().unlock_shared();
+ }
+
+ bool try_lock_shared_until(chrono::system_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_lock_shared_until(abs_time);
+ }
+ bool try_lock_shared_until(chrono::steady_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_lock_shared_until(abs_time);
+ }
+ bool try_lock_shared_for(chrono::nanoseconds const & rel_time)
+ {
+ return this->mtx().try_lock_shared_for(rel_time);
+ }
+
+ };
+
+ //]
+
+ //[upgrade_lockable_adapter
+ template <typename Mutex, typename Base=poly_shared_lockable>
+ class upgrade_lockable_adapter: public shared_lockable_adapter<Mutex, Base>
+ {
+ public:
+ typedef Mutex mutex_type;
+
+ void lock_upgrade()
+ {
+ this->mtx().lock_upgrade();
+ }
+
+ bool try_lock_upgrade()
+ {
+ return this->mtx().try_lock_upgrade();
+ }
+
+ void unlock_upgrade()
+ {
+ this->mtx().unlock_upgrade();
+ }
+
+ bool try_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_lock_upgrade_until(abs_time);
+ }
+ bool try_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_lock_upgrade_until(abs_time);
+ }
+ bool try_lock_upgrade_for(chrono::nanoseconds const & rel_time)
+ {
+ return this->mtx().try_lock_upgrade_for(rel_time);
+ }
+
+ bool try_unlock_shared_and_lock()
+ {
+ return this->mtx().try_unlock_shared_and_lock();
+ }
+
+ bool try_unlock_shared_and_lock_until(chrono::system_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_unlock_shared_and_lock_until(abs_time);
+ }
+ bool try_unlock_shared_and_lock_until(chrono::steady_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_unlock_shared_and_lock_until(abs_time);
+ }
+ template <typename Rep, typename Period>
+ bool try_unlock_shared_and_lock_for(chrono::nanoseconds const & rel_time)
+ {
+ return this->mtx().try_unlock_shared_and_lock_for(rel_time);
+ }
+
+ void unlock_and_lock_shared()
+ {
+ this->mtx().unlock_and_lock_shared();
+ }
+
+ bool try_unlock_shared_and_lock_upgrade()
+ {
+ return this->mtx().try_unlock_shared_and_lock_upgrade();
+ }
+
+ bool try_unlock_shared_and_lock_upgrade_until(chrono::system_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_unlock_shared_and_lock_upgrade_until(abs_time);
+ }
+ bool try_unlock_shared_and_lock_upgrade_until(chrono::steady_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_unlock_shared_and_lock_upgrade_until(abs_time);
+ }
+ bool try_unlock_shared_and_lock_upgrade_for(chrono::nanoseconds const & rel_time)
+ {
+ return this->mtx().try_unlock_shared_and_lock_upgrade_for(rel_time);
+ }
+
+ void unlock_and_lock_upgrade()
+ {
+ this->mtx().unlock_and_lock_upgrade();
+ }
+
+ void unlock_upgrade_and_lock()
+ {
+ this->mtx().unlock_upgrade_and_lock();
+ }
+
+ bool try_unlock_upgrade_and_lock()
+ {
+ return this->mtx().try_unlock_upgrade_and_lock();
+ }
+ bool try_unlock_upgrade_and_lock_until(chrono::system_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_unlock_upgrade_and_lock_until(abs_time);
+ }
+ bool try_unlock_upgrade_and_lock_until(chrono::steady_clock::time_point const & abs_time)
+ {
+ return this->mtx().try_unlock_upgrade_and_lock_until(abs_time);
+ }
+ bool try_unlock_upgrade_and_lock_for(chrono::nanoseconds const & rel_time)
+ {
+ return this->mtx().try_unlock_upgrade_and_lock_for(rel_time);
+ }
+
+ void unlock_upgrade_and_lock_shared()
+ {
+ this->mtx().unlock_upgrade_and_lock_shared();
+ }
+
+ };
+//]
+
+}
+#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