2
0
mirror of https://github.com/boostorg/thread.git synced 2026-02-09 11:32:12 +00:00

Thread: merge from trunk latest changes.

[SVN r82356]
This commit is contained in:
Vicente J. Botet Escriba
2013-01-04 18:40:49 +00:00
parent d07835908f
commit 67da33a182
17 changed files with 193 additions and 134 deletions

View File

@@ -66,6 +66,13 @@
#define BOOST_THREAD_DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS
#endif
#if defined BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX || defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#define BOOST_THREAD_NO_CXX11_HDR_INITIALIZER_LIST
//#elif defined __GNUC__ && (__GNUC__ < 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ <= 6 ))
//#define BOOST_THREAD_NO_CXX11_HDR_INITIALIZER_LIST
#endif
/// BASIC_THREAD_ID
// todo to be removed for 1.54
#if ! defined BOOST_THREAD_DONT_PROVIDE_BASIC_THREAD_ID \

View File

@@ -6,7 +6,9 @@
#ifndef BOOST_THREAD_DETAIL_LOCKABLE_WRAPPER_HPP
#define BOOST_THREAD_DETAIL_LOCKABLE_WRAPPER_HPP
#if ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#include <boost/thread/detail/config.hpp>
#if ! defined BOOST_THREAD_NO_CXX11_HDR_INITIALIZER_LIST
#include <initializer_list>
#endif
#include <boost/config/abi_prefix.hpp>
@@ -14,7 +16,7 @@
namespace boost
{
#if ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#if ! defined BOOST_THREAD_NO_CXX11_HDR_INITIALIZER_LIST
namespace thread_detail
{
template <typename Mutex>

View File

@@ -4,12 +4,15 @@
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_HPP
#define BOOST_THREAD_EXTERNALLY_LOCKED_HPP
#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_STREAM_HPP
#define BOOST_THREAD_EXTERNALLY_LOCKED_STREAM_HPP
#include <boost/thread/detail/config.hpp>
#include <boost/thread/detail/move.hpp>
#include <boost/thread/detail/delete.hpp>
#include <boost/thread/externally_locked.hpp>
#include <boost/thread/lock_traits.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/config/abi_prefix.hpp>
@@ -17,11 +20,11 @@
namespace boost
{
static recursive_mutex& terminal_mutex()
{
static recursive-mutex mtx;
return mtx;
}
// inline static recursive_mutex& terminal_mutex()
// {
// static recursive_mutex mtx;
// return mtx;
// }
template <typename Stream>
class externally_locked_stream;
@@ -29,36 +32,47 @@ namespace boost
template <class Stream>
class stream_guard
{
stream_guard(externally_locked_stream<Stream>& mtx, adopt_lock_t)
: mtx_(mtx)
stream_guard(externally_locked_stream<Stream>& mtx, adopt_lock_t) :
mtx_(mtx)
{
}
Stream& get() const
{
mtx_.get(*this);
}
friend class externally_locked_stream<Stream>;
friend class externally_locked_stream<Stream> ;
public:
typedef typename externally_locked_stream<Stream>::mutex_type mutex_type;
BOOST_THREAD_NO_COPYABLE( externally_locked_stream )
BOOST_THREAD_MOVABLE_ONLY( stream_guard)
stream_guard(externally_locked_stream<Stream>& mtx)
: mtx_(mtx)
stream_guard(externally_locked_stream<Stream>& mtx) :
mtx_(&mtx)
{
mtx.lock();
}
~stream_guard()
stream_guard(BOOST_THREAD_RV_REF(stream_guard) rhs)
: mtx_(rhs.mtx_)
{
mtx_.unlock();
rhs.mtx_= 0;
}
~stream_guard()
{
if (mtx_ != 0) mtx_->unlock();
}
bool owns_lock(mutex_type const* l) const BOOST_NOEXCEPT
{
return l == mtx_->mutex();
}
Stream& get() const
{
return mtx_->get(*this);
}
private:
externally_locked_stream<Stream>& mtx_;
externally_locked_stream<Stream>* mtx_;
};
template <typename Stream>
@@ -78,6 +92,8 @@ namespace boost
{
typedef externally_locked<Stream&, recursive_mutex> base_type;
public:
BOOST_THREAD_NO_COPYABLE( externally_locked_stream)
/**
* Effects: Constructs an externally locked object storing the cloaked reference object.
*/
@@ -86,60 +102,57 @@ namespace boost
{
}
stream_guard<Stream> hold()
{
return stream_guard<Stream>(*this);
return stream_guard<Stream> (*this);
}
};
//]
//]
template <typename Stream, typename T>
const stream_guard<Stream>& operator<<(const stream_guard<Stream>& lck, T arg)
inline const stream_guard<Stream>& operator<<(const stream_guard<Stream>& lck, T arg)
{
lck.get() << arg;
return lck;
lck.get() << arg;
return lck;
}
template <typename Stream>
const stream_guard<Stream>& operator<<(const stream_guard<Stream>& lck,
Stream& (*arg)(Stream&))
inline const stream_guard<Stream>& operator<<(const stream_guard<Stream>& lck, Stream& (*arg)(Stream&))
{
lck.get() << arg;
return lck;
lck.get() << arg;
return lck;
}
template <typename Stream, typename T>
const stream_guard<Stream>& operator>>(const stream_guard<Stream>& lck, T& arg)
inline const stream_guard<Stream>& operator>>(const stream_guard<Stream>& lck, T& arg)
{
lck.get() >> arg;
return lck;
lck.get() >> arg;
return lck;
}
template <typename Stream, typename T>
stream_guard<Stream> operator<<(externally_locked_stream<Stream>& mtx, T arg)
inline stream_guard<Stream> operator<<(externally_locked_stream<Stream>& mtx, T arg)
{
mtx.lock();
mtx.get() << arg;
return stream_guard<Stream>(mtx, adopt_lock);
stream_guard<Stream> lk(mtx);
mtx.get(lk) << arg;
return boost::move(lk);
}
template <typename Stream>
stream_guard<Stream> operator<<(externally_locked_stream<Stream>& mtx,
Stream& (*arg)(Stream&))
inline stream_guard<Stream> operator<<(externally_locked_stream<Stream>& mtx, Stream& (*arg)(Stream&))
{
mtx.lock();
mtx.get() << arg;
return stream_guard<Stream>(mtx, adopt_lock);
stream_guard<Stream> lk(mtx);
mtx.get(lk) << arg;
return boost::move(lk);
}
template <typename Stream, typename T>
stream_guard<Stream> operator>>(externally_locked_stream<Stream>& mtx, T& arg)
inline stream_guard<Stream> operator>>(externally_locked_stream<Stream>& mtx, T& arg)
{
mtx.lock();
mtx.get() >> arg;
return stream_guard<Stream>(mtx, adopt_lock);
stream_guard<Stream> lk(mtx);
mtx.get(lk) >> arg;
return boost::move(lk);
}
}

View File

@@ -59,7 +59,7 @@ namespace boost
);
}
template <typename L1, typename L2, typename L3>
std::tuple<unique_lock<L1>, unique_lock<L2>, unique_lock<L3> > make_unique_locks(L1& m1, L2& m2, L2& m3)
std::tuple<unique_lock<L1>, unique_lock<L2>, unique_lock<L3> > make_unique_locks(L1& m1, L2& m2, L3& m3)
{
boost::lock(m1, m2, m3);
return std::tuple<unique_lock<L1>,unique_lock<L2>,unique_lock<L3> >(

View File

@@ -7,6 +7,7 @@
#ifndef BOOST_THREAD_LOCK_GUARD_HPP
#define BOOST_THREAD_LOCK_GUARD_HPP
#include <boost/thread/detail/config.hpp>
#include <boost/thread/detail/delete.hpp>
#include <boost/thread/detail/move.hpp>
#include <boost/thread/detail/lockable_wrapper.hpp>
@@ -45,7 +46,7 @@ namespace boost
#endif
}
#if ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#if ! defined BOOST_THREAD_NO_CXX11_HDR_INITIALIZER_LIST
lock_guard(std::initializer_list<thread_detail::lockable_wrapper<Mutex> > l_) :
m(*(const_cast<thread_detail::lockable_wrapper<Mutex>*>(l_.begin())->m))
{
@@ -68,7 +69,7 @@ namespace boost
};
#if ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#if ! defined BOOST_THREAD_NO_CXX11_HDR_INITIALIZER_LIST
template <typename Lockable>
lock_guard<Lockable> make_lock_guard(Lockable& mtx)
{

View File

@@ -6,6 +6,7 @@
#ifndef BOOST_THREAD_STRICT_LOCK_HPP
#define BOOST_THREAD_STRICT_LOCK_HPP
#include <boost/thread/detail/config.hpp>
#include <boost/thread/detail/delete.hpp>
#include <boost/thread/detail/lockable_wrapper.hpp>
#include <boost/thread/lock_options.hpp>
@@ -50,7 +51,7 @@ namespace boost
} /*< locks on construction >*/
#if ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#if ! defined BOOST_THREAD_NO_CXX11_HDR_INITIALIZER_LIST
strict_lock(std::initializer_list<thread_detail::lockable_wrapper<Lockable> > l_) :
mtx_(*(const_cast<thread_detail::lockable_wrapper<Lockable>*>(l_.begin())->m))
{
@@ -148,7 +149,7 @@ namespace boost
tmp_lk_ = move(lk); /*< Move ownership to temporary lk >*/
}
#if ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#if ! defined BOOST_THREAD_NO_CXX11_HDR_INITIALIZER_LIST
nested_strict_lock(std::initializer_list<thread_detail::lockable_wrapper<Lock> > l_) :
lk_(*(const_cast<thread_detail::lockable_wrapper<Lock>*>(l_.begin())->m))
{
@@ -203,7 +204,7 @@ public:
{
};
#if ! defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#if ! defined BOOST_THREAD_NO_CXX11_HDR_INITIALIZER_LIST
template <typename Lockable>
strict_lock<Lockable> make_strict_lock(Lockable& mtx)
{