|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r81100 - trunk/boost/thread
From: vicente.botet_at_[hidden]
Date: 2012-10-29 15:05:36
Author: viboes
Date: 2012-10-29 15:05:35 EDT (Mon, 29 Oct 2012)
New Revision: 81100
URL: http://svn.boost.org/trac/boost/changeset/81100
Log:
Thread: change strict_lock is_locking by own_lock and update lockable concepts
Added:
trunk/boost/thread/lockable_adapter.hpp (contents, props changed)
Text files modified:
trunk/boost/thread/lock_concepts.hpp | 60 ++++++++++++++++++++++++++++++++-------
trunk/boost/thread/lockable_concepts.hpp | 30 ++++++++++++++-----
trunk/boost/thread/strict_lock.hpp | 13 +++++---
3 files changed, 79 insertions(+), 24 deletions(-)
Modified: trunk/boost/thread/lock_concepts.hpp
==============================================================================
--- trunk/boost/thread/lock_concepts.hpp (original)
+++ trunk/boost/thread/lock_concepts.hpp 2012-10-29 15:05:35 EDT (Mon, 29 Oct 2012)
@@ -10,6 +10,7 @@
#include <boost/thread/lock_options.hpp>
#include <boost/thread/lockable_concepts.hpp>
#include <boost/thread/exceptions.hpp>
+#include <boost/thread/detail/move.hpp>
#include <boost/chrono/chrono.hpp>
#include <boost/concept_check.hpp>
@@ -37,7 +38,7 @@
Lk l2(mtx, defer_lock);
Lk l3(mtx, adopt_lock);
Lk l4(( Lk()));
- // BUG Lk l5(( boost::move(l1)));
+ Lk l5(( boost::move(l2)));
cvt_mutex_ptr(l1.mutex());
if (l1.owns_lock()) return;
if (l1) return;
@@ -48,7 +49,12 @@
l2.release();
}
- mutex_type mtx;
+ BasicLock() :
+ mtx(*static_cast<mutex_type*>(0))
+ {}
+ private:
+ BasicLock operator=(BasicLock const&);
+ mutex_type& mtx;
}
;
@@ -64,7 +70,12 @@
Lk l1(mtx, try_to_lock);
if (l1.try_lock()) return;
}
- mutex_type mtx;
+ Lock() :
+ mtx(*static_cast<mutex_type*>(0))
+ {}
+ private:
+ Lock operator=(Lock const&);
+ mutex_type& mtx;
};
template <typename Lk>
@@ -76,12 +87,17 @@
BOOST_CONCEPT_USAGE(TimedLock)
{
- Lk l1(mtx, t);
+ const Lk l1(mtx, t);
Lk l2(mtx, d);
if (l1.try_lock_until(t)) return;
if (l1.try_lock_for(d)) return;
}
- mutex_type mtx;
+ TimedLock() :
+ mtx(*static_cast<mutex_type*>(0))
+ {}
+ private:
+ TimedLock operator=(TimedLock const&);
+ mutex_type& mtx;
boost::chrono::system_clock::time_point t;
boost::chrono::system_clock::duration d;
};
@@ -96,7 +112,12 @@
{
}
- mutex_type mtx;
+ UniqueLock() :
+ mtx(*static_cast<mutex_type*>(0))
+ {}
+ private:
+ UniqueLock operator=(UniqueLock const&);
+ mutex_type& mtx;
};
template <typename Lk>
@@ -108,7 +129,12 @@
BOOST_CONCEPT_USAGE(SharedLock)
{
}
- mutex_type mtx;
+ SharedLock() :
+ mtx(*static_cast<mutex_type*>(0))
+ {}
+ private:
+ SharedLock operator=(SharedLock const&);
+ mutex_type& mtx;
};
@@ -121,7 +147,12 @@
BOOST_CONCEPT_USAGE(UpgradeLock)
{
}
- mutex_type mtx;
+ UpgradeLock() :
+ mtx(*static_cast<mutex_type*>(0))
+ {}
+ private:
+ UpgradeLock operator=(UpgradeLock const&);
+ mutex_type& mtx;
};
/**
@@ -147,10 +178,17 @@
BOOST_CONCEPT_USAGE( StrictLock)
{
- if (l1.is_locking(&mtx)) return;
+ if (l1.owns_lock(&mtx)) return;
}
- const Lk &l1;
- mutex_type mtx;
+ StrictLock() :
+ l1(*static_cast<Lk*>(0)),
+ mtx(*static_cast<mutex_type*>(0))
+ {}
+ private:
+ StrictLock operator=(StrictLock const&);
+
+ Lk const& l1;
+ mutex_type const& mtx;
};
Added: trunk/boost/thread/lockable_adapter.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/lockable_adapter.hpp 2012-10-29 15:05:35 EDT (Mon, 29 Oct 2012)
@@ -0,0 +1,226 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_LOCKABLE_ADAPTER_HPP
+#define BOOST_THREAD_LOCKABLE_ADAPTER_HPP
+
+#include <boost/thread/detail/delete.hpp>
+#include <boost/chrono/chrono.hpp>
+
+namespace boost
+{
+
+ //[basic_lockable_adapter
+ template <typename BasicLockable>
+ class basic_lockable_adapter
+ {
+ public:
+ typedef BasicLockable mutex_type;
+
+ protected:
+ mutex_type& lockable() const
+ {
+ return lockable_;
+ }
+ mutable mutex_type lockable_; /*< mutable so that it can be modified by const functions >*/
+ public:
+
+ BOOST_THREAD_NO_COPYABLE( basic_lockable_adapter) /*< no copyable >*/
+
+ basic_lockable_adapter()
+ {}
+
+ void lock()
+ {
+ lockable().lock();
+ }
+ void unlock()
+ {
+ lockable().unlock();
+ }
+
+ };
+ //]
+
+ //[lockable_adapter
+ template <typename Lockable>
+ class lockable_adapter : public basic_lockable_adapter<Lockable>
+ {
+ public:
+ typedef Lockable mutex_type;
+
+ bool try_lock()
+ {
+ return this->lockable().try_lock();
+ }
+ };
+ //]
+
+ //[timed_lockable_adapter
+ template <typename TimedLock>
+ class timed_lockable_adapter: public lockable_adapter<TimedLock>
+ {
+ public:
+ typedef TimedLock mutex_type;
+
+ template <typename Clock, typename Duration>
+ bool try_lock_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return this->lockable().try_lock_until(abs_time);
+ }
+ template <typename Rep, typename Period>
+ bool try_lock_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return this->lockable().try_lock_for(rel_time);
+ }
+
+ };
+ //]
+
+ //[shared_lockable_adapter
+ template <typename SharableLock>
+ class shared_lockable_adapter: public timed_lockable_adapter<SharableLock>
+ {
+ public:
+ typedef SharableLock mutex_type;
+
+ void lock_shared()
+ {
+ this->lockable().lock_shared();
+ }
+ bool try_lock_shared()
+ {
+ return this->lockable().try_lock_shared();
+ }
+ void unlock_shared()
+ {
+ this->lockable().unlock_shared();
+ }
+
+ template <typename Clock, typename Duration>
+ bool try_lock_shared_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return this->lockable().try_lock_shared_until(abs_time);
+ }
+ template <typename Rep, typename Period>
+ bool try_lock_shared_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return this->lockable().try_lock_shared_for(rel_time);
+ }
+
+ };
+
+ //]
+
+ //[upgrade_lockable_adapter
+ template <typename UpgradableLock>
+ class upgrade_lockable_adapter: public shared_lockable_adapter<UpgradableLock>
+ {
+ public:
+ typedef UpgradableLock mutex_type;
+
+ void lock_upgrade()
+ {
+ this->lockable().lock_upgrade();
+ }
+
+ bool try_lock_upgrade()
+ {
+ return this->lockable().try_lock_upgrade();
+ }
+
+ void unlock_upgrade()
+ {
+ this->lockable().unlock_upgrade();
+ }
+
+ template <typename Clock, typename Duration>
+ bool try_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return this->lockable().try_lock_upgrade_until(abs_time);
+ }
+ template <typename Rep, typename Period>
+ bool try_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return this->lockable().try_lock_upgrade_for(rel_time);
+ }
+
+ bool try_unlock_shared_and_lock()
+ {
+ return this->lockable().try_unlock_shared_and_lock();
+ }
+
+ template <typename Clock, typename Duration>
+ bool try_unlock_shared_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return this->lockable().try_unlock_shared_and_lock_until(abs_time);
+ }
+ template <typename Rep, typename Period>
+ bool try_unlock_shared_and_lock_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return this->lockable().try_unlock_shared_and_lock_for(rel_time);
+ }
+
+ void unlock_and_lock_shared()
+ {
+ this->lockable().unlock_and_lock_shared();
+ }
+
+ bool try_unlock_shared_and_lock_upgrade()
+ {
+ return this->lockable().try_unlock_shared_and_lock_upgrade();
+ }
+
+ template <typename Clock, typename Duration>
+ bool try_unlock_shared_and_lock_upgrade_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return this->lockable().try_unlock_shared_and_lock_upgrade_until(abs_time);
+ }
+ template <typename Rep, typename Period>
+ bool try_unlock_shared_and_lock_upgrade_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return this->lockable().try_unlock_shared_and_lock_upgrade_for(rel_time);
+ }
+
+ void unlock_and_lock_upgrade()
+ {
+ this->lockable().unlock_and_lock_upgrade();
+ }
+
+ void unlock_upgrade_and_lock()
+ {
+ this->lockable().unlock_upgrade_and_lock();
+ }
+
+ bool try_unlock_upgrade_and_lock()
+ {
+ return this->lockable().try_unlock_upgrade_and_lock();
+ }
+ template <typename Clock, typename Duration>
+ bool try_unlock_upgrade_and_lock_until(chrono::time_point<Clock, Duration> const & abs_time)
+ {
+ return this->lockable().try_unlock_upgrade_and_lock_until(abs_time);
+ }
+ template <typename Rep, typename Period>
+ bool try_unlock_upgrade_and_lock_for(chrono::duration<Rep, Period> const & rel_time)
+ {
+ return this->lockable().try_unlock_upgrade_and_lock_for(rel_time);
+ }
+
+ void unlock_upgrade_and_lock_shared()
+ {
+ this->lockable().unlock_upgrade_and_lock_shared();
+ }
+
+ };
+//]
+
+}
+#endif
Modified: trunk/boost/thread/lockable_concepts.hpp
==============================================================================
--- trunk/boost/thread/lockable_concepts.hpp (original)
+++ trunk/boost/thread/lockable_concepts.hpp 2012-10-29 15:05:35 EDT (Mon, 29 Oct 2012)
@@ -28,8 +28,11 @@
l.lock();
l.unlock();
}
+ BasicLockable() : l(*static_cast<Mutex*>(0)) {}
private:
- Mutex l;
+ BasicLockable operator=(BasicLockable const&);
+
+ Mutex& l;
}
;
//]
@@ -48,8 +51,10 @@
{
if (l.try_lock()) return;
}
+ Lockable() : l(*static_cast<Mutex*>(0)) {}
private:
- Mutex l;
+ Lockable operator=(Lockable const&);
+ Mutex& l;
};
//]
@@ -69,9 +74,12 @@
if (l.try_lock_until(t)) return;
if (l.try_lock_for(d)) return;
}
+ TimedLockable() : l(*static_cast<Mutex*>(0)) {}
+ private:
+ TimedLockable operator=(TimedLockable const&);
Mutex& l;
- chrono::system_clock::time_point& t;
- chrono::system_clock::duration& d;
+ chrono::system_clock::time_point t;
+ chrono::system_clock::duration d;
};
//]
@@ -94,9 +102,12 @@
if (l.try_lock_shared_until(t)) return;
if (l.try_lock_shared_for(d)) return;
}
+ SharedLockable() : l(*static_cast<Mutex*>(0)) {}
+ private:
+ SharedLockable operator=(SharedLockable const&);
Mutex& l;
- chrono::system_clock::time_point& t;
- chrono::system_clock::duration& d;
+ chrono::system_clock::time_point t;
+ chrono::system_clock::duration d;
};
//]
@@ -133,9 +144,12 @@
if (l.try_unlock_upgrade_and_lock_for(d)) return;
l.unlock_upgrade_and_lock_shared();
}
+ UpgradeLockable() : l(*static_cast<Mutex*>(0)) {}
+ private:
+ UpgradeLockable operator=(UpgradeLockable const&);
Mutex& l;
- chrono::system_clock::time_point& t;
- chrono::system_clock::duration& d;
+ chrono::system_clock::time_point t;
+ chrono::system_clock::duration d;
};
//]
Modified: trunk/boost/thread/strict_lock.hpp
==============================================================================
--- trunk/boost/thread/strict_lock.hpp (original)
+++ trunk/boost/thread/strict_lock.hpp 2012-10-29 15:05:35 EDT (Mon, 29 Oct 2012)
@@ -62,6 +62,8 @@
// observers
+ private:
+
/**
* @return the owned mutex.
*/
@@ -69,11 +71,12 @@
{
return &mtx_;
}
+ public:
/**
* @return whether if this lock is locking that mutex.
*/
- bool is_locking(mutex_type* l) const BOOST_NOEXCEPT
+ bool owns_lock(mutex_type const* l) const BOOST_NOEXCEPT
{
return l == mutex();
} /*< strict locks specific function >*/
@@ -115,7 +118,7 @@
* __Requires: <c>lk.mutex() != null_ptr</c>
* __Effects: Stores the reference to the lock parameter and takes ownership on it.
* If the lock doesn't owns the mutex @mtx lock it.
- * __Postconditions: @c is_locking()
+ * __Postconditions: @c owns_lock()
* __StrongException
* __Throws:
*
@@ -148,7 +151,7 @@
}
// observers
-
+private:
/**
* return @c the owned mutex.
*/
@@ -156,11 +159,11 @@
{
return tmp_lk_.mutex();
}
-
+public:
/**
* @return whether if this lock is locking that mutex.
*/
- bool is_locking(mutex_type* l) const BOOST_NOEXCEPT
+ bool owns_lock(mutex_type const* l) const BOOST_NOEXCEPT
{
return l == mutex();
}
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