|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62134 - in sandbox/chrono/boost/thread: . detail pthread win32
From: vicente.botet_at_[hidden]
Date: 2010-05-21 20:35:47
Author: viboes
Date: 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
New Revision: 62134
URL: http://svn.boost.org/trac/boost/changeset/62134
Log:
Boost.Chrono 0.5:
* Add Boost.Thread using Boost.Chrono
Text files modified:
sandbox/chrono/boost/thread/condition_variable.hpp | 1
sandbox/chrono/boost/thread/detail/thread.hpp | 93 ++++++++++-------
sandbox/chrono/boost/thread/future.hpp | 208 ++++++++++++++++++++++++++-------------
sandbox/chrono/boost/thread/locks.hpp | 143 ++++++++++++++++++---------
sandbox/chrono/boost/thread/pthread/condition_variable.hpp | 45 +++++++-
sandbox/chrono/boost/thread/pthread/condition_variable_fwd.hpp | 36 ++++++
sandbox/chrono/boost/thread/pthread/mutex.hpp | 12 ++
sandbox/chrono/boost/thread/pthread/recursive_mutex.hpp | 32 ++++-
sandbox/chrono/boost/thread/pthread/shared_mutex.hpp | 60 +++++++++--
sandbox/chrono/boost/thread/win32/basic_recursive_mutex.hpp | 23 +++
sandbox/chrono/boost/thread/win32/basic_timed_mutex.hpp | 31 ++++-
sandbox/chrono/boost/thread/win32/condition_variable.hpp | 110 ++++++++++++++++----
sandbox/chrono/boost/thread/win32/shared_mutex.hpp | 62 ++++++++---
13 files changed, 611 insertions(+), 245 deletions(-)
Modified: sandbox/chrono/boost/thread/condition_variable.hpp
==============================================================================
--- sandbox/chrono/boost/thread/condition_variable.hpp (original)
+++ sandbox/chrono/boost/thread/condition_variable.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -10,6 +10,7 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/thread/detail/platform.hpp>
+#include <boost/thread/detail/cv_status.hpp>
#if defined(BOOST_THREAD_PLATFORM_WIN32)
#include <boost/thread/win32/condition_variable.hpp>
#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
Modified: sandbox/chrono/boost/thread/detail/thread.hpp
==============================================================================
--- sandbox/chrono/boost/thread/detail/thread.hpp (original)
+++ sandbox/chrono/boost/thread/detail/thread.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -4,7 +4,7 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// (C) Copyright 2007-8 Anthony Williams
-
+
#include <boost/thread/exceptions.hpp>
#include <ostream>
#include <boost/thread/detail/move.hpp>
@@ -22,6 +22,11 @@
#include <memory>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/remove_reference.hpp>
+#include <boost/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
+
+
#include <boost/config/abi_prefix.hpp>
@@ -53,7 +58,7 @@
thread_data(detail::thread_move_t<F> f_):
f(f_)
{}
-#endif
+#endif
void run()
{
f();
@@ -78,7 +83,7 @@
thread_data(boost::reference_wrapper<F> f_):
f(f_)
{}
-
+
void run()
{
f();
@@ -97,14 +102,14 @@
thread_data(const boost::reference_wrapper<F> f_):
f(f_)
{}
-
+
void run()
{
f();
}
};
}
-
+
class BOOST_THREAD_DECL thread
{
private:
@@ -112,12 +117,12 @@
thread& operator=(thread&);
void release_handle();
-
+
mutable boost::mutex thread_info_mutex;
detail::thread_data_ptr thread_info;
void start_thread();
-
+
explicit thread(detail::thread_data_ptr data);
detail::thread_data_ptr get_thread_info() const;
@@ -147,9 +152,9 @@
#endif
struct dummy;
public:
-#ifdef __SUNPRO_CC
- thread(const volatile thread&);
-#endif
+#ifdef __SUNPRO_CC
+ thread(const volatile thread&);
+#endif
thread();
~thread();
@@ -174,7 +179,7 @@
{
thread_info.swap(other.thread_info);
}
-
+
thread& operator=(thread&& other)
{
thread_info=other.thread_info;
@@ -186,7 +191,7 @@
{
return static_cast<thread&&>(*this);
}
-
+
#else
#ifdef BOOST_NO_SFINAE
template <class F>
@@ -203,7 +208,7 @@
start_thread();
}
#endif
-
+
template <class F>
explicit thread(detail::thread_move_t<F> f):
thread_info(make_thread_info(f))
@@ -216,13 +221,13 @@
thread_info=x->thread_info;
x->thread_info.reset();
}
-
-#ifdef __SUNPRO_CC
- thread& operator=(thread x)
- {
- swap(x);
- return *this;
- }
+
+#ifdef __SUNPRO_CC
+ thread& operator=(thread x)
+ {
+ swap(x);
+ return *this;
+ }
#else
thread& operator=(detail::thread_move_t<thread> x)
{
@@ -230,12 +235,12 @@
swap(new_thread);
return *this;
}
-#endif
+#endif
operator detail::thread_move_t<thread>()
{
return move();
}
-
+
detail::thread_move_t<thread> move()
{
detail::thread_move_t<thread> x(*this);
@@ -339,12 +344,13 @@
{
this_thread::yield();
}
-
+
static inline void sleep(const system_time& xt)
{
this_thread::sleep(xt);
}
+
// extensions
void interrupt();
bool interruption_requested() const;
@@ -354,7 +360,7 @@
{
return lhs.swap(rhs);
}
-
+
#ifndef BOOST_NO_RVALUE_REFERENCES
inline thread&& move(thread& t)
{
@@ -383,13 +389,22 @@
{
sleep(system_time(abs_time));
}
+ template <class Clock, class Duration>
+ void sleep_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ sleep(convert_to<system_time>(abs_time));
+ }
+ template <class Rep, class Period>
+ void sleep_for(const chrono::duration<Rep, Period>& rel_time) {
+ sleep(convert_to<posix_time::time_duration>(rel_time));
+ }
+
}
class thread::id
{
private:
detail::thread_data_ptr thread_data;
-
+
id(detail::thread_data_ptr thread_data_):
thread_data(thread_data_)
{}
@@ -399,39 +414,39 @@
id():
thread_data()
{}
-
+
bool operator==(const id& y) const
{
return thread_data==y.thread_data;
}
-
+
bool operator!=(const id& y) const
{
return thread_data!=y.thread_data;
}
-
+
bool operator<(const id& y) const
{
return thread_data<y.thread_data;
}
-
+
bool operator>(const id& y) const
{
return y.thread_data<thread_data;
}
-
+
bool operator<=(const id& y) const
{
return !(y.thread_data<thread_data);
}
-
+
bool operator>=(const id& y) const
{
return !(thread_data<y.thread_data);
}
template<class charT, class traits>
- friend std::basic_ostream<charT, traits>&
+ friend std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const id& x)
{
if(x.thread_data)
@@ -449,12 +464,12 @@
{
return get_id()==other.get_id();
}
-
+
inline bool thread::operator!=(const thread& other) const
{
return get_id()!=other.get_id();
}
-
+
namespace detail
{
struct thread_exit_function_base
@@ -463,26 +478,26 @@
{}
virtual void operator()()=0;
};
-
+
template<typename F>
struct thread_exit_function:
thread_exit_function_base
{
F f;
-
+
thread_exit_function(F f_):
f(f_)
{}
-
+
void operator()()
{
f();
}
};
-
+
void BOOST_THREAD_DECL add_thread_exit_function(thread_exit_function_base*);
}
-
+
namespace this_thread
{
template<typename F>
Modified: sandbox/chrono/boost/thread/future.hpp
==============================================================================
--- sandbox/chrono/boost/thread/future.hpp (original)
+++ sandbox/chrono/boost/thread/future.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -1,4 +1,4 @@
-// (C) Copyright 2008-10 Anthony Williams
+// (C) Copyright 2008-10 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -27,8 +27,36 @@
#include <boost/next_prior.hpp>
#include <vector>
+#include <boost/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
+
+#ifndef BOOST_ENUM_CLASS
+#if defined(BOOST_NO_SCOPED_ENUMS)
+#define BOOST_ENUM_CLASS(T) T::type
+#else
+#define BOOST_ENUM_CLASS(T) T
+#endif
+#endif
+
namespace boost
{
+#if defined(BOOST_NO_SCOPED_ENUMS)
+ namespace future_status {
+ enum type {
+ ready,
+ timeout,
+ deferred
+ };
+ }
+#else
+ enum class future_status {
+ ready,
+ timeout,
+ deferred
+ };
+#endif
+
class future_uninitialized:
public std::logic_error
{
@@ -109,7 +137,7 @@
do_callback(lock);
return external_waiters.insert(external_waiters.end(),&cv);
}
-
+
void remove_external_waiter(waiter_list::iterator it)
{
boost::lock_guard<boost::mutex> lock(mutex);
@@ -130,7 +158,7 @@
struct relocker
{
boost::unique_lock<boost::mutex>& lock;
-
+
relocker(boost::unique_lock<boost::mutex>& lock_):
lock(lock_)
{
@@ -151,7 +179,7 @@
local_callback();
}
}
-
+
void wait(bool rethrow=true)
{
@@ -181,7 +209,21 @@
}
return true;
}
-
+
+ template <class Rep, class Period>
+ BOOST_ENUM_CLASS(future_status) wait_for(const chrono::duration<Rep, Period>& rel_time) {
+ return (timed_wait_until(convert_to<posix_time::time_duration>(rel_time)))
+ ? future_status::timeout
+ : future_status::ready;
+ }
+
+ template <class Clock, class Duration>
+ BOOST_ENUM_CLASS(future_status) wait_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return (timed_wait_until(convert_to<system_time>(abs_time)))
+ ? future_status::timeout
+ : future_status::ready;
+ }
+
void mark_exceptional_finish_internal(boost::exception_ptr const& e)
{
exception=e;
@@ -209,7 +251,7 @@
{
callback=boost::bind(f,boost::ref(*u));
}
-
+
private:
future_object_base(future_object_base const&);
future_object_base& operator=(future_object_base const&);
@@ -234,7 +276,7 @@
{
storage.reset(new T(t));
}
-
+
static void init(storage_type& storage,rvalue_source_type t)
{
storage.reset(new T(static_cast<rvalue_source_type>(t)));
@@ -245,7 +287,7 @@
storage.reset();
}
};
-
+
template<typename T>
struct future_traits<T&>
{
@@ -292,7 +334,7 @@
typedef typename future_traits<T>::source_reference_type source_reference_type;
typedef typename future_traits<T>::rvalue_source_type rvalue_source_type;
typedef typename future_traits<T>::move_dest_type move_dest_type;
-
+
storage_type result;
future_object():
@@ -367,7 +409,7 @@
{
wait();
}
-
+
future_state::state get_state()
{
boost::lock_guard<boost::mutex> guard(mutex);
@@ -401,13 +443,13 @@
{}
};
-
+
struct all_futures_lock
{
typedef std::vector<registered_waiter>::size_type count_type;
count_type count;
boost::scoped_array<boost::unique_lock<boost::mutex> > locks;
-
+
all_futures_lock(std::vector<registered_waiter>& futures):
count(futures.size()),locks(new boost::unique_lock<boost::mutex>[count])
{
@@ -416,12 +458,12 @@
locks[i]=boost::unique_lock<boost::mutex>(futures[i].future->mutex);
}
}
-
+
void lock()
{
boost::lock(locks.get(),locks.get()+count);
}
-
+
void unlock()
{
for(unsigned i=0;i<count;++i)
@@ -430,16 +472,16 @@
}
}
};
-
+
boost::condition_variable_any cv;
std::vector<registered_waiter> futures;
unsigned future_count;
-
+
public:
future_waiter():
future_count(0)
{}
-
+
template<typename F>
void add(F& f)
{
@@ -465,7 +507,7 @@
cv.wait(lk);
}
}
-
+
~future_waiter()
{
for(unsigned i=0;i<futures.size();++i)
@@ -473,9 +515,9 @@
futures[i].future->remove_external_waiter(futures[i].wait_iterator);
}
}
-
+
};
-
+
}
template <typename R>
@@ -489,13 +531,13 @@
{
BOOST_STATIC_CONSTANT(bool, value=false);
};
-
+
template<typename T>
struct is_future_type<unique_future<T> >
{
BOOST_STATIC_CONSTANT(bool, value=true);
};
-
+
template<typename T>
struct is_future_type<shared_future<T> >
{
@@ -525,7 +567,7 @@
f2.wait();
f3.wait();
}
-
+
template<typename F1,typename F2,typename F3,typename F4>
void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4)
{
@@ -574,7 +616,7 @@
waiter.add(f3);
return waiter.wait();
}
-
+
template<typename F1,typename F2,typename F3,typename F4>
unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4)
{
@@ -597,7 +639,7 @@
waiter.add(f5);
return waiter.wait();
}
-
+
template <typename R>
class promise;
@@ -611,7 +653,7 @@
unique_future& operator=(unique_future& rhs);// = delete;
typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
-
+
future_ptr future;
friend class shared_future<R>;
@@ -630,7 +672,7 @@
unique_future()
{}
-
+
~unique_future()
{}
@@ -680,7 +722,7 @@
return future->get();
}
-
+
// functions to check state, and wait for ready
state get_state() const
{
@@ -690,23 +732,23 @@
}
return future->get_state();
}
-
+
bool is_ready() const
{
return get_state()==future_state::ready;
}
-
+
bool has_exception() const
{
return future && future->has_exception();
}
-
+
bool has_value() const
{
return future && future->has_value();
}
-
+
void wait() const
{
if(!future)
@@ -715,13 +757,13 @@
}
future->wait(false);
}
-
+
template<typename Duration>
bool timed_wait(Duration const& rel_time) const
{
return timed_wait_until(boost::get_system_time()+rel_time);
}
-
+
bool timed_wait_until(boost::system_time const& abs_time) const
{
if(!future)
@@ -730,14 +772,27 @@
}
return future->timed_wait_until(abs_time);
}
-
+ template <class Rep, class Period>
+ BOOST_ENUM_CLASS(future_status) wait_for(const chrono::duration<Rep, Period>& rel_time) {
+ return (timed_wait(convert_to<posix_time::time_duration>(rel_time)))
+ ? future_status::timeout
+ : future_status::ready;
+ }
+
+ template <class Clock, class Duration>
+ BOOST_ENUM_CLASS(future_status) wait_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return (timed_wait_until(convert_to<system_time>(abs_time)))
+ ? future_status::timeout
+ : future_status::ready;
+ }
+
};
template <typename R>
class shared_future
{
typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
-
+
future_ptr future;
// shared_future(const unique_future<R>& other);
@@ -746,7 +801,7 @@
friend class detail::future_waiter;
friend class promise<R>;
friend class packaged_task<R>;
-
+
shared_future(future_ptr future_):
future(future_)
{}
@@ -790,7 +845,7 @@
other.future.reset();
return *this;
}
-#else
+#else
shared_future(boost::detail::thread_move_t<shared_future> other):
future(other->future)
{
@@ -837,7 +892,7 @@
return future->get();
}
-
+
// functions to check state, and wait for ready
state get_state() const
{
@@ -847,18 +902,18 @@
}
return future->get_state();
}
-
+
bool is_ready() const
{
return get_state()==future_state::ready;
}
-
+
bool has_exception() const
{
return future && future->has_exception();
}
-
+
bool has_value() const
{
return future && future->has_value();
@@ -872,13 +927,13 @@
}
future->wait(false);
}
-
+
template<typename Duration>
bool timed_wait(Duration const& rel_time) const
{
return timed_wait_until(boost::get_system_time()+rel_time);
}
-
+
bool timed_wait_until(boost::system_time const& abs_time) const
{
if(!future)
@@ -887,17 +942,30 @@
}
return future->timed_wait_until(abs_time);
}
-
+ template <class Rep, class Period>
+ BOOST_ENUM_CLASS(future_status) wait_for(const chrono::duration<Rep, Period>& rel_time) {
+ return (timed_wait(convert_to<posix_time::time_duration>(rel_time)))
+ ? future_status::timeout
+ : future_status::ready;
+ }
+
+ template <class Clock, class Duration>
+ BOOST_ENUM_CLASS(future_status) wait_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return (timed_wait_until(convert_to<system_time>(abs_time)))
+ ? future_status::timeout
+ : future_status::ready;
+ }
+
};
template <typename R>
class promise
{
typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
-
+
future_ptr future;
bool future_obtained;
-
+
promise(promise & rhs);// = delete;
promise & operator=(promise & rhs);// = delete;
@@ -909,14 +977,14 @@
future.reset(new detail::future_object<R>);
}
}
-
+
public:
// template <class Allocator> explicit promise(Allocator a);
promise():
future(),future_obtained(false)
{}
-
+
~promise()
{
if(future)
@@ -962,8 +1030,8 @@
{
return boost::detail::thread_move_t<promise>(*this);
}
-#endif
-
+#endif
+
void swap(promise& other)
{
future.swap(other.future);
@@ -1022,17 +1090,17 @@
lazy_init();
future->set_wait_callback(f,this);
}
-
+
};
template <>
class promise<void>
{
typedef boost::shared_ptr<detail::future_object<void> > future_ptr;
-
+
future_ptr future;
bool future_obtained;
-
+
promise(promise & rhs);// = delete;
promise & operator=(promise & rhs);// = delete;
@@ -1050,7 +1118,7 @@
promise():
future(),future_obtained(false)
{}
-
+
~promise()
{
if(future)
@@ -1097,7 +1165,7 @@
return boost::detail::thread_move_t<promise>(*this);
}
#endif
-
+
void swap(promise& other)
{
future.swap(other.future);
@@ -1108,7 +1176,7 @@
unique_future<void> get_future()
{
lazy_init();
-
+
if(future_obtained)
{
boost::throw_exception(future_already_retrieved());
@@ -1145,7 +1213,7 @@
lazy_init();
future->set_wait_callback(f,this);
}
-
+
};
namespace detail
@@ -1182,12 +1250,12 @@
this->mark_exceptional_finish_internal(boost::copy_exception(boost::broken_promise()));
}
}
-
-
+
+
virtual void do_run()=0;
};
-
-
+
+
template<typename R,typename F>
struct task_object:
task_base<R>
@@ -1199,7 +1267,7 @@
task_object(boost::detail::thread_move_t<F> f_):
f(f_)
{}
-
+
void do_run()
{
try
@@ -1224,7 +1292,7 @@
task_object(boost::detail::thread_move_t<F> f_):
f(f_)
{}
-
+
void do_run()
{
try
@@ -1240,7 +1308,7 @@
};
}
-
+
template<typename R>
class packaged_task
@@ -1250,12 +1318,12 @@
packaged_task(packaged_task&);// = delete;
packaged_task& operator=(packaged_task&);// = delete;
-
+
public:
packaged_task():
future_obtained(false)
{}
-
+
// construction and destruction
template <class F>
explicit packaged_task(F const& f):
@@ -1264,7 +1332,7 @@
explicit packaged_task(R(*f)()):
task(new detail::task_object<R,R(*)()>(f)),future_obtained(false)
{}
-
+
template <class F>
explicit packaged_task(boost::detail::thread_move_t<F> f):
task(new detail::task_object<R,F>(f)),future_obtained(false)
@@ -1340,7 +1408,7 @@
boost::throw_exception(future_already_retrieved());
}
}
-
+
// execution
void operator()()
@@ -1357,7 +1425,7 @@
{
task->set_wait_callback(f,this);
}
-
+
};
}
Modified: sandbox/chrono/boost/thread/locks.hpp
==============================================================================
--- sandbox/chrono/boost/thread/locks.hpp (original)
+++ sandbox/chrono/boost/thread/locks.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -12,10 +12,15 @@
#include <boost/thread/thread_time.hpp>
#include <boost/detail/workaround.hpp>
+#include <boost/chrono/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
+
#include <boost/config/abi_prefix.hpp>
namespace boost
{
+
struct xtime;
#if defined(BOOST_NO_SFINAE) || \
@@ -35,11 +40,11 @@
{
true_type dummy[2];
};
-
+
template<typename U>
static true_type has_member(U*,void (U::*dummy)()=&U::lock);
static false_type has_member(void*);
-
+
BOOST_STATIC_CONSTANT(bool, value=sizeof(has_member_lock<T>::has_member((T*)NULL))==sizeof(true_type));
};
@@ -51,14 +56,14 @@
{
true_type dummy[2];
};
-
+
template<typename U>
static true_type has_member(U*,void (U::*dummy)()=&U::unlock);
static false_type has_member(void*);
-
+
BOOST_STATIC_CONSTANT(bool, value=sizeof(has_member_unlock<T>::has_member((T*)NULL))==sizeof(true_type));
};
-
+
template<typename T>
struct has_member_try_lock
{
@@ -67,16 +72,16 @@
{
true_type dummy[2];
};
-
+
template<typename U>
static true_type has_member(U*,bool (U::*dummy)()=&U::try_lock);
static false_type has_member(void*);
-
+
BOOST_STATIC_CONSTANT(bool, value=sizeof(has_member_try_lock<T>::has_member((T*)NULL))==sizeof(true_type));
};
}
-
+
template<typename T>
struct is_mutex_type
@@ -84,7 +89,7 @@
BOOST_STATIC_CONSTANT(bool, value = detail::has_member_lock<T>::value &&
detail::has_member_unlock<T>::value &&
detail::has_member_try_lock<T>::value);
-
+
};
#else
template<typename T>
@@ -92,7 +97,7 @@
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
-#endif
+#endif
struct defer_lock_t
{};
@@ -100,7 +105,7 @@
{};
struct adopt_lock_t
{};
-
+
const defer_lock_t defer_lock={};
const try_to_lock_t try_to_lock={};
const adopt_lock_t adopt_lock={};
@@ -119,7 +124,7 @@
template<typename Mutex>
class try_lock_wrapper;
}
-
+
#ifdef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES
template<typename T>
struct is_mutex_type<unique_lock<T> >
@@ -138,7 +143,7 @@
{
BOOST_STATIC_CONSTANT(bool, value = true);
};
-
+
template<typename T>
struct is_mutex_type<detail::try_lock_wrapper<T> >
{
@@ -150,7 +155,7 @@
class recursive_mutex;
class recursive_timed_mutex;
class shared_mutex;
-
+
template<>
struct is_mutex_type<mutex>
{
@@ -214,13 +219,13 @@
unique_lock& operator=(unique_lock&);
unique_lock& operator=(upgrade_lock<Mutex>& other);
public:
-#ifdef __SUNPRO_CC
- unique_lock(const volatile unique_lock&);
+#ifdef __SUNPRO_CC
+ unique_lock(const volatile unique_lock&);
#endif
unique_lock():
m(0),is_locked(false)
{}
-
+
explicit unique_lock(Mutex& m_):
m(&m_),is_locked(false)
{
@@ -248,6 +253,19 @@
{
timed_lock(target_time);
}
+ template <class Clock, class Duration>
+ unique_lock(Mutex& m_, chrono::time_point<Clock, Duration> const & abs_time) :
+ m(&m_),is_locked(false)
+ {
+ timed_lock(convert_to<system_time>(abs_time));
+ }
+ template <class Rep, class Period>
+ unique_lock(Mutex& m_, const chrono::duration<Rep, Period>& rel_time) :
+ m(&m_),is_locked(false)
+ {
+ timed_lock(convert_to<posix_time::time_duration>(rel_time));
+ }
+
#ifndef BOOST_NO_RVALUE_REFERENCES
unique_lock(unique_lock&& other):
m(other.m),is_locked(other.is_locked)
@@ -301,11 +319,11 @@
}
#ifdef __SUNPRO_CC
- unique_lock& operator=(unique_lock<Mutex> other)
- {
- swap(other);
- return *this;
- }
+ unique_lock& operator=(unique_lock<Mutex> other)
+ {
+ swap(other);
+ return *this;
+ }
#else
unique_lock& operator=(detail::thread_move_t<unique_lock<Mutex> > other)
{
@@ -332,7 +350,7 @@
std::swap(m,other.m);
std::swap(is_locked,other.is_locked);
}
-
+
~unique_lock()
{
if(owns_lock())
@@ -364,7 +382,7 @@
is_locked=m->timed_lock(relative_time);
return is_locked;
}
-
+
bool timed_lock(::boost::system_time const& absolute_time)
{
is_locked=m->timed_lock(absolute_time);
@@ -375,6 +393,14 @@
is_locked=m->timed_lock(absolute_time);
return is_locked;
}
+ template <class Rep, class Period>
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time) {
+ return timed_lock(convert_to<posix_time::time_duration>(rel_time));
+ }
+ template <class Clock, class Duration>
+ bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return timed_lock(convert_to<system_time>(abs_time));
+ }
void unlock()
{
if(!owns_lock())
@@ -384,7 +410,7 @@
m->unlock();
is_locked=false;
}
-
+
typedef void (unique_lock::*bool_type)();
operator bool_type() const
{
@@ -456,7 +482,7 @@
shared_lock():
m(0),is_locked(false)
{}
-
+
explicit shared_lock(Mutex& m_):
m(&m_),is_locked(false)
{
@@ -478,6 +504,18 @@
{
timed_lock(target_time);
}
+ template <class Clock, class Duration>
+ shared_lock(Mutex& m_, const chrono::time_point<Clock, Duration>& abs_time) :
+ m(&m_),is_locked(false)
+ {
+ timed_lock(convert_to<system_time>(abs_time));
+ }
+ template <class Rep, class Period>
+ shared_lock(Mutex& m_, const chrono::duration<Rep, Period>& rel_time) :
+ m(&m_),is_locked(false)
+ {
+ timed_lock(get_system_time()+convert_to<posix_time::time_duration>(rel_time));
+ }
shared_lock(detail::thread_move_t<shared_lock<Mutex> > other):
m(other->m),is_locked(other->is_locked)
@@ -563,7 +601,7 @@
{
return m;
}
-
+
~shared_lock()
{
if(owns_lock())
@@ -608,6 +646,15 @@
is_locked=m->timed_lock_shared(target_time);
return is_locked;
}
+ template <class Rep, class Period>
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time) {
+ return timed_lock(convert_to<posix_time::time_duration>(rel_time));
+ }
+ template <class Clock, class Duration>
+ bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return timed_lock(convert_to<system_time>(abs_time));
+ }
+
void unlock()
{
if(!owns_lock())
@@ -617,7 +664,7 @@
m->unlock_shared();
is_locked=false;
}
-
+
typedef void (shared_lock<Mutex>::*bool_type)();
operator bool_type() const
{
@@ -661,7 +708,7 @@
upgrade_lock():
m(0),is_locked(false)
{}
-
+
explicit upgrade_lock(Mutex& m_):
m(&m_),is_locked(false)
{
@@ -726,7 +773,7 @@
std::swap(m,other.m);
std::swap(is_locked,other.is_locked);
}
-
+
~upgrade_lock()
{
if(owns_lock())
@@ -761,7 +808,7 @@
m->unlock_upgrade();
is_locked=false;
}
-
+
typedef void (upgrade_lock::*bool_type)();
operator bool_type() const
{
@@ -829,7 +876,7 @@
{
other->source=0;
}
-
+
upgrade_to_unique_lock& operator=(detail::thread_move_t<upgrade_to_unique_lock<Mutex> > other)
{
upgrade_to_unique_lock temp(other);
@@ -866,7 +913,7 @@
public:
try_lock_wrapper()
{}
-
+
explicit try_lock_wrapper(Mutex& m):
base(m,try_to_lock)
{}
@@ -981,7 +1028,7 @@
lhs.swap(rhs);
}
#endif
-
+
template<typename MutexType1,typename MutexType2>
unsigned try_lock_internal(MutexType1& m1,MutexType2& m2)
{
@@ -1110,7 +1157,7 @@
template<bool x>
struct is_mutex_type_wrapper
{};
-
+
template<typename MutexType1,typename MutexType2>
void lock_impl(MutexType1& m1,MutexType2& m2,is_mutex_type_wrapper<true>)
{
@@ -1138,7 +1185,7 @@
template<typename Iterator>
void lock_impl(Iterator begin,Iterator end,is_mutex_type_wrapper<false>);
}
-
+
template<typename MutexType1,typename MutexType2>
void lock(MutexType1& m1,MutexType2& m2)
@@ -1283,7 +1330,7 @@
{
typedef int type;
};
-
+
template<typename Iterator>
struct try_lock_impl_return<Iterator,false>
{
@@ -1299,7 +1346,7 @@
template<typename Iterator>
Iterator try_lock_impl(Iterator begin,Iterator end,is_mutex_type_wrapper<false>);
}
-
+
template<typename MutexType1,typename MutexType2>
typename detail::try_lock_impl_return<MutexType1>::type try_lock(MutexType1& m1,MutexType2& m2)
{
@@ -1341,7 +1388,7 @@
{
return ((int)detail::try_lock_internal(m1,m2,m3,m4,m5))-1;
}
-
+
namespace detail
{
@@ -1350,13 +1397,13 @@
{
Iterator begin;
Iterator end;
-
+
range_lock_guard(Iterator begin_,Iterator end_):
begin(begin_),end(end_)
{
lock(begin,end);
}
-
+
void release()
{
begin=end;
@@ -1381,7 +1428,7 @@
}
typedef typename std::iterator_traits<Iterator>::value_type lock_type;
unique_lock<lock_type> guard(*begin,try_to_lock);
-
+
if(!guard.owns_lock())
{
return begin;
@@ -1391,11 +1438,11 @@
{
guard.release();
}
-
+
return failed;
}
}
-
+
namespace detail
{
@@ -1403,7 +1450,7 @@
void lock_impl(Iterator begin,Iterator end,is_mutex_type_wrapper<false>)
{
typedef typename std::iterator_traits<Iterator>::value_type lock_type;
-
+
if(begin==end)
{
return;
@@ -1412,7 +1459,7 @@
Iterator second=begin;
++second;
Iterator next=second;
-
+
for(;;)
{
unique_lock<lock_type> begin_lock(*begin,defer_lock);
@@ -1451,9 +1498,9 @@
}
}
}
-
+
}
-
+
}
#include <boost/config/abi_suffix.hpp>
Modified: sandbox/chrono/boost/thread/pthread/condition_variable.hpp
==============================================================================
--- sandbox/chrono/boost/thread/pthread/condition_variable.hpp (original)
+++ sandbox/chrono/boost/thread/pthread/condition_variable.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -10,6 +10,10 @@
#include "thread_data.hpp"
#include "condition_variable_fwd.hpp"
+#include <boost/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
+
#include <boost/config/abi_prefix.hpp>
namespace boost
@@ -37,19 +41,19 @@
{
BOOST_VERIFY(!pthread_cond_signal(&cond));
}
-
+
inline void condition_variable::notify_all()
{
BOOST_VERIFY(!pthread_cond_broadcast(&cond));
}
-
+
class condition_variable_any
{
pthread_mutex_t internal_mutex;
pthread_cond_t cond;
- condition_variable_any(condition_variable&);
- condition_variable_any& operator=(condition_variable&);
+ condition_variable_any(condition_variable_any&);
+ condition_variable_any& operator=(condition_variable_any&);
public:
condition_variable_any()
@@ -71,7 +75,7 @@
BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
BOOST_VERIFY(!pthread_cond_destroy(&cond));
}
-
+
template<typename lock_type>
void wait(lock_type& m)
{
@@ -96,7 +100,7 @@
{
while(!pred()) wait(m);
}
-
+
template<typename lock_type>
bool timed_wait(lock_type& m,boost::system_time const& wait_until)
{
@@ -156,12 +160,39 @@
return timed_wait(m,get_system_time()+wait_duration,pred);
}
+ template <typename lock_type,class Clock, class Duration>
+ BOOST_ENUM_CLASS(cv_status) wait_until(lock_type& lock,
+ const chrono::time_point<Clock, Duration>& abs_time) {
+ return (timed_wait(lock, convert_to<system_time>(abs_time)))
+ ? cv_status::timeout
+ : cv_status::no_timeout;
+ }
+ template <typename lock_type,class Clock, class Duration, class Predicate>
+ bool wait_until(lock_type& lock,
+ const chrono::time_point<Clock, Duration>& abs_time,
+ Predicate pred) {
+ return timed_wait(lock, convert_to<system_time>(abs_time), pred);
+ }
+ template <typename lock_type,class Rep, class Period>
+ BOOST_ENUM_CLASS(cv_status) wait_for(lock_type& lock,
+ const chrono::duration<Rep, Period>& rel_time) {
+ return (timed_wait(lock, convert_to<posix_time::time_duration>(rel_time)))
+ ? cv_status::timeout
+ : cv_status::no_timeout;
+ }
+ template <typename lock_type,class Rep, class Period, class Predicate>
+ bool wait_for(lock_type& lock,
+ const chrono::duration<Rep, Period>& rel_time,
+ Predicate pred) {
+ return timed_wait(lock, convert_to<posix_time::time_duration>(rel_time), pred);
+ }
+
void notify_one()
{
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
BOOST_VERIFY(!pthread_cond_signal(&cond));
}
-
+
void notify_all()
{
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
Modified: sandbox/chrono/boost/thread/pthread/condition_variable_fwd.hpp
==============================================================================
--- sandbox/chrono/boost/thread/pthread/condition_variable_fwd.hpp (original)
+++ sandbox/chrono/boost/thread/pthread/condition_variable_fwd.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -5,6 +5,8 @@
// http://www.boost.org/LICENSE_1_0.txt)
// (C) Copyright 2007-8 Anthony Williams
+#include <boost/config.hpp>
+
#include <boost/assert.hpp>
#include <boost/throw_exception.hpp>
#include <pthread.h>
@@ -13,6 +15,11 @@
#include <boost/thread/thread_time.hpp>
#include <boost/thread/xtime.hpp>
+#include <boost/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
+#include <boost/thread/detail/cv_status.hpp>
+
#include <boost/config/abi_prefix.hpp>
namespace boost
@@ -21,7 +28,7 @@
{
private:
pthread_cond_t cond;
-
+
condition_variable(condition_variable&);
condition_variable& operator=(condition_variable&);
@@ -82,6 +89,33 @@
return timed_wait(m,get_system_time()+wait_duration,pred);
}
+ template <class Clock, class Duration>
+ BOOST_ENUM_CLASS(cv_status) wait_until(unique_lock<mutex>& lock,
+ const chrono::time_point<Clock, Duration>& abs_time) {
+ return (timed_wait(lock, convert_to<system_time>(abs_time)))
+ ? cv_status::timeout
+ : cv_status::no_timeout;
+ }
+ template <class Clock, class Duration, class Predicate>
+ bool wait_until(unique_lock<mutex>& lock,
+ const chrono::time_point<Clock, Duration>& abs_time,
+ Predicate pred) {
+ return timed_wait(lock, convert_to<system_time>(abs_time), pred);
+ }
+ template <class Rep, class Period>
+ BOOST_ENUM_CLASS(cv_status) wait_for(unique_lock<mutex>& lock,
+ const chrono::duration<Rep, Period>& rel_time) {
+ return (timed_wait(lock, convert_to<posix_time::time_duration>(rel_time)))
+ ? cv_status::timeout
+ : cv_status::no_timeout;
+ }
+ template <class Rep, class Period, class Predicate>
+ bool wait_for(unique_lock<mutex>& lock,
+ const chrono::duration<Rep, Period>& rel_time,
+ Predicate pred) {
+ return timed_wait(lock, convert_to<posix_time::time_duration>(rel_time), pred);
+ }
+
typedef pthread_cond_t* native_handle_type;
native_handle_type native_handle()
{
Modified: sandbox/chrono/boost/thread/pthread/mutex.hpp
==============================================================================
--- sandbox/chrono/boost/thread/pthread/mutex.hpp (original)
+++ sandbox/chrono/boost/thread/pthread/mutex.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -23,6 +23,10 @@
#endif
#endif
+#include <boost/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
+
#include <boost/config/abi_prefix.hpp>
namespace boost
@@ -119,6 +123,14 @@
{
return timed_lock(system_time(absolute_time));
}
+ template <class Rep, class Period>
+ bool try_lock_for(chrono::duration<Rep, Period> const & rel_time) {
+ return timed_lock(convert_to<posix_time::time_duration>(rel_time));
+ }
+ template <class Clock, class Duration>
+ bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return timed_lock(convert_to<system_time>(abs_time));
+ }
#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
void lock()
Modified: sandbox/chrono/boost/thread/pthread/recursive_mutex.hpp
==============================================================================
--- sandbox/chrono/boost/thread/pthread/recursive_mutex.hpp (original)
+++ sandbox/chrono/boost/thread/pthread/recursive_mutex.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -26,6 +26,10 @@
#endif
#endif
+#include <boost/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
+
#include <boost/config/abi_prefix.hpp>
namespace boost
@@ -39,7 +43,7 @@
recursive_mutex()
{
pthread_mutexattr_t attr;
-
+
int const init_attr_res=pthread_mutexattr_init(&attr);
if(init_attr_res)
{
@@ -50,7 +54,7 @@
{
boost::throw_exception(thread_resource_error());
}
-
+
int const res=pthread_mutex_init(&m,&attr);
if(res)
{
@@ -62,7 +66,7 @@
{
BOOST_VERIFY(!pthread_mutex_destroy(&m));
}
-
+
void lock()
{
BOOST_VERIFY(!pthread_mutex_lock(&m));
@@ -72,7 +76,7 @@
{
BOOST_VERIFY(!pthread_mutex_unlock(&m));
}
-
+
bool try_lock()
{
int const res=pthread_mutex_trylock(&m);
@@ -108,7 +112,7 @@
{
#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
pthread_mutexattr_t attr;
-
+
int const init_attr_res=pthread_mutexattr_init(&attr);
if(init_attr_res)
{
@@ -119,7 +123,7 @@
{
boost::throw_exception(thread_resource_error());
}
-
+
int const res=pthread_mutex_init(&m,&attr);
if(res)
{
@@ -157,6 +161,16 @@
return timed_lock(get_system_time()+relative_time);
}
+ template <class Rep, class Period>
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time) {
+ return timed_lock(convert_to<posix_time::time_duration>(rel_time));
+ }
+
+ template <class Clock, class Duration>
+ bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return timed_lock(convert_to<system_time>(abs_time));
+ }
+
#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
void lock()
{
@@ -167,7 +181,7 @@
{
BOOST_VERIFY(!pthread_mutex_unlock(&m));
}
-
+
bool try_lock()
{
int const res=pthread_mutex_trylock(&m);
@@ -197,7 +211,7 @@
++count;
return;
}
-
+
while(is_locked)
{
BOOST_VERIFY(!pthread_cond_wait(&cond,&m));
@@ -216,7 +230,7 @@
}
BOOST_VERIFY(!pthread_cond_signal(&cond));
}
-
+
bool try_lock()
{
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
Modified: sandbox/chrono/boost/thread/pthread/shared_mutex.hpp
==============================================================================
--- sandbox/chrono/boost/thread/pthread/shared_mutex.hpp (original)
+++ sandbox/chrono/boost/thread/pthread/shared_mutex.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -13,6 +13,10 @@
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/detail/thread_interruption.hpp>
+#include <boost/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
+
#include <boost/config/abi_prefix.hpp>
namespace boost
@@ -27,7 +31,7 @@
bool upgrade;
bool exclusive_waiting_blocked;
};
-
+
state_data state;
@@ -41,7 +45,7 @@
exclusive_cond.notify_one();
shared_cond.notify_all();
}
-
+
public:
shared_mutex()
@@ -58,7 +62,7 @@
{
boost::this_thread::disable_interruption do_not_disturb;
boost::mutex::scoped_lock lk(state_change);
-
+
while(state.exclusive || state.exclusive_waiting_blocked)
{
shared_cond.wait(lk);
@@ -69,7 +73,7 @@
bool try_lock_shared()
{
boost::mutex::scoped_lock lk(state_change);
-
+
if(state.exclusive || state.exclusive_waiting_blocked)
{
return false;
@@ -85,7 +89,7 @@
{
boost::this_thread::disable_interruption do_not_disturb;
boost::mutex::scoped_lock lk(state_change);
-
+
while(state.exclusive || state.exclusive_waiting_blocked)
{
if(!shared_cond.timed_wait(lk,timeout))
@@ -103,11 +107,21 @@
return timed_lock_shared(get_system_time()+relative_time);
}
+ template <class Rep, class Period>
+ bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time) {
+ return timed_lock_shared(convert_to<posix_time::time_duration>(rel_time));
+ }
+
+ template <class Clock, class Duration>
+ bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return timed_lock_shared(convert_to<system_time>(abs_time));
+ }
+
void unlock_shared()
{
boost::mutex::scoped_lock lk(state_change);
bool const last_reader=!--state.shared_count;
-
+
if(last_reader)
{
if(state.upgrade)
@@ -128,7 +142,7 @@
{
boost::this_thread::disable_interruption do_not_disturb;
boost::mutex::scoped_lock lk(state_change);
-
+
while(state.shared_count || state.exclusive)
{
state.exclusive_waiting_blocked=true;
@@ -165,11 +179,21 @@
{
return timed_lock(get_system_time()+relative_time);
}
+
+ template <class Rep, class Period>
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time) {
+ return timed_lock(convert_to<posix_time::time_duration>(rel_time));
+ }
+
+ template <class Clock, class Duration>
+ bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return timed_lock(convert_to<system_time>(abs_time));
+ }
bool try_lock()
{
boost::mutex::scoped_lock lk(state_change);
-
+
if(state.shared_count || state.exclusive)
{
return false;
@@ -179,7 +203,7 @@
state.exclusive=true;
return true;
}
-
+
}
void unlock()
@@ -225,7 +249,17 @@
template<typename TimeDuration>
bool timed_lock_upgrade(TimeDuration const & relative_time)
{
- return timed_lock(get_system_time()+relative_time);
+ return timed_lock_upgrade(get_system_time()+relative_time);
+ }
+
+ template <class Rep, class Period>
+ bool try_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time) {
+ return timed_lock_upgrade(convert_to<posix_time::time_duration>(rel_time));
+ }
+
+ template <class Clock, class Duration>
+ bool try_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return timed_lock_upgrade(convert_to<system_time>(abs_time));
}
bool try_lock_upgrade()
@@ -248,7 +282,7 @@
boost::mutex::scoped_lock lk(state_change);
state.upgrade=false;
bool const last_reader=!--state.shared_count;
-
+
if(last_reader)
{
state.exclusive_waiting_blocked=false;
@@ -278,7 +312,7 @@
state.exclusive_waiting_blocked=false;
release_waiters();
}
-
+
void unlock_and_lock_shared()
{
boost::mutex::scoped_lock lk(state_change);
@@ -287,7 +321,7 @@
state.exclusive_waiting_blocked=false;
release_waiters();
}
-
+
void unlock_upgrade_and_lock_shared()
{
boost::mutex::scoped_lock lk(state_change);
Modified: sandbox/chrono/boost/thread/win32/basic_recursive_mutex.hpp
==============================================================================
--- sandbox/chrono/boost/thread/win32/basic_recursive_mutex.hpp (original)
+++ sandbox/chrono/boost/thread/win32/basic_recursive_mutex.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -3,7 +3,7 @@
// basic_recursive_mutex.hpp
//
-// (C) Copyright 2006-8 Anthony Williams
+// (C) Copyright 2006-8 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -12,6 +12,9 @@
#include "thread_primitives.hpp"
#include "basic_timed_mutex.hpp"
+#include <boost/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost
@@ -42,7 +45,7 @@
long const current_thread_id=win32::GetCurrentThreadId();
return try_recursive_lock(current_thread_id) || try_basic_lock(current_thread_id);
}
-
+
void lock()
{
long const current_thread_id=win32::GetCurrentThreadId();
@@ -64,6 +67,16 @@
return timed_lock(get_system_time()+timeout);
}
+ template <class Rep, class Period>
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time) {
+ return timed_lock(convert_to<posix_time::time_duration>(rel_time));
+ }
+
+ template <class Clock, class Duration>
+ bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return timed_lock(convert_to<system_time>(abs_time));
+ }
+
void unlock()
{
if(!--recursion_count)
@@ -83,7 +96,7 @@
}
return false;
}
-
+
bool try_basic_lock(long current_thread_id)
{
if(mutex.try_lock())
@@ -94,7 +107,7 @@
}
return false;
}
-
+
bool try_timed_lock(long current_thread_id,::boost::system_time const& target)
{
if(mutex.timed_lock(target))
@@ -105,7 +118,7 @@
}
return false;
}
-
+
};
typedef basic_recursive_mutex_impl<basic_timed_mutex> basic_recursive_mutex;
Modified: sandbox/chrono/boost/thread/win32/basic_timed_mutex.hpp
==============================================================================
--- sandbox/chrono/boost/thread/win32/basic_timed_mutex.hpp (original)
+++ sandbox/chrono/boost/thread/win32/basic_timed_mutex.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -3,7 +3,7 @@
// basic_timed_mutex_win32.hpp
//
-// (C) Copyright 2006-8 Anthony Williams
+// (C) Copyright 2006-8 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -16,6 +16,9 @@
#include <boost/thread/xtime.hpp>
#include <boost/detail/interlocked.hpp>
+#include <boost/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost
@@ -52,13 +55,13 @@
win32::CloseHandle(old_event);
}
}
-
-
+
+
bool try_lock()
{
return !win32::interlocked_bit_test_and_set(&active_count,lock_flag_bit);
}
-
+
void lock()
{
if(try_lock())
@@ -112,8 +115,8 @@
old_count=current;
}
}
-
-
+
+
bool timed_lock(::boost::system_time const& wait_until)
{
if(try_lock())
@@ -154,6 +157,16 @@
return timed_lock(system_time(timeout));
}
+ template <class Rep, class Period>
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time) {
+ return timed_lock(convert_to<posix_time::time_duration>(rel_time));
+ }
+
+ template <class Clock, class Duration>
+ bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return timed_lock(convert_to<system_time>(abs_time));
+ }
+
void unlock()
{
long const offset=lock_flag_value;
@@ -171,7 +184,7 @@
void* get_event()
{
void* current_event=::boost::detail::interlocked_read_acquire(&event);
-
+
if(!current_event)
{
void* const new_event=win32::create_anonymous_event(win32::auto_reset_event,win32::event_initially_reset);
@@ -196,9 +209,9 @@
}
return current_event;
}
-
+
};
-
+
}
}
Modified: sandbox/chrono/boost/thread/win32/condition_variable.hpp
==============================================================================
--- sandbox/chrono/boost/thread/win32/condition_variable.hpp (original)
+++ sandbox/chrono/boost/thread/win32/condition_variable.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -17,6 +17,9 @@
#include <vector>
#include <boost/intrusive_ptr.hpp>
+#include <boost/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost
@@ -26,7 +29,7 @@
class basic_cv_list_entry;
void intrusive_ptr_add_ref(basic_cv_list_entry * p);
void intrusive_ptr_release(basic_cv_list_entry * p);
-
+
class basic_cv_list_entry
{
private:
@@ -38,7 +41,7 @@
basic_cv_list_entry(basic_cv_list_entry&);
void operator=(basic_cv_list_entry&);
-
+
public:
explicit basic_cv_list_entry(detail::win32::handle_manager const& wake_sem_):
semaphore(detail::win32::create_anonymous_semaphore(0,LONG_MAX)),
@@ -55,7 +58,7 @@
{
BOOST_INTERLOCKED_INCREMENT(&waiters);
}
-
+
void remove_waiter()
{
BOOST_INTERLOCKED_DECREMENT(&waiters);
@@ -97,7 +100,7 @@
{
BOOST_INTERLOCKED_INCREMENT(&p->references);
}
-
+
inline void intrusive_ptr_release(basic_cv_list_entry * p)
{
if(!BOOST_INTERLOCKED_DECREMENT(&p->references))
@@ -125,13 +128,13 @@
detail::interlocked_write_release(&total_count,total_count-count_to_wake);
detail::win32::ReleaseSemaphore(wake_sem,count_to_wake,0);
}
-
+
template<typename lock_type>
struct relocker
{
lock_type& lock;
bool unlocked;
-
+
relocker(lock_type& lock_):
lock(lock_),unlocked(false)
{}
@@ -146,13 +149,13 @@
{
lock.lock();
}
-
+
}
private:
relocker(relocker&);
void operator=(relocker&);
};
-
+
entry_ptr get_wait_entry()
{
@@ -177,15 +180,15 @@
return generations.back();
}
}
-
+
struct entry_manager
{
entry_ptr const entry;
-
+
entry_manager(entry_ptr const& entry_):
entry(entry_)
{}
-
+
~entry_manager()
{
entry->remove_waiter();
@@ -200,14 +203,14 @@
void operator=(entry_manager&);
entry_manager(entry_manager&);
};
-
+
protected:
template<typename lock_type>
bool do_wait(lock_type& lock,timeout wait_until)
{
relocker<lock_type> locker(lock);
-
+
entry_manager entry(get_wait_entry());
locker.unlock();
@@ -219,7 +222,7 @@
{
return false;
}
-
+
woken=entry->woken();
}
return woken;
@@ -235,7 +238,7 @@
}
return true;
}
-
+
basic_condition_variable(const basic_condition_variable& other);
basic_condition_variable& operator=(const basic_condition_variable& other);
@@ -243,7 +246,7 @@
basic_condition_variable():
total_count(0),active_generation_count(0),wake_sem(0)
{}
-
+
~basic_condition_variable()
{}
@@ -267,7 +270,7 @@
generations.erase(std::remove_if(generations.begin(),generations.end(),&basic_cv_list_entry::no_waiters),generations.end());
}
}
-
+
void notify_all()
{
if(detail::interlocked_read_acquire(&total_count))
@@ -288,7 +291,7 @@
wake_sem=detail::win32::handle(0);
}
}
-
+
};
}
@@ -301,10 +304,10 @@
public:
condition_variable()
{}
-
+
using detail::basic_condition_variable::notify_one;
using detail::basic_condition_variable::notify_all;
-
+
void wait(unique_lock<mutex>& m)
{
do_wait(m,detail::timeout::sentinel());
@@ -315,7 +318,7 @@
{
while(!pred()) wait(m);
}
-
+
bool timed_wait(unique_lock<mutex>& m,boost::system_time const& wait_until)
{
@@ -347,8 +350,35 @@
{
return do_wait(m,wait_duration.total_milliseconds(),pred);
}
+
+ template <class Clock, class Duration>
+ BOOST_ENUM_CLASS(cv_status) wait_until(unique_lock<mutex>& lock,
+ const chrono::time_point<Clock, Duration>& abs_time) {
+ return (timed_wait(lock, convert_to<system_time>(abs_time)))
+ ? cv_status::timeout
+ : cv_status::no_timeout;
+ }
+ template <class Clock, class Duration, class Predicate>
+ bool wait_until(unique_lock<mutex>& lock,
+ const chrono::time_point<Clock, Duration>& abs_time,
+ Predicate pred) {
+ return timed_wait(lock, convert_to<system_time>(abs_time), pred);
+ }
+ template <class Rep, class Period>
+ BOOST_ENUM_CLASS(cv_status) wait_for(unique_lock<mutex>& lock,
+ const chrono::duration<Rep, Period>& rel_time) {
+ return (timed_wait(lock, convert_to<posix_time::time_duration>(rel_time)))
+ ? cv_status::timeout
+ : cv_status::no_timeout;
+ }
+ template <class Rep, class Period, class Predicate>
+ bool wait_for(unique_lock<mutex>& lock,
+ const chrono::duration<Rep, Period>& rel_time,
+ Predicate pred) {
+ return timed_wait(lock, convert_to<posix_time::time_duration>(rel_time), pred);
+ }
};
-
+
class condition_variable_any:
private detail::basic_condition_variable
{
@@ -358,10 +388,10 @@
public:
condition_variable_any()
{}
-
+
using detail::basic_condition_variable::notify_one;
using detail::basic_condition_variable::notify_all;
-
+
template<typename lock_type>
void wait(lock_type& m)
{
@@ -373,7 +403,7 @@
{
while(!pred()) wait(m);
}
-
+
template<typename lock_type>
bool timed_wait(lock_type& m,boost::system_time const& wait_until)
{
@@ -409,6 +439,36 @@
{
return do_wait(m,wait_duration.total_milliseconds(),pred);
}
+
+ template <typename lock_type,class Clock, class Duration>
+ BOOST_ENUM_CLASS(cv_status) wait_until(lock_type& lock,
+ const chrono::time_point<Clock, Duration>& abs_time) {
+ return (timed_wait(lock, convert_to<system_time>(abs_time)))
+ ? cv_status::timeout
+ : cv_status::no_timeout;
+ }
+
+ template <typename lock_type,class Clock, class Duration, class Predicate>
+ bool wait_until(lock_type& lock,
+ const chrono::time_point<Clock, Duration>& abs_time,
+ Predicate pred) {
+ return timed_wait(lock, convert_to<system_time>(abs_time), pred);
+ }
+
+ template <typename lock_type,class Rep, class Period>
+ BOOST_ENUM_CLASS(cv_status) wait_for(lock_type& lock,
+ const chrono::duration<Rep, Period>& rel_time) {
+ return (timed_wait(lock, convert_to<posix_time::time_duration>(rel_time)))
+ ? cv_status::timeout
+ : cv_status::no_timeout;
+ }
+
+ template <typename lock_type,class Rep, class Period, class Predicate>
+ bool wait_for(lock_type& lock,
+ const chrono::duration<Rep, Period>& rel_time,
+ Predicate pred) {
+ return timed_wait(lock, convert_to<posix_time::time_duration>(rel_time), pred);
+ }
};
}
Modified: sandbox/chrono/boost/thread/win32/shared_mutex.hpp
==============================================================================
--- sandbox/chrono/boost/thread/win32/shared_mutex.hpp (original)
+++ sandbox/chrono/boost/thread/win32/shared_mutex.hpp 2010-05-21 20:35:45 EDT (Fri, 21 May 2010)
@@ -15,6 +15,10 @@
#include <boost/utility.hpp>
#include <boost/thread/thread_time.hpp>
+#include <boost/chrono.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
+
#include <boost/config/abi_prefix.hpp>
namespace boost
@@ -37,7 +41,7 @@
return *reinterpret_cast<unsigned const*>(&lhs)==*reinterpret_cast<unsigned const*>(&rhs);
}
};
-
+
template<typename T>
T interlocked_compare_exchange(T* target,T new_value,T comparand)
@@ -61,18 +65,18 @@
{
BOOST_VERIFY(detail::win32::ReleaseSemaphore(exclusive_sem,1,0)!=0);
}
-
+
if(old_state.shared_waiting || old_state.exclusive_waiting)
{
BOOST_VERIFY(detail::win32::ReleaseSemaphore(unlock_sem,old_state.shared_waiting + (old_state.exclusive_waiting?1:0),0)!=0);
}
}
-
+
public:
shared_mutex():
unlock_sem(semaphores[0]),
- exclusive_sem(semaphores[1])
+ exclusive_sem(semaphores[1])
{
unlock_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX);
exclusive_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX);
@@ -98,7 +102,7 @@
{
++new_state.shared_count;
}
-
+
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
if(current_state==old_state)
{
@@ -149,7 +153,7 @@
{
return true;
}
-
+
unsigned long const res=detail::win32::WaitForSingleObject(unlock_sem,::boost::detail::get_milliseconds_until(wait_until));
if(res==detail::win32::timeout)
{
@@ -182,11 +186,21 @@
}
return false;
}
-
+
BOOST_ASSERT(res==0);
}
}
+ template <class Rep, class Period>
+ bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time) {
+ return timed_lock_shared(convert_to<posix_time::time_duration>(rel_time));
+ }
+
+ template <class Clock, class Duration>
+ bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return timed_lock_shared(convert_to<system_time>(abs_time));
+ }
+
void unlock_shared()
{
state_data old_state=state;
@@ -194,7 +208,7 @@
{
state_data new_state=old_state;
bool const last_reader=!--new_state.shared_count;
-
+
if(last_reader)
{
if(new_state.upgrade)
@@ -212,7 +226,7 @@
new_state.shared_waiting=0;
}
}
-
+
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
if(current_state==old_state)
{
@@ -258,7 +272,7 @@
{
new_state.exclusive=true;
}
-
+
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
if(current_state==old_state)
{
@@ -339,6 +353,16 @@
}
}
+ template <class Rep, class Period>
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time) {
+ return timed_lock(convert_to<posix_time::time_duration>(rel_time));
+ }
+
+ template <class Clock, class Duration>
+ bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time) {
+ return timed_lock(convert_to<system_time>(abs_time));
+ }
+
void unlock()
{
state_data old_state=state;
@@ -393,7 +417,7 @@
{
return;
}
-
+
BOOST_VERIFY(!detail::win32::WaitForSingleObject(unlock_sem,detail::win32::infinite));
}
}
@@ -413,7 +437,7 @@
++new_state.shared_count;
new_state.upgrade=true;
}
-
+
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
if(current_state==old_state)
{
@@ -432,7 +456,7 @@
state_data new_state=old_state;
new_state.upgrade=false;
bool const last_reader=!--new_state.shared_count;
-
+
if(last_reader)
{
if(new_state.exclusive_waiting)
@@ -442,7 +466,7 @@
}
new_state.shared_waiting=0;
}
-
+
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
if(current_state==old_state)
{
@@ -463,13 +487,13 @@
{
state_data new_state=old_state;
bool const last_reader=!--new_state.shared_count;
-
+
if(last_reader)
{
new_state.upgrade=false;
new_state.exclusive=true;
}
-
+
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
if(current_state==old_state)
{
@@ -508,7 +532,7 @@
}
release_waiters(old_state);
}
-
+
void unlock_and_lock_shared()
{
state_data old_state=state;
@@ -533,7 +557,7 @@
}
release_waiters(old_state);
}
-
+
void unlock_upgrade_and_lock_shared()
{
state_data old_state=state;
@@ -557,7 +581,7 @@
}
release_waiters(old_state);
}
-
+
};
}
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