Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85676 - in trunk/boost/sync: . detail detail/osx detail/posix detail/posix/mutexes detail/windows exceptions locks mutexes
From: andrey.semashev_at_[hidden]
Date: 2013-09-15 11:57:21


Author: andysem
Date: 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013)
New Revision: 85676
URL: http://svn.boost.org/trac/boost/changeset/85676

Log:
Implemented a few exceptions and basic mutexes.

Added:
   trunk/boost/sync/detail/osx/
   trunk/boost/sync/detail/posix/
   trunk/boost/sync/detail/posix/mutexes/
   trunk/boost/sync/detail/posix/mutexes/mutex.hpp (contents, props changed)
   trunk/boost/sync/detail/posix/mutexes/timed_mutex.hpp (contents, props changed)
   trunk/boost/sync/detail/pthread.hpp (contents, props changed)
   trunk/boost/sync/detail/pthread_mutex_locks.hpp (contents, props changed)
   trunk/boost/sync/detail/system_error.hpp (contents, props changed)
   trunk/boost/sync/detail/windows/
   trunk/boost/sync/exceptions/
   trunk/boost/sync/exceptions.hpp (contents, props changed)
   trunk/boost/sync/exceptions/lock_error.hpp (contents, props changed)
   trunk/boost/sync/exceptions/resource_error.hpp (contents, props changed)
   trunk/boost/sync/exceptions/runtime_exception.hpp (contents, props changed)
   trunk/boost/sync/mutexes/
   trunk/boost/sync/mutexes.hpp (contents, props changed)
   trunk/boost/sync/mutexes/mutex.hpp (contents, props changed)
   trunk/boost/sync/mutexes/timed_mutex.hpp (contents, props changed)
Text files modified:
   trunk/boost/sync/detail/config.hpp | 4
   trunk/boost/sync/detail/posix/mutexes/mutex.hpp | 120 ++++++++++++++++++
   trunk/boost/sync/detail/posix/mutexes/timed_mutex.hpp | 255 ++++++++++++++++++++++++++++++++++++++++
   trunk/boost/sync/detail/pthread.hpp | 136 +++++++++++++++++++++
   trunk/boost/sync/detail/pthread_mutex_locks.hpp | 84 +++++++++++++
   trunk/boost/sync/detail/system_error.hpp | 51 ++++++++
   trunk/boost/sync/exceptions.hpp | 27 ++++
   trunk/boost/sync/exceptions/lock_error.hpp | 58 +++++++++
   trunk/boost/sync/exceptions/resource_error.hpp | 58 +++++++++
   trunk/boost/sync/exceptions/runtime_exception.hpp | 64 ++++++++++
   trunk/boost/sync/locks/unique_lock.hpp | 32 ++--
   trunk/boost/sync/mutexes.hpp | 26 ++++
   trunk/boost/sync/mutexes/mutex.hpp | 104 ++++++++++++++++
   trunk/boost/sync/mutexes/timed_mutex.hpp | 118 ++++++++++++++++++
   trunk/boost/sync/semaphore.hpp | 4
   15 files changed, 1122 insertions(+), 19 deletions(-)

Modified: trunk/boost/sync/detail/config.hpp
==============================================================================
--- trunk/boost/sync/detail/config.hpp Sun Sep 15 09:55:24 2013 (r85675)
+++ trunk/boost/sync/detail/config.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -40,10 +40,6 @@
 #define BOOST_SYNC_DETAIL_PLATFORM_PTHREAD
 #endif
 
-#if defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) || defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-#define BOOST_SYNC_DETAIL_NO_CXX11_INITIALIZER_LISTS
-#endif
-
 
 #ifdef BOOST_HAS_UNISTD_H
 #include <unistd.h>

Added: trunk/boost/sync/detail/posix/mutexes/mutex.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/detail/posix/mutexes/mutex.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,120 @@
+/*
+ * 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 2007-2008 Anthony Williams
+ * (C) Copyright 2012-2013 Vicente J. Botet Escriba
+ * (C) Copyright 2013 Andrey Semashev
+ */
+/*!
+ * \file detail/pthread/mutexes/mutex.hpp
+ *
+ * \brief This header is the Boost.Sync library implementation, see the library documentation
+ * at http://www.boost.org/doc/libs/release/libs/sync/doc/html/index.html.
+ */
+
+#ifndef BOOST_SYNC_DETAIL_POSIX_MUTEXES_MUTEX_HPP_INCLUDED_
+#define BOOST_SYNC_DETAIL_POSIX_MUTEXES_MUTEX_HPP_INCLUDED_
+
+#include <boost/assert.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/sync/exceptions/lock_error.hpp>
+#include <boost/sync/exceptions/resource_error.hpp>
+#include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/pthread.hpp>
+
+#include <boost/sync/detail/header.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+#define BOOST_SYNC_DEFINES_MUTEX_NATIVE_HANDLE
+
+namespace boost {
+
+namespace sync {
+
+BOOST_SYNC_DETAIL_OPEN_ABI_NAMESPACE {
+
+class mutex
+{
+public:
+ typedef pthread_mutex_t* native_handle_type;
+
+private:
+ pthread_mutex_t m_mutex;
+
+public:
+#if defined(PTHREAD_MUTEX_INITIALIZER)
+#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
+ BOOST_CONSTEXPR mutex() BOOST_NOEXCEPT : m_mutex{ PTHREAD_MUTEX_INITIALIZER }
+ {
+ }
+#else
+ BOOST_CONSTEXPR mutex() BOOST_NOEXCEPT
+ {
+ BOOST_CONSTEXPR_OR_CONST pthread_mutex_t temp = PTHREAD_MUTEX_INITIALIZER;
+ m_mutex = temp;
+ }
+#endif
+#else // defined(PTHREAD_MUTEX_INITIALIZER)
+ mutex()
+ {
+ int const res = pthread_mutex_init(&m_mutex, 0);
+ if (res)
+ {
+ BOOST_THROW_EXCEPTION(resource_error(res, "boost:: mutex constructor failed in pthread_mutex_init"));
+ }
+ }
+#endif // defined(PTHREAD_MUTEX_INITIALIZER)
+
+ ~mutex()
+ {
+ BOOST_VERIFY(sync::detail::posix::pthread_mutex_destroy(&m_mutex) == 0);
+ }
+
+ void lock()
+ {
+ int const res = sync::detail::posix::pthread_mutex_lock(&m_mutex);
+ if (res)
+ {
+ BOOST_THROW_EXCEPTION(lock_error(res, "boost: mutex lock failed in pthread_mutex_lock"));
+ }
+ }
+
+ void unlock() BOOST_NOEXCEPT
+ {
+ BOOST_VERIFY(sync::detail::posix::pthread_mutex_unlock(&m_mutex) == 0);
+ }
+
+ bool try_lock()
+ {
+ int const res = sync::detail::posix::pthread_mutex_trylock(&m_mutex);
+
+ if (res == 0)
+ return true;
+ else if (res != EBUSY)
+ BOOST_THROW_EXCEPTION(lock_error(res, "boost: mutex trylock failed in pthread_mutex_trylock"));
+ return false;
+ }
+
+ native_handle_type native_handle() BOOST_NOEXCEPT
+ {
+ return &m_mutex;
+ }
+
+ BOOST_DELETED_FUNCTION(mutex(mutex const&))
+ BOOST_DELETED_FUNCTION(mutex& operator= (mutex const&))
+};
+
+} // namespace posix
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_DETAIL_POSIX_MUTEXES_MUTEX_HPP_INCLUDED_

Added: trunk/boost/sync/detail/posix/mutexes/timed_mutex.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/detail/posix/mutexes/timed_mutex.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,255 @@
+/*
+ * 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 2007-2008 Anthony Williams
+ * (C) Copyright 2012-2013 Vicente J. Botet Escriba
+ * (C) Copyright 2013 Andrey Semashev
+ */
+/*!
+ * \file detail/pthread/mutexes/timed_mutex.hpp
+ *
+ * \brief This header is the Boost.Sync library implementation, see the library documentation
+ * at http://www.boost.org/doc/libs/release/libs/sync/doc/html/index.html.
+ */
+
+#ifndef BOOST_SYNC_DETAIL_POSIX_MUTEXES_TIMED_MUTEX_HPP_INCLUDED_
+#define BOOST_SYNC_DETAIL_POSIX_MUTEXES_TIMED_MUTEX_HPP_INCLUDED_
+
+#include <time.h>
+#include <boost/assert.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/sync/exceptions/lock_error.hpp>
+#include <boost/sync/exceptions/resource_error.hpp>
+#include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/pthread.hpp>
+#include <boost/sync/detail/time_traits.hpp>
+#include <boost/sync/detail/time_units.hpp>
+#if defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+#include <boost/sync/detail/pthread_mutex_locks.hpp>
+#endif
+#include <boost/sync/detail/header.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+#define BOOST_SYNC_DEFINES_TIMED_MUTEX_NATIVE_HANDLE
+
+namespace boost {
+
+namespace sync {
+
+#if defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+
+namespace detail {
+
+namespace BOOST_SYNC_DETAIL_ABI_NAMESPACE {
+
+#if defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+using ::pthread_mutex_timedlock;
+#else
+BOOST_FORCEINLINE int pthread_mutex_timedlock(pthread_mutex_t* m, const struct timespec* t)
+{
+ int ret;
+ do
+ {
+ ret = ::pthread_mutex_timedlock(m, t);
+ }
+ while (ret == EINTR);
+ return ret;
+}
+#endif
+
+} // namespace posix
+
+} // namespace detail
+
+#endif // defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+
+BOOST_SYNC_DETAIL_OPEN_ABI_NAMESPACE {
+
+class timed_mutex
+{
+public:
+ typedef pthread_mutex_t* native_handle_type;
+
+private:
+ pthread_mutex_t m_mutex;
+#if !defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+ pthread_cond_t m_cond;
+ bool m_is_locked;
+#endif
+
+public:
+#if defined(PTHREAD_MUTEX_INITIALIZER) && (defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK) || defined(PTHREAD_COND_INITIALIZER))
+#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
+ BOOST_CONSTEXPR timed_mutex() BOOST_NOEXCEPT :
+ m_mutex{ PTHREAD_MUTEX_INITIALIZER }
+#if !defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+ , m_cond{ PTHREAD_COND_INITIALIZER },
+ m_is_locked(false)
+#endif
+ {
+ }
+#else
+ BOOST_CONSTEXPR timed_mutex() BOOST_NOEXCEPT
+ {
+ BOOST_CONSTEXPR_OR_CONST pthread_mutex_t temp = PTHREAD_MUTEX_INITIALIZER;
+ m_mutex = temp;
+
+#if !defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+ BOOST_CONSTEXPR_OR_CONST pthread_cond_t temp2 = PTHREAD_COND_INITIALIZER;
+ m_cond = temp2;
+ m_is_locked = false;
+#endif
+ }
+#endif
+#else // defined(PTHREAD_MUTEX_INITIALIZER)
+ timed_mutex()
+ {
+ int const res = pthread_mutex_init(&m_mutex, 0);
+ if (res)
+ {
+ BOOST_THROW_EXCEPTION(resource_error(res, "boost:: timed_mutex constructor failed in pthread_mutex_init"));
+ }
+
+#if !defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+ int const res2 = pthread_cond_init(&m_cond, 0);
+ if (res2)
+ {
+ BOOST_THROW_EXCEPTION(resource_error(res, "boost:: timed_mutex constructor failed in pthread_cond_init"));
+ }
+ m_is_locked = false;
+#endif
+ }
+#endif // defined(PTHREAD_MUTEX_INITIALIZER)
+
+ ~timed_mutex()
+ {
+ BOOST_VERIFY(sync::detail::posix::pthread_mutex_destroy(&m_mutex) == 0);
+#if !defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+ BOOST_VERIFY(::pthread_cond_destroy(&m_cond) == 0);
+#endif
+ }
+
+#if defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+
+ void lock()
+ {
+ int const res = sync::detail::posix::pthread_mutex_lock(&m_mutex);
+ if (res)
+ {
+ BOOST_THROW_EXCEPTION(lock_error(res, "boost: timed_mutex lock failed in pthread_mutex_lock"));
+ }
+ }
+
+ void unlock() BOOST_NOEXCEPT
+ {
+ BOOST_VERIFY(sync::detail::posix::pthread_mutex_unlock(&m_mutex) == 0);
+ }
+
+ bool try_lock()
+ {
+ int const res = sync::detail::posix::pthread_mutex_trylock(&m_mutex);
+
+ if (res == 0)
+ return true;
+ else if (res != EBUSY)
+ BOOST_THROW_EXCEPTION(lock_error(res, "boost: timed_mutex trylock failed in pthread_mutex_trylock"));
+ return false;
+ }
+
+#else // defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+
+ void lock()
+ {
+ sync::detail::posix::pthread_mutex_lock_guard const local_lock(m_mutex);
+ while (m_is_locked)
+ {
+ BOOST_VERIFY(!pthread_cond_wait(&m_cond, &m_mutex));
+ }
+ m_is_locked = true;
+ }
+
+ void unlock() BOOST_NOEXCEPT
+ {
+ sync::detail::posix::pthread_mutex_lock_guard const local_lock(m_mutex);
+ m_is_locked = false;
+ BOOST_VERIFY(pthread_cond_signal(&m_cond) == 0);
+ }
+
+ bool try_lock()
+ {
+ sync::detail::posix::pthread_mutex_lock_guard const local_lock(m_mutex);
+ if (m_is_locked)
+ {
+ return false;
+ }
+ m_is_locked = true;
+ return true;
+ }
+
+#endif // defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+
+ template< typename Time >
+ typename enable_if_c< sync::detail::time_traits< Time >::is_specialized, bool >::type timed_lock(Time const& t)
+ {
+ return timed_lock(sync::detail::time_traits< Time >::to_sync_unit(t));
+ }
+
+ native_handle_type native_handle() BOOST_NOEXCEPT
+ {
+ return &m_mutex;
+ }
+
+ BOOST_DELETED_FUNCTION(timed_mutex(timed_mutex const&))
+ BOOST_DELETED_FUNCTION(timed_mutex& operator= (timed_mutex const&))
+
+private:
+ bool timed_lock(sync::detail::duration dur)
+ {
+ return timed_lock(sync::detail::time_point::now() + dur);
+ }
+
+ bool timed_lock(sync::detail::time_point const& t)
+ {
+#if defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+
+ int const res = sync::detail::posix::pthread_mutex_timedlock(&m_mutex, &t.get());
+
+ if (res == 0)
+ return true;
+ else if (res != ETIMEDOUT)
+ BOOST_THROW_EXCEPTION(lock_error(res, "boost: timed_mutex timedlock failed in pthread_mutex_timedlock"));
+ return false;
+
+#else // defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+
+ sync::detail::posix::pthread_mutex_lock_guard const local_lock(m_mutex);
+ while (m_is_locked)
+ {
+ int const cond_res = pthread_cond_timedwait(&m_cond, &m_mutex, &t.get());
+ if (cond_res == ETIMEDOUT)
+ return false;
+ else if (cond_res != 0)
+ BOOST_THROW_EXCEPTION(lock_error(res, "boost: timed_mutex timedlock failed in pthread_cond_timedwait"));
+ }
+ m_is_locked = true;
+ return true;
+
+#endif // defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
+ }
+};
+
+} // namespace posix
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_DETAIL_POSIX_MUTEXES_TIMED_MUTEX_HPP_INCLUDED_

Added: trunk/boost/sync/detail/pthread.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/detail/pthread.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,136 @@
+/*
+ * 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-2013 Vicente J. Botet Escriba
+ * (C) Copyright 2013 Andrey Semashev
+ */
+/*!
+ * \file pthread.hpp
+ *
+ * \brief This header is the Boost.Sync library implementation, see the library documentation
+ * at http://www.boost.org/doc/libs/release/libs/sync/doc/html/index.html.
+ *
+ * This header contains POSIX threads support configuration.
+ */
+
+#ifndef BOOST_SYNC_DETAIL_PTHREAD_HPP_INCLUDED_
+#define BOOST_SYNC_DETAIL_PTHREAD_HPP_INCLUDED_
+
+#include <errno.h>
+#include <pthread.h>
+#include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/header.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+#ifdef _POSIX_TIMEOUTS
+#if _POSIX_TIMEOUTS >= 0 && _POSIX_TIMEOUTS >= 200112L
+#ifndef BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK
+#define BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK
+#endif
+#endif
+#endif
+
+// ABI namespace name
+#define BOOST_SYNC_DETAIL_ABI_NAMESPACE posix
+
+#if !defined(BOOST_NO_CXX11_INLINE_NAMESPACES)
+#define BOOST_SYNC_DETAIL_OPEN_ABI_NAMESPACE inline namespace BOOST_SYNC_DETAIL_ABI_NAMESPACE
+#else
+#define BOOST_SYNC_DETAIL_OPEN_ABI_NAMESPACE namespace BOOST_SYNC_DETAIL_ABI_NAMESPACE
+#endif // !defined(BOOST_NO_CXX11_INLINE_NAMESPACES)
+
+namespace boost {
+
+namespace sync {
+
+#if defined(BOOST_NO_CXX11_INLINE_NAMESPACES)
+
+// Emulate inline namespace with a using directive
+
+BOOST_SYNC_DETAIL_OPEN_ABI_NAMESPACE {}
+
+using namespace BOOST_SYNC_DETAIL_ABI_NAMESPACE
+#if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+__attribute__((__strong__))
+#endif
+;
+
+#endif // defined(BOOST_NO_CXX11_INLINE_NAMESPACES)
+
+namespace detail {
+
+namespace posix {
+
+#if !defined(BOOST_SYNC_HAS_PTHREAD_EINTR_BUG)
+
+using ::pthread_mutex_destroy;
+using ::pthread_mutex_lock;
+using ::pthread_mutex_trylock;
+using ::pthread_mutex_unlock;
+
+#else // !defined(BOOST_SYNC_HAS_PTHREAD_EINTR_BUG)
+
+// Workaround for https://svn.boost.org/trac/boost/ticket/6200
+
+BOOST_FORCEINLINE int pthread_mutex_destroy(pthread_mutex_t* m)
+{
+ int ret;
+ do
+ {
+ ret = ::pthread_mutex_destroy(m);
+ }
+ while (ret == EINTR);
+ return ret;
+}
+
+BOOST_FORCEINLINE int pthread_mutex_lock(pthread_mutex_t* m)
+{
+ int ret;
+ do
+ {
+ ret = ::pthread_mutex_lock(m);
+ }
+ while (ret == EINTR);
+ return ret;
+}
+
+BOOST_FORCEINLINE int pthread_mutex_trylock(pthread_mutex_t* m)
+{
+ int ret;
+ do
+ {
+ ret = ::pthread_mutex_trylock(m);
+ }
+ while (ret == EINTR);
+ return ret;
+}
+
+BOOST_FORCEINLINE int pthread_mutex_unlock(pthread_mutex_t* m)
+{
+ int ret;
+ do
+ {
+ ret = ::pthread_mutex_unlock(m);
+ }
+ while (ret == EINTR);
+ return ret;
+}
+
+#endif // !defined(BOOST_SYNC_HAS_PTHREAD_EINTR_BUG)
+
+} // namespace posix
+
+} // namespace detail
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_DETAIL_PTHREAD_HPP_INCLUDED_

Added: trunk/boost/sync/detail/pthread_mutex_locks.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/detail/pthread_mutex_locks.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,84 @@
+/*
+ * 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 2007-2008 Anthony Williams
+ * (C) Copyright 2013 Andrey Semashev
+ */
+/*!
+ * \file pthread_mutex_locks.hpp
+ *
+ * \brief This header is the Boost.Sync library implementation, see the library documentation
+ * at http://www.boost.org/doc/libs/release/libs/sync/doc/html/index.html.
+ */
+
+#ifndef BOOST_SYNC_DETAIL_PTHREAD_MUTEX_LOCKS_HPP_INCLUDED_
+#define BOOST_SYNC_DETAIL_PTHREAD_MUTEX_LOCKS_HPP_INCLUDED_
+
+#include <boost/assert.hpp>
+#include <boost/sync/detail/pthread.hpp>
+#include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/header.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+namespace boost {
+
+namespace sync {
+
+namespace detail {
+
+namespace posix {
+
+class pthread_mutex_lock_guard
+{
+ pthread_mutex_t* const m_mutex;
+
+public:
+ explicit pthread_mutex_lock_guard(pthread_mutex_t& m) BOOST_NOEXCEPT : m_mutex(&m)
+ {
+ BOOST_VERIFY(pthread_mutex_lock(m_mutex) == 0);
+ }
+
+ ~pthread_mutex_lock_guard()
+ {
+ BOOST_VERIFY(pthread_mutex_unlock(m_mutex) == 0);
+ }
+
+ BOOST_DELETED_FUNCTION(pthread_mutex_lock_guard(pthread_mutex_lock_guard const&))
+ BOOST_DELETED_FUNCTION(pthread_mutex_lock_guard& operator= (pthread_mutex_lock_guard const&))
+};
+
+class pthread_mutex_unlock_guard
+{
+ pthread_mutex_t* const m_mutex;
+
+public:
+ explicit pthread_mutex_unlock_guard(pthread_mutex_t& m) BOOST_NOEXCEPT : m_mutex(&m)
+ {
+ BOOST_VERIFY(pthread_mutex_unlock(m_mutex) == 0);
+ }
+
+ ~pthread_mutex_unlock_guard()
+ {
+ BOOST_VERIFY(pthread_mutex_lock(m_mutex) == 0);
+ }
+
+ BOOST_DELETED_FUNCTION(pthread_mutex_unlock_guard(pthread_mutex_unlock_guard const&))
+ BOOST_DELETED_FUNCTION(pthread_mutex_unlock_guard& operator= (pthread_mutex_unlock_guard const&))
+};
+
+} // namespace posix
+
+} // namespace detail
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_DETAIL_PTHREAD_MUTEX_LOCKS_HPP_INCLUDED_

Added: trunk/boost/sync/detail/system_error.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/detail/system_error.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,51 @@
+/*
+ * 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 2013 Andrey Semashev
+ */
+/*!
+ * \file system_error.hpp
+ *
+ * \brief This header is the Boost.Sync library implementation, see the library documentation
+ * at http://www.boost.org/doc/libs/release/libs/sync/doc/html/index.html.
+ */
+
+#ifndef BOOST_SYNC_DETAIL_SYSTEM_ERROR_HPP_INCLUDED_
+#define BOOST_SYNC_DETAIL_SYSTEM_ERROR_HPP_INCLUDED_
+
+#include <boost/sync/detail/config.hpp>
+#if defined(BOOST_SYNC_USE_STD_SYSTEM_ERROR)
+#include <system_error>
+#else
+#include <boost/system/error_code.hpp>
+#include <boost/system/system_error.hpp>
+#endif
+#include <boost/sync/detail/header.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+namespace boost {
+
+namespace sync {
+
+namespace detail {
+
+#if defined(BOOST_SYNC_USE_STD_SYSTEM_ERROR)
+namespace system_namespace = std;
+#else
+namespace system_namespace = boost::system;
+#endif
+
+} // namespace detail
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_DETAIL_SYSTEM_ERROR_HPP_INCLUDED_

Added: trunk/boost/sync/exceptions.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/exceptions.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,27 @@
+/*
+ * 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 2013 Andrey Semashev
+ */
+/*!
+ * \file exceptions.hpp
+ *
+ * \brief This header includes all exception types.
+ */
+
+#ifndef BOOST_SYNC_EXCEPTIONS_HPP_INCLUDED_
+#define BOOST_SYNC_EXCEPTIONS_HPP_INCLUDED_
+
+#include <boost/sync/detail/config.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+#include <boost/sync/exceptions/runtime_exception.hpp>
+#include <boost/sync/exceptions/resource_error.hpp>
+#include <boost/sync/exceptions/lock_error.hpp>
+
+#endif // BOOST_SYNC_EXCEPTIONS_HPP_INCLUDED_

Added: trunk/boost/sync/exceptions/lock_error.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/exceptions/lock_error.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,58 @@
+/*
+ * 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 2013 Andrey Semashev
+ */
+/*!
+ * \file exceptions/lock_error.hpp
+ *
+ * \brief This header defines the \c lock_error exception.
+ */
+
+#ifndef BOOST_SYNC_EXCEPTIONS_LOCK_ERROR_HPP_INCLUDED_
+#define BOOST_SYNC_EXCEPTIONS_LOCK_ERROR_HPP_INCLUDED_
+
+#include <string>
+#include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/system_error.hpp>
+#include <boost/sync/exceptions/runtime_exception.hpp>
+#include <boost/sync/detail/header.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+namespace boost {
+
+namespace sync {
+
+class BOOST_VISIBLE_SYMBOL lock_error :
+ public runtime_exception
+{
+public:
+ explicit lock_error(int sys_err = 0) : runtime_exception(sys_err, "boost::sync::lock_error")
+ {
+ }
+
+ lock_error(int sys_err, const char* what) : runtime_exception(sys_err, what)
+ {
+ }
+
+ lock_error(int sys_err, std::string const& what) : runtime_exception(sys_err, what)
+ {
+ }
+
+ ~lock_error() BOOST_NOEXCEPT_OR_NOTHROW
+ {
+ }
+};
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_EXCEPTIONS_LOCK_ERROR_HPP_INCLUDED_

Added: trunk/boost/sync/exceptions/resource_error.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/exceptions/resource_error.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,58 @@
+/*
+ * 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 2013 Andrey Semashev
+ */
+/*!
+ * \file exceptions/resource_error.hpp
+ *
+ * \brief This header defines the \c resource_error exception.
+ */
+
+#ifndef BOOST_SYNC_EXCEPTIONS_RESOURCE_ERROR_HPP_INCLUDED_
+#define BOOST_SYNC_EXCEPTIONS_RESOURCE_ERROR_HPP_INCLUDED_
+
+#include <string>
+#include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/system_error.hpp>
+#include <boost/sync/exceptions/runtime_exception.hpp>
+#include <boost/sync/detail/header.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+namespace boost {
+
+namespace sync {
+
+class BOOST_VISIBLE_SYMBOL resource_error :
+ public runtime_exception
+{
+public:
+ explicit resource_error(int sys_err = 0) : runtime_exception(sys_err, "boost::sync::resource_error")
+ {
+ }
+
+ resource_error(int sys_err, const char* what) : runtime_exception(sys_err, what)
+ {
+ }
+
+ resource_error(int sys_err, std::string const& what) : runtime_exception(sys_err, what)
+ {
+ }
+
+ ~resource_error() BOOST_NOEXCEPT_OR_NOTHROW
+ {
+ }
+};
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_EXCEPTIONS_RESOURCE_ERROR_HPP_INCLUDED_

Added: trunk/boost/sync/exceptions/runtime_exception.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/exceptions/runtime_exception.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,64 @@
+/*
+ * 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 2013 Andrey Semashev
+ */
+/*!
+ * \file exceptions/runtime_exception.hpp
+ *
+ * \brief This header defines a base class for all exceptions from Boost.Sync.
+ */
+
+#ifndef BOOST_SYNC_EXCEPTIONS_RUNTIME_EXCEPTION_HPP_INCLUDED_
+#define BOOST_SYNC_EXCEPTIONS_RUNTIME_EXCEPTION_HPP_INCLUDED_
+
+#include <string>
+#include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/system_error.hpp>
+#include <boost/sync/detail/header.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+namespace boost {
+
+namespace sync {
+
+class BOOST_VISIBLE_SYMBOL runtime_exception :
+ public sync::detail::system_namespace::system_error
+{
+public:
+ explicit runtime_exception(int sys_err = 0) : sync::detail::system_namespace::system_error(sys_err, sync::detail::system_namespace::system_category())
+ {
+ }
+
+ runtime_exception(int sys_err, const char* what) :
+ sync::detail::system_namespace::system_error(sync::detail::system_namespace::error_code(sys_err, sync::detail::system_namespace::system_category()), what)
+ {
+ }
+
+ runtime_exception(int sys_err, std::string const& what) :
+ sync::detail::system_namespace::system_error(sync::detail::system_namespace::error_code(sys_err, sync::detail::system_namespace::system_category()), what)
+ {
+ }
+
+ ~runtime_exception() BOOST_NOEXCEPT_OR_NOTHROW
+ {
+ }
+
+ int native_error() const BOOST_NOEXCEPT
+ {
+ return this->code().value();
+ }
+};
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_EXCEPTIONS_RUNTIME_EXCEPTION_HPP_INCLUDED_

Modified: trunk/boost/sync/locks/unique_lock.hpp
==============================================================================
--- trunk/boost/sync/locks/unique_lock.hpp Sun Sep 15 09:55:24 2013 (r85675)
+++ trunk/boost/sync/locks/unique_lock.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -24,6 +24,8 @@
 #include <boost/utility/explicit_operator_bool.hpp>
 #include <boost/sync/detail/config.hpp>
 #include <boost/sync/detail/time_traits.hpp>
+#include <boost/sync/detail/system_error.hpp>
+#include <boost/sync/exceptions/lock_error.hpp>
 #include <boost/sync/locks/lock_options.hpp>
 #include <boost/sync/locks/unique_lock_fwd.hpp>
 #include <boost/sync/locks/shared_lock_fwd.hpp>
@@ -84,7 +86,7 @@
     }
 
     template< typename Time >
- unique_lock(typename enable_if_c< detail::time_traits< Time >::is_supported, mutex_type& >::type m, Time const& t) :
+ unique_lock(typename enable_if_c< detail::time_traits< Time >::is_specialized, mutex_type& >::type m, Time const& t) :
         m_mutex(&m), m_is_locked(false)
     {
         timed_lock(t);
@@ -144,7 +146,7 @@
     }
 
     template< typename Time >
- unique_lock(BOOST_RV_REF(shared_lock< mutex_type >) sl, Time const& t, typename enable_if_c< detail::time_traits< Time >::is_supported, int >::type = 0) :
+ unique_lock(BOOST_RV_REF(shared_lock< mutex_type >) sl, Time const& t, typename enable_if_c< detail::time_traits< Time >::is_specialized, int >::type = 0) :
         m_mutex(NULL), m_is_locked(false)
     {
         if (sl.owns_lock())
@@ -186,11 +188,11 @@
     {
         if (!m_mutex)
         {
- boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::operation_not_permitted, "boost unique_lock has no mutex"));
         }
         if (m_is_locked)
         {
- boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
         }
 
         m_mutex->lock();
@@ -201,11 +203,11 @@
     {
         if (!m_mutex)
         {
- boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::operation_not_permitted, "boost unique_lock has no mutex"));
         }
         if (m_is_locked)
         {
- boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
         }
 
         m_is_locked = m_mutex->try_lock();
@@ -214,15 +216,15 @@
     }
 
     template< typename Time >
- typename enable_if_c< detail::time_traits< Time >::is_supported, bool >::type timed_lock(Time const& time)
+ typename enable_if_c< detail::time_traits< Time >::is_specialized, bool >::type timed_lock(Time const& time)
     {
         if (!m_mutex)
         {
- boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::operation_not_permitted, "boost unique_lock has no mutex"));
         }
         if (m_is_locked)
         {
- boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
         }
 
         m_is_locked = m->timed_lock(time);
@@ -235,11 +237,11 @@
     {
         if (!m_mutex)
         {
- boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::operation_not_permitted, "boost unique_lock has no mutex"));
         }
         if (m_is_locked)
         {
- boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
         }
 
         m_is_locked = m_mutex->try_lock_for(rel_time);
@@ -252,11 +254,11 @@
     {
         if (!m_mutex)
         {
- boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::operation_not_permitted, "boost unique_lock has no mutex"));
         }
         if (m_is_locked)
         {
- boost::throw_exception(boost::lock_error(system::errc::resource_deadlock_would_occur, "boost unique_lock owns already the mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
         }
 
         m_is_locked = m_mutex->try_lock_until(abs_time);
@@ -268,11 +270,11 @@
     {
         if (!m_mutex)
         {
- boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::operation_not_permitted, "boost unique_lock has no mutex"));
         }
         if (m_is_locked)
         {
- boost::throw_exception(boost::lock_error(system::errc::operation_not_permitted, "boost unique_lock doesn't own the mutex"));
+ BOOST_THROW_EXCEPTION(lock_error(detail::system_namespace::errc::operation_not_permitted, "boost unique_lock doesn't own the mutex"));
         }
 
         m_mutex->unlock();

Added: trunk/boost/sync/mutexes.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/mutexes.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,26 @@
+/*
+ * 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 2013 Andrey Semashev
+ */
+/*!
+ * \file mutexes.hpp
+ *
+ * \brief This header includes all mutex types.
+ */
+
+#ifndef BOOST_SYNC_MUTEXES_HPP_INCLUDED_
+#define BOOST_SYNC_MUTEXES_HPP_INCLUDED_
+
+#include <boost/sync/detail/config.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+#include <boost/sync/mutexes/mutex.hpp>
+#include <boost/sync/mutexes/timed_mutex.hpp>
+
+#endif // BOOST_SYNC_MUTEXES_HPP_INCLUDED_

Added: trunk/boost/sync/mutexes/mutex.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/mutexes/mutex.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,104 @@
+/*
+ * 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 2013 Andrey Semashev
+ */
+/*!
+ * \file sync/mutexes/mutex.hpp
+ *
+ * \brief This header defines a basic mutex primitive.
+ */
+
+#ifndef BOOST_SYNC_MUTEXES_MUTEX_HPP_INCLUDED_
+#define BOOST_SYNC_MUTEXES_MUTEX_HPP_INCLUDED_
+
+#if defined(BOOST_SYNC_DETAIL_DOXYGEN)
+
+namespace boost {
+
+namespace sync {
+
+class mutex
+{
+public:
+ /*!
+ * \brief Default constructor
+ *
+ * Creates a mutual exclusion primitive in the unlocked state.
+ *
+ * \b Throws: An exception in case if the operating system is unable to create the primitive (e.g. due to insufficient resources).
+ */
+ mutex();
+
+ /*!
+ * \brief Destructor
+ *
+ * Destroys the mutual exclusion primitive.
+ *
+ * \pre The primitive is in the unlocked state.
+ */
+ ~mutex();
+
+ mutex(mutex const&) = delete;
+ mutex& operator= (mutex const&) = delete;
+
+ /*!
+ * \brief Locks the mutex
+ *
+ * If the mutex is not locked, the method locks it and returns. Otherwise the method blocks until the mutex is unlocked.
+ *
+ * \b Throws: An exception in case if the operating system is unable to fulfill the request.
+ */
+ void lock();
+
+ /*!
+ * \brief Attempts to lock the mutex
+ *
+ * If the mutex is not locked, the method locks it and returns \c true. Otherwise the method returns \c false.
+ *
+ * \b Throws: An exception in case if the operating system is unable to fulfill the request.
+ */
+ bool try_lock();
+
+ /*!
+ * \brief Unlocks the mutex
+ *
+ * Releases the mutex that has been locked by the current thread.
+ *
+ * \pre The mutex is locked by the current thread.
+ */
+ void unlock() noexcept;
+
+ /*!
+ * \brief Returns a handle that represents a native operating system primitive that implements the mutex
+ *
+ * \note This method is only available if \c BOOST_SYNC_DEFINES_MUTEX_NATIVE_HANDLE macro is defined by the library.
+ */
+ native_handle_type native_handle() noexcept;
+};
+
+} // namespace sync
+
+} // namespace boost
+
+#else // defined(BOOST_SYNC_DETAIL_DOXYGEN)
+
+#include <boost/sync/detail/config.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+#if defined(BOOST_SYNC_DETAIL_PLATFORM_PTHREAD)
+#include <boost/sync/detail/posix/mutexes/mutex.hpp>
+#elif defined(BOOST_SYNC_DETAIL_PLATFORM_WINAPI)
+#include <boost/sync/detail/windows/mutexes/mutex.hpp>
+#else
+#error Boost.Sync: Unsupported threading API
+#endif
+
+#endif // defined(BOOST_SYNC_DETAIL_DOXYGEN)
+
+#endif // BOOST_SYNC_MUTEXES_MUTEX_HPP_INCLUDED_

Added: trunk/boost/sync/mutexes/timed_mutex.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/sync/mutexes/timed_mutex.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -0,0 +1,118 @@
+/*
+ * 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 2013 Andrey Semashev
+ */
+/*!
+ * \file sync/mutexes/timed_mutex.hpp
+ *
+ * \brief This header defines a mutex primitive with support for timed operations.
+ */
+
+#ifndef BOOST_SYNC_MUTEXES_TIMED_MUTEX_HPP_INCLUDED_
+#define BOOST_SYNC_MUTEXES_TIMED_MUTEX_HPP_INCLUDED_
+
+#if defined(BOOST_SYNC_DETAIL_DOXYGEN)
+
+namespace boost {
+
+namespace sync {
+
+class timed_mutex
+{
+public:
+ /*!
+ * \brief Default constructor
+ *
+ * Creates a mutual exclusion primitive in the unlocked state.
+ *
+ * \b Throws: An exception in case if the operating system is unable to create the primitive (e.g. due to insufficient resources).
+ */
+ timed_mutex();
+
+ /*!
+ * \brief Destructor
+ *
+ * Destroys the mutual exclusion primitive.
+ *
+ * \pre The primitive is in the unlocked state.
+ */
+ ~timed_mutex();
+
+ timed_mutex(timed_mutex const&) = delete;
+ timed_mutex& operator= (timed_mutex const&) = delete;
+
+ /*!
+ * \brief Locks the mutex
+ *
+ * If the mutex is not locked, the method locks it and returns. Otherwise the method blocks until the mutex is unlocked.
+ *
+ * \b Throws: An exception in case if the operating system is unable to fulfill the request.
+ */
+ void lock();
+
+ /*!
+ * \brief Attempts to lock the mutex
+ *
+ * If the mutex is not locked, the method locks it and returns \c true. Otherwise the method returns \c false.
+ *
+ * \b Throws: An exception in case if the operating system is unable to fulfill the request.
+ */
+ bool try_lock();
+
+ /*!
+ * \brief Attempts to lock the mutex within the specified timeout
+ *
+ * If the mutex is not locked, the method locks it and returns \c true. Otherwise the method blocks for up to \a time timeout,
+ * which can be an absolute time point or a duration. If the operation completes successfully until the timeout expires, \c true is returned.
+ * Otherwise, returns \c false.
+ *
+ * \b Throws: An exception in case if the operating system is unable to fulfill the request.
+ *
+ * \note In order to use this method, a supplementary header must be included from boost/sync/support to enable support for particular time units.
+ */
+ template< typename Time >
+ bool timed_lock(Time time);
+
+ /*!
+ * \brief Unlocks the mutex
+ *
+ * Releases the mutex that has been locked by the current thread.
+ *
+ * \pre The mutex is locked by the current thread.
+ */
+ void unlock() noexcept;
+
+ /*!
+ * \brief Returns a handle that represents a native operating system primitive that implements the mutex
+ *
+ * \note This method is only available if \c BOOST_SYNC_DEFINES_TIMED_MUTEX_NATIVE_HANDLE macro is defined by the library.
+ */
+ native_handle_type native_handle() noexcept;
+};
+
+} // namespace sync
+
+} // namespace boost
+
+#else // defined(BOOST_SYNC_DETAIL_DOXYGEN)
+
+#include <boost/sync/detail/config.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+#if defined(BOOST_SYNC_DETAIL_PLATFORM_PTHREAD)
+#include <boost/sync/detail/posix/mutexes/timed_mutex.hpp>
+#elif defined(BOOST_SYNC_DETAIL_PLATFORM_WINAPI)
+#include <boost/sync/detail/windows/mutexes/timed_mutex.hpp>
+#else
+#error Boost.Sync: Unsupported threading API
+#endif
+
+#endif // defined(BOOST_SYNC_DETAIL_DOXYGEN)
+
+#endif // BOOST_SYNC_MUTEXES_TIMED_MUTEX_HPP_INCLUDED_

Modified: trunk/boost/sync/semaphore.hpp
==============================================================================
--- trunk/boost/sync/semaphore.hpp Sun Sep 15 09:55:24 2013 (r85675)
+++ trunk/boost/sync/semaphore.hpp 2013-09-15 11:57:21 EDT (Sun, 15 Sep 2013) (r85676)
@@ -16,6 +16,7 @@
 
 class semaphore
 {
+public:
     /**
      * \b Effects: Constructs a semaphore object. The semaphore is initialized to `initial_count`, which is expected to be non-negative.
      *
@@ -32,6 +33,9 @@
      * */
     ~semaphore();
 
+ semaphore(semaphore const&) = delete;
+ semaphore& operator= (semaphore const&) = delete;
+
     /**
      * \b Effects: Increments the semaphore count. If a thread is waiting for this semaphore, it will be unblocked.
      *


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