|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r51158 - sandbox/synchro/boost/synchro/poly
From: vicente.botet_at_[hidden]
Date: 2009-02-09 17:39:34
Author: viboes
Date: 2009-02-09 17:39:33 EST (Mon, 09 Feb 2009)
New Revision: 51158
URL: http://svn.boost.org/trac/boost/changeset/51158
Log:
Boost.Synchro V0.0.0
Added:
sandbox/synchro/boost/synchro/poly/adaptive_lock.hpp (contents, props changed)
sandbox/synchro/boost/synchro/poly/lock.hpp (contents, props changed)
sandbox/synchro/boost/synchro/poly/lock_adapter.hpp (contents, props changed)
Added: sandbox/synchro/boost/synchro/poly/adaptive_lock.hpp
==============================================================================
--- (empty file)
+++ sandbox/synchro/boost/synchro/poly/adaptive_lock.hpp 2009-02-09 17:39:33 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,86 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008. 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_POLY_ADAPTIVE_LOCK__HPP
+#define BOOST_SYNCHRO_POLY_ADAPTIVE_LOCK__HPP
+
+#include <boost/synchro/poly/lock.hpp>
+
+namespace boost { namespace synchro { namespace poly {
+
+class adaptive_exclusive_lock
+ : public virtual exclusive_lock
+{
+public:
+ virtual ~adaptive_exclusive_lock() {}
+ virtual void lock()
+ {lock_->lock();}
+ virtual void unlock()
+ {lock_->unlock();}
+ virtual bool try_lock()
+ { return lock_->try_lock();}
+protected:
+ adaptive_exclusive_lock(exclusive_lock* lock) : lock_(lock)
+ {
+ // assert lock is not null
+ }
+ exclusive_lock* lock_;
+};
+
+class adaptive_sharable_lock
+ : public adaptive_exclusive_lock
+ , public virtual sharable_lock
+{
+public:
+ virtual ~adaptive_sharable_lock() {}
+ virtual void lock_shared()
+ {the_lock()->lock_shared();}
+ virtual bool try_lock_shared()
+ { return the_lock()->try_lock_shared();}
+ virtual void unlock_shared()
+ {the_lock()->unlock_shared();}
+protected:
+ adaptive_sharable_lock(sharable_lock* lock) : adaptive_exclusive_lock(lock)
+ {}
+
+private:
+ sharable_lock* the_lock() {return static_cast<sharable_lock*>(this->lock_);}
+};
+
+class adaptive_upgradable_lock
+ : public adaptive_sharable_lock
+ , public virtual upgradable_lock
+{
+public:
+ virtual ~adaptive_upgradable_lock() {}
+ virtual void lock_upgrade()
+ {the_lock()->lock_upgrade();}
+ virtual void unlock_upgrade()
+ {the_lock()->unlock_upgrade();}
+
+ virtual void unlock_upgrade_and_lock()
+ {the_lock()->unlock_upgrade_and_lock();}
+ virtual void unlock_and_lock_upgrade()
+ {the_lock()->unlock_and_lock_upgrade();}
+ virtual void unlock_and_lock_shared()
+ {the_lock()->unlock_and_lock_shared();}
+ virtual void unlock_upgrade_and_lock_shared()
+ {the_lock()->unlock_upgrade_and_lock_shared();}
+protected:
+ adaptive_upgradable_lock(upgradable_lock* lock)
+ : adaptive_sharable_lock(lock) {}
+private:
+ upgradable_lock* the_lock() {return static_cast<upgradable_lock*>(this->lock_);}
+};
+
+}
+}
+}
+#endif
Added: sandbox/synchro/boost/synchro/poly/lock.hpp
==============================================================================
--- (empty file)
+++ sandbox/synchro/boost/synchro/poly/lock.hpp 2009-02-09 17:39:33 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,69 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008. 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_POLY_LOCK__HPP
+#define BOOST_SYNCHRO_POLY_LOCK__HPP
+
+namespace boost { namespace synchro { namespace poly {
+
+//////////////////////////////////////////////////////////////////////////////
+
+struct exclusive_lock {
+ virtual ~exclusive_lock()=0;
+ virtual void lock()=0;
+ virtual void unlock()=0;
+ virtual bool try_lock()=0;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+struct timed_lock : exclusive_lock {
+ virtual ~timed_lock()=0;
+ bool try_lock_until(boost::system_time const& abs_time)=0;
+ template<typename DurationType>
+ bool try_lock_for(DurationType const& rel_time)
+ {
+ return try_lock_until(get_system_time()+abs_time);
+ }
+};
+
+
+//////////////////////////////////////////////////////////////////////////////
+
+struct sharable_lock : timed_lock {
+ virtual ~sharable_lock();
+ virtual void lock_shared()=0;
+ virtual bool try_lock_shared()=0;
+ virtual bool try_lock_shared_until(boost::system_time const& abs_time)=0;
+ virtual void unlock_shared()=0;
+ template<typename DurationType>
+ bool try_lock_shared_for(DurationType const& rel_time)
+ {
+ return try_lock_shared_until(get_system_time()+abs_time);
+ }
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+struct upgradable_lock : sharable_lock {
+ virtual ~upgradable_lock();
+ virtual void lock_upgrade()=0;
+ virtual void unlock_upgrade()=0;
+ virtual void unlock_upgrade_and_lock()=0;
+ virtual void unlock_and_lock_upgrade()=0;
+ virtual void unlock_and_lock_shared()=0;
+ virtual void unlock_upgrade_and_lock_shared()=0;
+};
+
+}
+}
+}
+
+#endif
Added: sandbox/synchro/boost/synchro/poly/lock_adapter.hpp
==============================================================================
--- (empty file)
+++ sandbox/synchro/boost/synchro/poly/lock_adapter.hpp 2009-02-09 17:39:33 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,87 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008. 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_POLY_LOCK_ADAPTER__HPP
+#define BOOST_SYNCHRO_POLY_LOCK_ADAPTER__HPP
+
+#include <boost/synchro/poly/lock.hpp>
+namespace boost { namespace synchro { namespace poly {
+
+//////////////////////////////////////////////////////////////////////////////
+
+template <typename Lockable>
+class exclusive_lock_adapter
+ : public virtual exclusive_lock
+{
+ exclusive_lock_adapter(): lock_() {}
+ virtual ~exclusive_lock_adapter() {}
+
+ virtual void lock()
+ {lock_.lock();}
+ virtual void unlock()
+ {lock_.unlock();}
+ virtual bool try_lock()
+ { return lock_.try_lock();}
+protected:
+ Lockable lock_;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+template <typename SharableLock>
+class sharable_lock_adapter
+ : public exclusive_lock_adapter<SharableLock>
+ , public virtual sharable_lock
+{
+public:
+ virtual ~sharable_lock_adapter()
+ {}
+ virtual void lock_shared()
+ {the_lock().lock_shared();}
+ virtual bool try_lock_shared()
+ {return the_lock().try_lock_shared();}
+ virtual void unlock_shared()
+ {the_lock().unlock_shared();}
+private:
+ SharableLock& the_lock() {return *static_cast<SharableLock*>(&this->lock_);}
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+template <typename UpgradableLock>
+class upgradable_lock_adapter
+ : public sharable_lock_adapter<UpgradableLock>
+ , public virtual upgradable_lock
+{
+public:
+ virtual ~upgradable_lock_adapter() {}
+ virtual void lock_upgrade()
+ {the_lock().lock_upgrade();}
+
+ virtual void unlock_upgrade()
+ {the_lock().unlock_upgrade();}
+
+ virtual void unlock_upgrade_and_lock()
+ {the_lock().unlock_upgrade_and_lock();}
+ virtual void unlock_and_lock_upgrade()
+ {the_lock().unlock_and_lock_upgrade();}
+ virtual void unlock_and_lock_shared()
+ {the_lock().unlock_and_lock_shared();}
+ virtual void unlock_upgrade_and_lock_shared()
+ {the_lock().unlock_upgrade_and_lock_shared();}
+private:
+ UpgradableLock& the_lock() {return *static_cast<UpgradableLock*>(&this->lock_);}
+};
+
+}
+}
+}
+
+#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