|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85471 - in trunk/boost/sync: . locks
From: andrey.semashev_at_[hidden]
Date: 2013-08-25 18:23:55
Author: andysem
Date: 2013-08-25 18:23:54 EDT (Sun, 25 Aug 2013)
New Revision: 85471
URL: http://svn.boost.org/trac/boost/changeset/85471
Log:
Added shared_lock_guard. Removed make_lock_guard as it is not always reliable because it technically requires lock_guard to be copyable or moveable.
Added:
trunk/boost/sync/locks/shared_lock_guard.hpp (contents, props changed)
Text files modified:
trunk/boost/sync/locks.hpp | 1
trunk/boost/sync/locks/lock_guard.hpp | 41 ++---------------------
trunk/boost/sync/locks/shared_lock_guard.hpp | 69 ++++++++++++++++++++++++++++++++++++++++
trunk/boost/sync/locks/unique_lock.hpp | 12 ++----
4 files changed, 78 insertions(+), 45 deletions(-)
Modified: trunk/boost/sync/locks.hpp
==============================================================================
--- trunk/boost/sync/locks.hpp Sun Aug 25 15:10:31 2013 (r85470)
+++ trunk/boost/sync/locks.hpp 2013-08-25 18:23:54 EDT (Sun, 25 Aug 2013) (r85471)
@@ -21,5 +21,6 @@
#endif
#include <boost/sync/locks/lock_guard.hpp>
+#include <boost/sync/locks/shared_lock_guard.hpp>
#endif // BOOST_SYNC_LOCKS_HPP_INCLUDED_
Modified: trunk/boost/sync/locks/lock_guard.hpp
==============================================================================
--- trunk/boost/sync/locks/lock_guard.hpp Sun Aug 25 15:10:31 2013 (r85470)
+++ trunk/boost/sync/locks/lock_guard.hpp 2013-08-25 18:23:54 EDT (Sun, 25 Aug 2013) (r85471)
@@ -17,18 +17,15 @@
#define BOOST_SYNC_LOCKS_LOCK_GUARD_HPP_INCLUDED_
#include <boost/sync/detail/config.hpp>
-#if !defined(BOOST_SYNC_AUX_NO_CXX11_INITIALIZER_LISTS)
-#include <initializer_list>
-#include <boost/sync/detail/lockable_wrapper.hpp>
-#endif
-#include <boost/sync/locks/lock_options.hpp>
-
-#include <boost/sync/detail/header.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
#pragma once
#endif
+#include <boost/sync/locks/lock_options.hpp>
+
+#include <boost/sync/detail/header.hpp>
+
namespace boost {
namespace sync {
@@ -55,21 +52,6 @@
{
}
-#if !defined(BOOST_SYNC_AUX_NO_CXX11_INITIALIZER_LISTS)
-
- lock_guard(std::initializer_list< aux::lockable_wrapper< mutex_type > > l) :
- m_mutex(*(l.begin()->m_mutex))
- {
- m_mutex.lock();
- }
-
- lock_guard(std::initializer_list< aux::lockable_wrapper< mutex_type, adopt_lock_t > > l) :
- m_mutex(*(l.begin()->m_mutex))
- {
- }
-
-#endif // BOOST_SYNC_AUX_NO_CXX11_INITIALIZER_LISTS
-
~lock_guard()
{
m_mutex.unlock();
@@ -79,21 +61,6 @@
BOOST_DELETED_FUNCTION(lock_guard& operator= (lock_guard const&))
};
-#if !defined(BOOST_SYNC_AUX_NO_CXX11_INITIALIZER_LISTS)
-
-template< typename LockableT >
-inline lock_guard< LockableT > make_lock_guard(LockableT& mtx)
-{
- return { aux::lockable_wrapper< LockableT >(mtx) };
-}
-template< typename LockableT >
-inline lock_guard< LockableT > make_lock_guard(LockableT& mtx, adopt_lock_t)
-{
- return { aux::lockable_wrapper< LockableT, adopt_lock_t >(mtx) };
-}
-
-#endif // BOOST_SYNC_AUX_NO_CXX11_INITIALIZER_LISTS
-
} // namespace sync
} // namespace boost
Added: trunk/boost/sync/locks/shared_lock_guard.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/locks/shared_lock_guard.hpp 2013-08-25 18:23:54 EDT (Sun, 25 Aug 2013) (r85471)
@@ -0,0 +1,69 @@
+/*
+ * 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)
+ *
+ * (C) Copyright 2012 Vicente J. Botet Escriba
+ * (C) Copyright 2013 Andrey Semashev
+ */
+/*!
+ * \file locks/shared_lock_guard.hpp
+ *
+ * \brief This header defines an exclusive lock guard.
+ */
+
+#ifndef BOOST_SYNC_LOCKS_SHARED_LOCK_GUARD_HPP_INCLUDED_
+#define BOOST_SYNC_LOCKS_SHARED_LOCK_GUARD_HPP_INCLUDED_
+
+#include <boost/sync/detail/config.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+#include <boost/sync/locks/lock_options.hpp>
+
+#include <boost/sync/detail/header.hpp>
+
+namespace boost {
+
+namespace sync {
+
+/*!
+ * \brief A shared lock scope guard
+ */
+template< typename MutexT >
+class shared_lock_guard
+{
+private:
+ MutexT& m_mutex;
+
+public:
+ typedef MutexT mutex_type;
+
+public:
+ explicit shared_lock_guard(mutex_type& m) : m_mutex(m)
+ {
+ m.lock_shared();
+ }
+
+ shared_lock_guard(mutex_type& m, adopt_lock_t) : m_mutex(m)
+ {
+ }
+
+ ~shared_lock_guard()
+ {
+ m_mutex.unlock_shared();
+ }
+
+ BOOST_DELETED_FUNCTION(shared_lock_guard(shared_lock_guard const&))
+ BOOST_DELETED_FUNCTION(shared_lock_guard& operator= (shared_lock_guard const&))
+};
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_LOCKS_SHARED_LOCK_GUARD_HPP_INCLUDED_
Modified: trunk/boost/sync/locks/unique_lock.hpp
==============================================================================
--- trunk/boost/sync/locks/unique_lock.hpp Sun Aug 25 15:10:31 2013 (r85470)
+++ trunk/boost/sync/locks/unique_lock.hpp 2013-08-25 18:23:54 EDT (Sun, 25 Aug 2013) (r85471)
@@ -8,21 +8,17 @@
* (C) Copyright 2013 Andrey Semashev
*/
/*!
- * \file locks/lock_guard.hpp
+ * \file locks/unique_lock.hpp
*
* \brief This header defines an exclusive lock guard.
*/
-#ifndef BOOST_SYNC_LOCKS_LOCK_GUARD_HPP_INCLUDED_
-#define BOOST_SYNC_LOCKS_LOCK_GUARD_HPP_INCLUDED_
+#ifndef BOOST_SYNC_LOCKS_UNIQUE_LOCK_HPP_INCLUDED_
+#define BOOST_SYNC_LOCKS_UNIQUE_LOCK_HPP_INCLUDED_
#include <cstddef>
#include <boost/utility/enable_if.hpp>
#include <boost/sync/detail/config.hpp>
-#if !defined(BOOST_SYNC_AUX_NO_CXX11_INITIALIZER_LISTS)
-#include <initializer_list>
-#include <boost/sync/detail/lockable_wrapper.hpp>
-#endif
#include <boost/sync/locks/lock_options.hpp>
#include <boost/sync/detail/header.hpp>
@@ -415,4 +411,4 @@
#include <boost/sync/detail/footer.hpp>
-#endif // BOOST_SYNC_LOCKS_LOCK_GUARD_HPP_INCLUDED_
+#endif // BOOST_SYNC_LOCKS_UNIQUE_LOCK_HPP_INCLUDED_
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