mirror of
https://github.com/boostorg/thread.git
synced 2026-02-03 09:42:16 +00:00
Compare commits
223 Commits
boost-1.43
...
svn-branch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a181539c6 | ||
|
|
f6b8cdd1f5 | ||
|
|
6727013302 | ||
|
|
cda12a2660 | ||
|
|
c3c2072472 | ||
|
|
bfc226fdc0 | ||
|
|
fd28e1a7fb | ||
|
|
b11911f5e5 | ||
|
|
a1587d070f | ||
|
|
df2f43bc61 | ||
|
|
895e8eea52 | ||
|
|
97d6249f3b | ||
|
|
7a8ed98eb5 | ||
|
|
d611eece19 | ||
|
|
a99320f5a4 | ||
|
|
c97484943a | ||
|
|
547d9bd844 | ||
|
|
1a65aab05a | ||
|
|
2e869aeb86 | ||
|
|
d729776575 | ||
|
|
895c436405 | ||
|
|
4ae2932792 | ||
|
|
a52be2bdbb | ||
|
|
31c4792216 | ||
|
|
39fd9c0b47 | ||
|
|
9c25df3402 | ||
|
|
fb150b5038 | ||
|
|
8cff3a167e | ||
|
|
2be1431f60 | ||
|
|
255b7ed7f6 | ||
|
|
58fd27399e | ||
|
|
5f88ba1e47 | ||
|
|
ab569461d8 | ||
|
|
7093fc670b | ||
|
|
6f2b030253 | ||
|
|
0e61e679af | ||
|
|
b40998e1b5 | ||
|
|
174d701bc3 | ||
|
|
f2143d08b9 | ||
|
|
1273e2620d | ||
|
|
c719f6e37e | ||
|
|
37922d8ce0 | ||
|
|
7b79a31f40 | ||
|
|
9a09406f77 | ||
|
|
9bdb778478 | ||
|
|
9621dafe46 | ||
|
|
d7c9837844 | ||
|
|
27bb7803ae | ||
|
|
c0e1086f2c | ||
|
|
ffa751c617 | ||
|
|
b8ad60a2d6 | ||
|
|
5db0aac816 | ||
|
|
3fae7c5184 | ||
|
|
47889a8f22 | ||
|
|
8d22c3869b | ||
|
|
235ed4afe0 | ||
|
|
627cb7f774 | ||
|
|
09021af350 | ||
|
|
31c280d1fa | ||
|
|
629f344f34 | ||
|
|
db5f924e24 | ||
|
|
9be3eb282a | ||
|
|
effd891a16 | ||
|
|
13db35cbf5 | ||
|
|
0f2d480e3c | ||
|
|
9edc61e37b | ||
|
|
f4dab6aac5 | ||
|
|
9e0550d140 | ||
|
|
0d1701c509 | ||
|
|
f2f62f93ea | ||
|
|
8a329f66fb | ||
|
|
05d4c52918 | ||
|
|
8fd0dd0cc0 | ||
|
|
8eea5811ba | ||
|
|
a154c2adab | ||
|
|
10bf4ed576 | ||
|
|
60d12dd395 | ||
|
|
b4e9be3c52 | ||
|
|
dcebae6d4a | ||
|
|
0d776bcd26 | ||
|
|
2d6ed47cf2 | ||
|
|
ea06434425 | ||
|
|
6508eff95e | ||
|
|
69930684a9 | ||
|
|
b1931a3eda | ||
|
|
63b44d4e32 | ||
|
|
f7cb8d8141 | ||
|
|
48c857e02c | ||
|
|
442dc58e0f | ||
|
|
25460c652c | ||
|
|
31a98f0a1e | ||
|
|
36c44b6f45 | ||
|
|
27426b18d1 | ||
|
|
3ea9ce1c8c | ||
|
|
4dfc636c84 | ||
|
|
5fe4312c6c | ||
|
|
63e675a6bb | ||
|
|
e92aeac7d7 | ||
|
|
f1f7eac1f2 | ||
|
|
eff0c84553 | ||
|
|
58c8ce61c7 | ||
|
|
6ac5e6953a | ||
|
|
5d9ad59af2 | ||
|
|
3c48a05437 | ||
|
|
4462124ff2 | ||
|
|
373f557ef7 | ||
|
|
495e561398 | ||
|
|
d24a579033 | ||
|
|
77130424b4 | ||
|
|
eb30688937 | ||
|
|
880bac0633 | ||
|
|
851d6a987f | ||
|
|
9bebd7b35f | ||
|
|
309acb9597 | ||
|
|
a56887167e | ||
|
|
e984dff4e4 | ||
|
|
685e4d446b | ||
|
|
8af680f307 | ||
|
|
6c60cce60d | ||
|
|
5882a675bb | ||
|
|
a5e95845b3 | ||
|
|
5b83d81e40 | ||
|
|
c8e5ad564d | ||
|
|
5edfa273ff | ||
|
|
4db57bcb10 | ||
|
|
3f13340903 | ||
|
|
6abb53c9d3 | ||
|
|
fdd20a519e | ||
|
|
67cc49f333 | ||
|
|
31a34cd0b5 | ||
|
|
ef8c08ba99 | ||
|
|
2991ca6c6f | ||
|
|
52bace18b2 | ||
|
|
767d14ae4f | ||
|
|
1a5c911e36 | ||
|
|
6e42a04e43 | ||
|
|
28be2cfeef | ||
|
|
8be168fd87 | ||
|
|
eee95fef57 | ||
|
|
9ea179b052 | ||
|
|
6868280409 | ||
|
|
e00b764454 | ||
|
|
999613c686 | ||
|
|
c2661d7eb5 | ||
|
|
4d21dd1f47 | ||
|
|
a0a0e57527 | ||
|
|
d8af0d0b4e | ||
|
|
113288e3b0 | ||
|
|
afecfd7c2d | ||
|
|
94d89aac5f | ||
|
|
8831b13efc | ||
|
|
01f99da03a | ||
|
|
080654e3ef | ||
|
|
2ac2eb2a61 | ||
|
|
61b940b705 | ||
|
|
4a4f87e017 | ||
|
|
6d5e7f63a7 | ||
|
|
f77285f375 | ||
|
|
dc5d03a6dc | ||
|
|
ea0961b7f6 | ||
|
|
33d9f9774c | ||
|
|
86097fa038 | ||
|
|
70d9dbc45a | ||
|
|
3926fd3a20 | ||
|
|
7861cf1146 | ||
|
|
0516b86a6e | ||
|
|
ec735d3e9b | ||
|
|
1c5c070983 | ||
|
|
a5c02b73dc | ||
|
|
918b920670 | ||
|
|
de67d2e27e | ||
|
|
bc89df04cb | ||
|
|
c26a4cf082 | ||
|
|
6e1a866b13 | ||
|
|
f91986ad0d | ||
|
|
795cc23f3e | ||
|
|
a3695bd4a0 | ||
|
|
08dc521daf | ||
|
|
8b916d21b1 | ||
|
|
c40f47a78a | ||
|
|
e9fb470b06 | ||
|
|
343d049772 | ||
|
|
86f9480da4 | ||
|
|
8696b610ca | ||
|
|
6f13227eda | ||
|
|
58d5110e61 | ||
|
|
76e53c7bc5 | ||
|
|
cfb08be1a8 | ||
|
|
b5bbb7fb1c | ||
|
|
a76c33f8cc | ||
|
|
810306b8f3 | ||
|
|
6c22bdb3bd | ||
|
|
6a0d3e98bc | ||
|
|
3809321037 | ||
|
|
eef695bdf0 | ||
|
|
ab01ab1e4d | ||
|
|
c8d8a108a7 | ||
|
|
7afd9efcc5 | ||
|
|
56ded87ad2 | ||
|
|
82e503339b | ||
|
|
713d0c7ace | ||
|
|
25ad6e3f8f | ||
|
|
df0197b617 | ||
|
|
a89c4f01ad | ||
|
|
ae67099633 | ||
|
|
57542d3a5c | ||
|
|
9a1da14116 | ||
|
|
ed050d753d | ||
|
|
8bec363710 | ||
|
|
7c68e190a9 | ||
|
|
7ebf5ea3d1 | ||
|
|
11e0435a4b | ||
|
|
d15ee57cd1 | ||
|
|
56d660b7fd | ||
|
|
792958e693 | ||
|
|
914e67dc04 | ||
|
|
b50a7ccb61 | ||
|
|
f827709d42 | ||
|
|
36abb42175 | ||
|
|
40f3b1b4c8 | ||
|
|
4f35e25688 | ||
|
|
270e88edd7 | ||
|
|
5ded171247 |
@@ -219,6 +219,7 @@ __thread_id__ yield a total order for every non-equal thread ID.
|
||||
};
|
||||
|
||||
void swap(thread& lhs,thread& rhs);
|
||||
detail::thread_move_t<thread> move(detail::thread_move_t<thread> t);
|
||||
|
||||
[section:default_constructor Default Constructor]
|
||||
|
||||
@@ -234,6 +235,40 @@ __thread_id__ yield a total order for every non-equal thread ID.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_constructor Move Constructor]
|
||||
|
||||
thread(detail::thread_move_t<thread> other);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Transfers ownership of the thread managed by `other` (if any) to the newly constructed __thread__ instance.]]
|
||||
|
||||
[[Postconditions:] [`other->get_id()==thread::id()`]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_assignment Move assignment operator]
|
||||
|
||||
thread& operator=(detail::thread_move_t<thread> other);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Transfers ownership of the thread managed by `other` (if
|
||||
any) to `*this`. If there was a thread previously associated with
|
||||
`*this` then that thread is detached.]]
|
||||
|
||||
[[Postconditions:] [`other->get_id()==thread::id()`]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:callable_constructor Thread Constructor]
|
||||
|
||||
template<typename Callable>
|
||||
@@ -521,6 +556,26 @@ value as `this->get_id()` prior to the call.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:non_member_move Non-member function `move()`]
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
detail::thread_move_t<thread> move(detail::thread_move_t<thread> t)
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [`t`.]]
|
||||
|
||||
]
|
||||
|
||||
Enables moving thread objects. e.g.
|
||||
|
||||
extern void some_func();
|
||||
boost::thread t(some_func);
|
||||
boost::thread t2(boost::move(t)); // transfer thread from t to t2
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:id Class `boost::thread::id`]
|
||||
|
||||
@@ -756,11 +811,14 @@ instances of __thread_id__ `a` and `b` is the same if `a==b`, and different if `
|
||||
{
|
||||
template<typename TimeDuration>
|
||||
void sleep(TimeDuration const& rel_time);
|
||||
void sleep(system_time const& abs_time)
|
||||
}
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Suspends the current thread until the specified time has elapsed.]]
|
||||
[[Effects:] [Suspends the current thread until the time period
|
||||
specified by `rel_time` has elapsed or the time point specified by
|
||||
`abs_time` has been reached.]]
|
||||
|
||||
[[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted.]]
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "platform.hpp"
|
||||
|
||||
// compatibility with the rest of Boost's auto-linking code:
|
||||
#if defined(BOOST_THREAD_DYN_DLL) || defined(BOOST_ALL_DYN_LINK)
|
||||
#if defined(BOOST_THREAD_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)
|
||||
# undef BOOST_THREAD_USE_LIB
|
||||
# define BOOST_THREAD_USE_DLL
|
||||
#endif
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
// 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-8 Anthony Williams
|
||||
// (C) Copyright 2007-10 Anthony Williams
|
||||
|
||||
#include <boost/thread/exceptions.hpp>
|
||||
#ifndef BOOST_NO_IOSTREAM
|
||||
#include <ostream>
|
||||
#endif
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
@@ -147,7 +149,7 @@ namespace boost
|
||||
#endif
|
||||
struct dummy;
|
||||
public:
|
||||
#ifdef __SUNPRO_CC
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100)
|
||||
thread(const volatile thread&);
|
||||
#endif
|
||||
thread();
|
||||
@@ -217,7 +219,7 @@ namespace boost
|
||||
x->thread_info.reset();
|
||||
}
|
||||
|
||||
#ifdef __SUNPRO_CC
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100)
|
||||
thread& operator=(thread x)
|
||||
{
|
||||
swap(x);
|
||||
@@ -394,7 +396,7 @@ namespace boost
|
||||
thread_data(thread_data_)
|
||||
{}
|
||||
friend class thread;
|
||||
friend id this_thread::get_id();
|
||||
friend id BOOST_THREAD_DECL this_thread::get_id();
|
||||
public:
|
||||
id():
|
||||
thread_data()
|
||||
@@ -430,6 +432,7 @@ namespace boost
|
||||
return !(thread_data<y.thread_data);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_IOSTREAM
|
||||
template<class charT, class traits>
|
||||
friend std::basic_ostream<charT, traits>&
|
||||
operator<<(std::basic_ostream<charT, traits>& os, const id& x)
|
||||
@@ -443,6 +446,7 @@ namespace boost
|
||||
return os<<"{Not-any-thread}";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
inline bool thread::operator==(const thread& other) const
|
||||
|
||||
@@ -18,10 +18,13 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class thread_group:
|
||||
private noncopyable
|
||||
class thread_group
|
||||
{
|
||||
private:
|
||||
thread_group(thread_group const&);
|
||||
thread_group& operator=(thread_group const&);
|
||||
public:
|
||||
thread_group() {}
|
||||
~thread_group()
|
||||
{
|
||||
for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
|
||||
|
||||
@@ -12,27 +12,9 @@
|
||||
|
||||
#if defined(BOOST_HAS_WINTHREADS)
|
||||
|
||||
typedef void (__cdecl *thread_exit_handler)(void);
|
||||
|
||||
extern "C" BOOST_THREAD_DECL int at_thread_exit(
|
||||
thread_exit_handler exit_handler
|
||||
);
|
||||
//Add a function to the list of functions that will
|
||||
//be called when a thread is about to exit.
|
||||
//Currently only implemented for Win32, but should
|
||||
//later be implemented for all platforms.
|
||||
//Used by Win32 implementation of Boost.Threads
|
||||
//tss to perform cleanup.
|
||||
//Like the C runtime library atexit() function,
|
||||
//which it mimics, at_thread_exit() returns
|
||||
//zero if successful and a nonzero
|
||||
//value if an error occurs.
|
||||
|
||||
#endif //defined(BOOST_HAS_WINTHREADS)
|
||||
|
||||
#if defined(BOOST_HAS_WINTHREADS)
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_process_enter(void);
|
||||
namespace boost
|
||||
{
|
||||
BOOST_THREAD_DECL void __cdecl on_process_enter(void);
|
||||
//Function to be called when the exe or dll
|
||||
//that uses Boost.Threads first starts
|
||||
//or is first loaded.
|
||||
@@ -42,7 +24,7 @@
|
||||
//a method for doing so has been discovered.
|
||||
//May be omitted; may be called multiple times.
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_process_exit(void);
|
||||
BOOST_THREAD_DECL void __cdecl on_process_exit(void);
|
||||
//Function to be called when the exe or dll
|
||||
//that uses Boost.Threads first starts
|
||||
//or is first loaded.
|
||||
@@ -52,7 +34,7 @@
|
||||
//a method for doing so has been discovered.
|
||||
//Must not be omitted; may be called multiple times.
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_thread_enter(void);
|
||||
BOOST_THREAD_DECL void __cdecl on_thread_enter(void);
|
||||
//Function to be called just after a thread starts
|
||||
//in an exe or dll that uses Boost.Threads.
|
||||
//Must be called in the context of the thread
|
||||
@@ -61,7 +43,7 @@
|
||||
//a method for doing so has been discovered.
|
||||
//May be omitted; may be called multiple times.
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void __cdecl on_thread_exit(void);
|
||||
BOOST_THREAD_DECL void __cdecl on_thread_exit(void);
|
||||
//Function to be called just be fore a thread ends
|
||||
//in an exe or dll that uses Boost.Threads.
|
||||
//Must be called in the context of the thread
|
||||
@@ -70,10 +52,11 @@
|
||||
//a method for doing so has been discovered.
|
||||
//Must not be omitted; may be called multiple times.
|
||||
|
||||
extern "C" void tss_cleanup_implemented(void);
|
||||
void tss_cleanup_implemented();
|
||||
//Dummy function used both to detect whether tss cleanup
|
||||
//cleanup has been implemented and to force
|
||||
//it to be linked into the Boost.Threads library.
|
||||
}
|
||||
|
||||
#endif //defined(BOOST_HAS_WINTHREADS)
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <stdexcept>
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#include <boost/thread/thread_time.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/exception_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
@@ -388,15 +390,18 @@ namespace boost
|
||||
|
||||
class future_waiter
|
||||
{
|
||||
struct registered_waiter;
|
||||
typedef std::vector<registered_waiter>::size_type count_type;
|
||||
|
||||
struct registered_waiter
|
||||
{
|
||||
boost::shared_ptr<detail::future_object_base> future;
|
||||
detail::future_object_base::waiter_list::iterator wait_iterator;
|
||||
unsigned index;
|
||||
count_type index;
|
||||
|
||||
registered_waiter(boost::shared_ptr<detail::future_object_base> const& future_,
|
||||
detail::future_object_base::waiter_list::iterator wait_iterator_,
|
||||
unsigned index_):
|
||||
count_type index_):
|
||||
future(future_),wait_iterator(wait_iterator_),index(index_)
|
||||
{}
|
||||
|
||||
@@ -404,7 +409,6 @@ namespace boost
|
||||
|
||||
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;
|
||||
|
||||
@@ -424,7 +428,7 @@ namespace boost
|
||||
|
||||
void unlock()
|
||||
{
|
||||
for(unsigned i=0;i<count;++i)
|
||||
for(count_type i=0;i<count;++i)
|
||||
{
|
||||
locks[i].unlock();
|
||||
}
|
||||
@@ -433,7 +437,7 @@ namespace boost
|
||||
|
||||
boost::condition_variable_any cv;
|
||||
std::vector<registered_waiter> futures;
|
||||
unsigned future_count;
|
||||
count_type future_count;
|
||||
|
||||
public:
|
||||
future_waiter():
|
||||
@@ -450,12 +454,12 @@ namespace boost
|
||||
++future_count;
|
||||
}
|
||||
|
||||
unsigned wait()
|
||||
count_type wait()
|
||||
{
|
||||
all_futures_lock lk(futures);
|
||||
for(;;)
|
||||
{
|
||||
for(unsigned i=0;i<futures.size();++i)
|
||||
for(count_type i=0;i<futures.size();++i)
|
||||
{
|
||||
if(futures[i].future->done)
|
||||
{
|
||||
@@ -468,7 +472,7 @@ namespace boost
|
||||
|
||||
~future_waiter()
|
||||
{
|
||||
for(unsigned i=0;i<futures.size();++i)
|
||||
for(count_type i=0;i<futures.size();++i)
|
||||
{
|
||||
futures[i].future->remove_external_waiter(futures[i].wait_iterator);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <iterator>
|
||||
#include <boost/thread/thread_time.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/type_traits/is_class.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
@@ -27,40 +28,100 @@ namespace boost
|
||||
#ifndef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES
|
||||
namespace detail
|
||||
{
|
||||
template<typename T>
|
||||
#define BOOST_DEFINE_HAS_MEMBER_CALLED(member_name) \
|
||||
template<typename T, bool=boost::is_class<T>::value> \
|
||||
struct has_member_called_##member_name \
|
||||
{ \
|
||||
BOOST_STATIC_CONSTANT(bool, value=false); \
|
||||
}; \
|
||||
\
|
||||
template<typename T> \
|
||||
struct has_member_called_##member_name<T,true> \
|
||||
{ \
|
||||
typedef char true_type; \
|
||||
struct false_type \
|
||||
{ \
|
||||
true_type dummy[2]; \
|
||||
}; \
|
||||
\
|
||||
struct fallback { int member_name; }; \
|
||||
struct derived: \
|
||||
T, fallback \
|
||||
{ \
|
||||
derived(); \
|
||||
}; \
|
||||
\
|
||||
template<int fallback::*> struct tester; \
|
||||
\
|
||||
template<typename U> \
|
||||
static false_type has_member(tester<&U::member_name>*); \
|
||||
template<typename U> \
|
||||
static true_type has_member(...); \
|
||||
\
|
||||
BOOST_STATIC_CONSTANT( \
|
||||
bool, value=sizeof(has_member<derived>(0))==sizeof(true_type)); \
|
||||
}
|
||||
|
||||
BOOST_DEFINE_HAS_MEMBER_CALLED(lock);
|
||||
BOOST_DEFINE_HAS_MEMBER_CALLED(unlock);
|
||||
BOOST_DEFINE_HAS_MEMBER_CALLED(try_lock);
|
||||
|
||||
template<typename T,bool=has_member_called_lock<T>::value >
|
||||
struct has_member_lock
|
||||
{
|
||||
typedef char true_type;
|
||||
struct false_type
|
||||
{
|
||||
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));
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct has_member_unlock
|
||||
{
|
||||
typedef char true_type;
|
||||
struct false_type
|
||||
{
|
||||
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));
|
||||
BOOST_STATIC_CONSTANT(bool, value=false);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct has_member_lock<T,true>
|
||||
{
|
||||
typedef char true_type;
|
||||
struct false_type
|
||||
{
|
||||
true_type dummy[2];
|
||||
};
|
||||
|
||||
template<typename U,typename V>
|
||||
static true_type has_member(V (U::*)());
|
||||
template<typename U>
|
||||
static false_type has_member(U);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool,value=sizeof(has_member_lock<T>::has_member(&T::lock))==sizeof(true_type));
|
||||
};
|
||||
|
||||
template<typename T,bool=has_member_called_unlock<T>::value >
|
||||
struct has_member_unlock
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value=false);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct has_member_unlock<T,true>
|
||||
{
|
||||
typedef char true_type;
|
||||
struct false_type
|
||||
{
|
||||
true_type dummy[2];
|
||||
};
|
||||
|
||||
template<typename U,typename V>
|
||||
static true_type has_member(V (U::*)());
|
||||
template<typename U>
|
||||
static false_type has_member(U);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool,value=sizeof(has_member_unlock<T>::has_member(&T::unlock))==sizeof(true_type));
|
||||
};
|
||||
|
||||
template<typename T,bool=has_member_called_try_lock<T>::value >
|
||||
struct has_member_try_lock
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value=false);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct has_member_try_lock<T,true>
|
||||
{
|
||||
typedef char true_type;
|
||||
struct false_type
|
||||
@@ -69,10 +130,12 @@ namespace boost
|
||||
};
|
||||
|
||||
template<typename U>
|
||||
static true_type has_member(U*,bool (U::*dummy)()=&U::try_lock);
|
||||
static false_type has_member(void*);
|
||||
static true_type has_member(bool (U::*)());
|
||||
template<typename U>
|
||||
static false_type has_member(U);
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, value=sizeof(has_member_try_lock<T>::has_member((T*)NULL))==sizeof(true_type));
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool,value=sizeof(has_member_try_lock<T>::has_member(&T::try_lock))==sizeof(true_type));
|
||||
};
|
||||
|
||||
}
|
||||
@@ -422,6 +485,12 @@ namespace boost
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
inline upgrade_lock<Mutex>&& move(upgrade_lock<Mutex>&& ul)
|
||||
{
|
||||
return ul;
|
||||
}
|
||||
#endif
|
||||
template<typename Mutex>
|
||||
void swap(unique_lock<Mutex>& lhs,unique_lock<Mutex>& rhs)
|
||||
@@ -678,6 +747,39 @@ namespace boost
|
||||
{
|
||||
try_lock();
|
||||
}
|
||||
#ifdef BOOST_HAS_RVALUE_REFS
|
||||
upgrade_lock(upgrade_lock<Mutex>&& other):
|
||||
m(other.m),is_locked(other.is_locked)
|
||||
{
|
||||
other.is_locked=false;
|
||||
other.m=0;
|
||||
}
|
||||
|
||||
upgrade_lock(unique_lock<Mutex>&& other):
|
||||
m(other.m),is_locked(other.is_locked)
|
||||
{
|
||||
if(is_locked)
|
||||
{
|
||||
m->unlock_and_lock_upgrade();
|
||||
}
|
||||
other.is_locked=false;
|
||||
other.m=0;
|
||||
}
|
||||
|
||||
upgrade_lock& operator=(upgrade_lock<Mutex>&& other)
|
||||
{
|
||||
upgrade_lock temp(other);
|
||||
swap(temp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
upgrade_lock& operator=(unique_lock<Mutex>&& other)
|
||||
{
|
||||
upgrade_lock temp(other);
|
||||
swap(temp);
|
||||
return *this;
|
||||
}
|
||||
#else
|
||||
upgrade_lock(detail::thread_move_t<upgrade_lock<Mutex> > other):
|
||||
m(other->m),is_locked(other->is_locked)
|
||||
{
|
||||
@@ -720,6 +822,7 @@ namespace boost
|
||||
swap(temp);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
void swap(upgrade_lock& other)
|
||||
{
|
||||
@@ -824,6 +927,20 @@ namespace boost
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BOOST_HAS_RVALUE_REFS
|
||||
upgrade_to_unique_lock(upgrade_to_unique_lock<Mutex>&& other):
|
||||
source(other.source),exclusive(move(other.exclusive))
|
||||
{
|
||||
other.source=0;
|
||||
}
|
||||
|
||||
upgrade_to_unique_lock& operator=(upgrade_to_unique_lock<Mutex>&& other)
|
||||
{
|
||||
upgrade_to_unique_lock temp(other);
|
||||
swap(temp);
|
||||
return *this;
|
||||
}
|
||||
#else
|
||||
upgrade_to_unique_lock(detail::thread_move_t<upgrade_to_unique_lock<Mutex> > other):
|
||||
source(other->source),exclusive(move(other->exclusive))
|
||||
{
|
||||
@@ -836,6 +953,7 @@ namespace boost
|
||||
swap(temp);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
void swap(upgrade_to_unique_lock& other)
|
||||
{
|
||||
std::swap(source,other.source);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// 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-8 Anthony Williams
|
||||
// (C) Copyright 2007-10 Anthony Williams
|
||||
|
||||
#include "timespec.hpp"
|
||||
#include "pthread_mutex_scoped_lock.hpp"
|
||||
@@ -48,8 +48,8 @@ namespace boost
|
||||
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()
|
||||
|
||||
@@ -47,7 +47,8 @@ namespace boost
|
||||
while(!pred()) wait(m);
|
||||
}
|
||||
|
||||
bool timed_wait(unique_lock<mutex>& m,boost::system_time const& wait_until);
|
||||
inline bool timed_wait(unique_lock<mutex>& m,
|
||||
boost::system_time const& wait_until);
|
||||
bool timed_wait(unique_lock<mutex>& m,xtime const& wait_until)
|
||||
{
|
||||
return timed_wait(m,system_time(wait_until));
|
||||
|
||||
@@ -27,10 +27,11 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class mutex:
|
||||
boost::noncopyable
|
||||
class mutex
|
||||
{
|
||||
private:
|
||||
mutex(mutex const&);
|
||||
mutex& operator=(mutex const&);
|
||||
pthread_mutex_t m;
|
||||
public:
|
||||
mutex()
|
||||
@@ -48,7 +49,11 @@ namespace boost
|
||||
|
||||
void lock()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_lock(&m));
|
||||
int const res=pthread_mutex_lock(&m);
|
||||
if(res)
|
||||
{
|
||||
boost::throw_exception(lock_error(res));
|
||||
}
|
||||
}
|
||||
|
||||
void unlock()
|
||||
@@ -59,7 +64,11 @@ namespace boost
|
||||
bool try_lock()
|
||||
{
|
||||
int const res=pthread_mutex_trylock(&m);
|
||||
BOOST_ASSERT(!res || res==EBUSY);
|
||||
if(res && (res!=EBUSY))
|
||||
{
|
||||
boost::throw_exception(lock_error(res));
|
||||
}
|
||||
|
||||
return !res;
|
||||
}
|
||||
|
||||
@@ -75,9 +84,11 @@ namespace boost
|
||||
|
||||
typedef mutex try_mutex;
|
||||
|
||||
class timed_mutex:
|
||||
boost::noncopyable
|
||||
class timed_mutex
|
||||
{
|
||||
private:
|
||||
timed_mutex(timed_mutex const&);
|
||||
timed_mutex& operator=(timed_mutex const&);
|
||||
private:
|
||||
pthread_mutex_t m;
|
||||
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
|
||||
@@ -30,10 +30,11 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class recursive_mutex:
|
||||
boost::noncopyable
|
||||
class recursive_mutex
|
||||
{
|
||||
private:
|
||||
recursive_mutex(recursive_mutex const&);
|
||||
recursive_mutex& operator=(recursive_mutex const&);
|
||||
pthread_mutex_t m;
|
||||
public:
|
||||
recursive_mutex()
|
||||
@@ -92,9 +93,11 @@ namespace boost
|
||||
|
||||
typedef recursive_mutex recursive_try_mutex;
|
||||
|
||||
class recursive_timed_mutex:
|
||||
boost::noncopyable
|
||||
class recursive_timed_mutex
|
||||
{
|
||||
private:
|
||||
recursive_timed_mutex(recursive_timed_mutex const&);
|
||||
recursive_timed_mutex& operator=(recursive_timed_mutex const&);
|
||||
private:
|
||||
pthread_mutex_t m;
|
||||
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
|
||||
@@ -225,7 +225,7 @@ namespace boost
|
||||
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);
|
||||
}
|
||||
|
||||
bool try_lock_upgrade()
|
||||
|
||||
@@ -62,6 +62,8 @@ namespace boost
|
||||
boost::shared_ptr<detail::tss_cleanup_function> cleanup;
|
||||
|
||||
public:
|
||||
typedef T element_type;
|
||||
|
||||
thread_specific_ptr():
|
||||
cleanup(detail::heap_new<delete_data>(),detail::do_heap_delete<delete_data>())
|
||||
{}
|
||||
|
||||
@@ -20,9 +20,11 @@ namespace boost
|
||||
}
|
||||
|
||||
class mutex:
|
||||
boost::noncopyable,
|
||||
public ::boost::detail::underlying_mutex
|
||||
{
|
||||
private:
|
||||
mutex(mutex const&);
|
||||
mutex& operator=(mutex const&);
|
||||
public:
|
||||
mutex()
|
||||
{
|
||||
@@ -40,9 +42,11 @@ namespace boost
|
||||
typedef mutex try_mutex;
|
||||
|
||||
class timed_mutex:
|
||||
boost::noncopyable,
|
||||
public ::boost::detail::basic_timed_mutex
|
||||
{
|
||||
private:
|
||||
timed_mutex(timed_mutex const&);
|
||||
timed_mutex& operator=(timed_mutex const&);
|
||||
public:
|
||||
timed_mutex()
|
||||
{
|
||||
|
||||
@@ -20,9 +20,11 @@
|
||||
namespace boost
|
||||
{
|
||||
class recursive_mutex:
|
||||
boost::noncopyable,
|
||||
public ::boost::detail::basic_recursive_mutex
|
||||
{
|
||||
private:
|
||||
recursive_mutex(recursive_mutex const&);
|
||||
recursive_mutex& operator=(recursive_mutex const&);
|
||||
public:
|
||||
recursive_mutex()
|
||||
{
|
||||
@@ -40,9 +42,11 @@ namespace boost
|
||||
typedef recursive_mutex recursive_try_mutex;
|
||||
|
||||
class recursive_timed_mutex:
|
||||
boost::noncopyable,
|
||||
public ::boost::detail::basic_recursive_timed_mutex
|
||||
{
|
||||
private:
|
||||
recursive_timed_mutex(recursive_timed_mutex const&);
|
||||
recursive_timed_mutex& operator=(recursive_timed_mutex const&);
|
||||
public:
|
||||
recursive_timed_mutex()
|
||||
{
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class shared_mutex:
|
||||
private boost::noncopyable
|
||||
class shared_mutex
|
||||
{
|
||||
private:
|
||||
shared_mutex(shared_mutex const&);
|
||||
shared_mutex& operator=(shared_mutex const&);
|
||||
private:
|
||||
struct state_data
|
||||
{
|
||||
@@ -49,33 +51,35 @@ namespace boost
|
||||
return *reinterpret_cast<T const*>(&res);
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
unlock_sem = 0,
|
||||
exclusive_sem = 1
|
||||
};
|
||||
|
||||
state_data state;
|
||||
detail::win32::handle semaphores[2];
|
||||
detail::win32::handle &unlock_sem;
|
||||
detail::win32::handle &exclusive_sem;
|
||||
detail::win32::handle upgrade_sem;
|
||||
|
||||
void release_waiters(state_data old_state)
|
||||
{
|
||||
if(old_state.exclusive_waiting)
|
||||
{
|
||||
BOOST_VERIFY(detail::win32::ReleaseSemaphore(exclusive_sem,1,0)!=0);
|
||||
BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[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);
|
||||
BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[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])
|
||||
shared_mutex()
|
||||
{
|
||||
unlock_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX);
|
||||
exclusive_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX);
|
||||
semaphores[unlock_sem]=detail::win32::create_anonymous_semaphore(0,LONG_MAX);
|
||||
semaphores[exclusive_sem]=detail::win32::create_anonymous_semaphore(0,LONG_MAX);
|
||||
upgrade_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX);
|
||||
state_data state_={0};
|
||||
state=state_;
|
||||
@@ -84,8 +88,8 @@ namespace boost
|
||||
~shared_mutex()
|
||||
{
|
||||
detail::win32::CloseHandle(upgrade_sem);
|
||||
detail::win32::CloseHandle(unlock_sem);
|
||||
detail::win32::CloseHandle(exclusive_sem);
|
||||
detail::win32::CloseHandle(semaphores[unlock_sem]);
|
||||
detail::win32::CloseHandle(semaphores[exclusive_sem]);
|
||||
}
|
||||
|
||||
bool try_lock_shared()
|
||||
@@ -97,6 +101,10 @@ namespace boost
|
||||
if(!new_state.exclusive && !new_state.exclusive_waiting_blocked)
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
@@ -131,10 +139,18 @@ namespace boost
|
||||
if(new_state.exclusive || new_state.exclusive_waiting_blocked)
|
||||
{
|
||||
++new_state.shared_waiting;
|
||||
if(!new_state.shared_waiting)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
}
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
@@ -150,7 +166,7 @@ namespace boost
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned long const res=detail::win32::WaitForSingleObject(unlock_sem,::boost::detail::get_milliseconds_until(wait_until));
|
||||
unsigned long const res=detail::win32::WaitForSingleObject(semaphores[unlock_sem],::boost::detail::get_milliseconds_until(wait_until));
|
||||
if(res==detail::win32::timeout)
|
||||
{
|
||||
for(;;)
|
||||
@@ -166,6 +182,10 @@ namespace boost
|
||||
else
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
@@ -282,6 +302,11 @@ namespace boost
|
||||
if(new_state.shared_count || new_state.exclusive)
|
||||
{
|
||||
++new_state.exclusive_waiting;
|
||||
if(!new_state.exclusive_waiting)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
|
||||
new_state.exclusive_waiting_blocked=true;
|
||||
}
|
||||
else
|
||||
@@ -374,10 +399,18 @@ namespace boost
|
||||
if(new_state.exclusive || new_state.exclusive_waiting_blocked || new_state.upgrade)
|
||||
{
|
||||
++new_state.shared_waiting;
|
||||
if(!new_state.shared_waiting)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
new_state.upgrade=true;
|
||||
}
|
||||
|
||||
@@ -394,7 +427,7 @@ namespace boost
|
||||
return;
|
||||
}
|
||||
|
||||
BOOST_VERIFY(!detail::win32::WaitForSingleObject(unlock_sem,detail::win32::infinite));
|
||||
BOOST_VERIFY(!detail::win32::WaitForSingleObject(semaphores[unlock_sem],detail::win32::infinite));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,6 +444,10 @@ namespace boost
|
||||
else
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
new_state.upgrade=true;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,6 +144,11 @@ namespace boost
|
||||
start(0),milliseconds(~uintmax_t(0)),relative(true)
|
||||
{}
|
||||
};
|
||||
|
||||
inline unsigned long pin_to_zero(long value)
|
||||
{
|
||||
return (value<0)?0u:(unsigned long)value;
|
||||
}
|
||||
}
|
||||
|
||||
namespace this_thread
|
||||
@@ -163,7 +168,7 @@ namespace boost
|
||||
template<typename TimeDuration>
|
||||
inline void sleep(TimeDuration const& rel_time)
|
||||
{
|
||||
interruptible_wait(static_cast<unsigned long>(rel_time.total_milliseconds()));
|
||||
interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
|
||||
}
|
||||
inline void sleep(system_time const& abs_time)
|
||||
{
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace boost
|
||||
{
|
||||
current=next;
|
||||
++next;
|
||||
if(current->second.func && current->second.value)
|
||||
if(current->second.func && (current->second.value!=0))
|
||||
{
|
||||
(*current->second.func)(current->second.value);
|
||||
}
|
||||
@@ -381,12 +381,12 @@ namespace boost
|
||||
{
|
||||
#if defined(PTW32_VERSION) || defined(__hpux)
|
||||
return pthread_num_processors_np();
|
||||
#elif defined(_GNU_SOURCE)
|
||||
return get_nprocs();
|
||||
#elif defined(__APPLE__) || defined(__FreeBSD__)
|
||||
int count;
|
||||
size_t size=sizeof(count);
|
||||
return sysctlbyname("hw.ncpu",&count,&size,NULL,0)?0:count;
|
||||
#elif defined(_GNU_SOURCE)
|
||||
return get_nprocs();
|
||||
#elif defined(BOOST_HAS_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
|
||||
int const count=sysconf(_SC_NPROCESSORS_ONLN);
|
||||
return (count>0)?count:0;
|
||||
@@ -582,11 +582,11 @@ namespace boost
|
||||
{
|
||||
if(tss_data_node* const current_node=find_tss_data(key))
|
||||
{
|
||||
if(cleanup_existing && current_node->func && current_node->value)
|
||||
if(cleanup_existing && current_node->func && (current_node->value!=0))
|
||||
{
|
||||
(*current_node->func)(current_node->value);
|
||||
}
|
||||
if(func || tss_data)
|
||||
if(func || (tss_data!=0))
|
||||
{
|
||||
current_node->func=func;
|
||||
current_node->value=tss_data;
|
||||
|
||||
@@ -304,7 +304,7 @@ namespace boost
|
||||
|
||||
unsigned thread::hardware_concurrency()
|
||||
{
|
||||
SYSTEM_INFO info={0};
|
||||
SYSTEM_INFO info={{0}};
|
||||
GetSystemInfo(&info);
|
||||
return info.dwNumberOfProcessors;
|
||||
}
|
||||
@@ -327,7 +327,7 @@ namespace boost
|
||||
{
|
||||
LARGE_INTEGER get_due_time(detail::timeout const& target_time)
|
||||
{
|
||||
LARGE_INTEGER due_time={0};
|
||||
LARGE_INTEGER due_time={{0}};
|
||||
if(target_time.relative)
|
||||
{
|
||||
unsigned long const elapsed_milliseconds=GetTickCount()-target_time.start;
|
||||
@@ -356,7 +356,23 @@ namespace boost
|
||||
else
|
||||
{
|
||||
long const hundred_nanoseconds_in_one_second=10000000;
|
||||
due_time.QuadPart+=target_time.abs_time.time_of_day().fractional_seconds()*(hundred_nanoseconds_in_one_second/target_time.abs_time.time_of_day().ticks_per_second());
|
||||
posix_time::time_duration::tick_type const ticks_per_second=
|
||||
target_time.abs_time.time_of_day().ticks_per_second();
|
||||
if(ticks_per_second>hundred_nanoseconds_in_one_second)
|
||||
{
|
||||
posix_time::time_duration::tick_type const
|
||||
ticks_per_hundred_nanoseconds=
|
||||
ticks_per_second/hundred_nanoseconds_in_one_second;
|
||||
due_time.QuadPart+=
|
||||
target_time.abs_time.time_of_day().fractional_seconds()/
|
||||
ticks_per_hundred_nanoseconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
due_time.QuadPart+=
|
||||
target_time.abs_time.time_of_day().fractional_seconds()*
|
||||
(hundred_nanoseconds_in_one_second/ticks_per_second);
|
||||
}
|
||||
}
|
||||
}
|
||||
return due_time;
|
||||
@@ -577,22 +593,22 @@ namespace boost
|
||||
}
|
||||
}
|
||||
}
|
||||
BOOST_THREAD_DECL void __cdecl on_process_enter()
|
||||
{}
|
||||
|
||||
BOOST_THREAD_DECL void __cdecl on_thread_enter()
|
||||
{}
|
||||
|
||||
BOOST_THREAD_DECL void __cdecl on_process_exit()
|
||||
{
|
||||
boost::cleanup_tls_key();
|
||||
}
|
||||
|
||||
BOOST_THREAD_DECL void __cdecl on_thread_exit()
|
||||
{
|
||||
boost::run_thread_exit_callbacks();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_process_enter()
|
||||
{}
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_thread_enter()
|
||||
{}
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_process_exit()
|
||||
{
|
||||
boost::cleanup_tls_key();
|
||||
}
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_thread_exit()
|
||||
{
|
||||
boost::run_thread_exit_callbacks();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,27 +24,27 @@
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
on_process_enter();
|
||||
on_thread_enter();
|
||||
boost::on_process_enter();
|
||||
boost::on_thread_enter();
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
{
|
||||
on_thread_enter();
|
||||
boost::on_thread_enter();
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_THREAD_DETACH:
|
||||
{
|
||||
on_thread_exit();
|
||||
boost::on_thread_exit();
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
on_thread_exit();
|
||||
on_process_exit();
|
||||
boost::on_thread_exit();
|
||||
boost::on_process_exit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,9 @@
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern "C" void tss_cleanup_implemented(void)
|
||||
namespace boost
|
||||
{
|
||||
void tss_cleanup_implemented()
|
||||
{
|
||||
/*
|
||||
This function's sole purpose is to cause a link error in cases where
|
||||
@@ -68,5 +70,7 @@
|
||||
longer needed and can be removed.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //defined(BOOST_HAS_WINTHREADS) && defined(BOOST_THREAD_BUILD_DLL)
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
extern "C" void tss_cleanup_implemented(void) {}
|
||||
namespace boost
|
||||
{
|
||||
void tss_cleanup_implemented() {}
|
||||
}
|
||||
|
||||
namespace {
|
||||
void NTAPI on_tls_callback(void* h, DWORD dwReason, PVOID pv)
|
||||
@@ -28,33 +31,18 @@ namespace {
|
||||
{
|
||||
case DLL_THREAD_DETACH:
|
||||
{
|
||||
on_thread_exit();
|
||||
boost::on_thread_exit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void on_after_ctors(void)
|
||||
{
|
||||
on_process_enter();
|
||||
}
|
||||
|
||||
void on_before_dtors(void)
|
||||
{
|
||||
on_thread_exit();
|
||||
}
|
||||
|
||||
void on_after_dtors(void)
|
||||
{
|
||||
on_process_exit();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
void (* after_ctors )(void) __attribute__((section(".ctors"))) = on_after_ctors;
|
||||
void (* before_dtors)(void) __attribute__((section(".dtors"))) = on_before_dtors;
|
||||
void (* after_dtors )(void) __attribute__((section(".dtors.zzz"))) = on_after_dtors;
|
||||
void (* after_ctors )(void) __attribute__((section(".ctors"))) = boost::on_process_enter;
|
||||
void (* before_dtors)(void) __attribute__((section(".dtors"))) = boost::on_thread_exit;
|
||||
void (* after_dtors )(void) __attribute__((section(".dtors.zzz"))) = boost::on_process_exit;
|
||||
|
||||
ULONG __tls_index__ = 0;
|
||||
char __tls_end__ __attribute__((section(".tls$zzz"))) = 0;
|
||||
@@ -221,18 +209,18 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata
|
||||
//for destructors of global objects, so that
|
||||
//shouldn't be a problem.
|
||||
|
||||
atexit(on_thread_exit);
|
||||
atexit(boost::on_thread_exit);
|
||||
|
||||
//Call Boost process entry callback here
|
||||
|
||||
on_process_enter();
|
||||
boost::on_process_enter();
|
||||
|
||||
return INIRETSUCCESS;
|
||||
}
|
||||
|
||||
PVAPI on_process_term(void)
|
||||
{
|
||||
on_process_exit();
|
||||
boost::on_process_exit();
|
||||
return INIRETSUCCESS;
|
||||
}
|
||||
|
||||
@@ -241,7 +229,7 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata
|
||||
switch (dwReason)
|
||||
{
|
||||
case DLL_THREAD_DETACH:
|
||||
on_thread_exit();
|
||||
boost::on_thread_exit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -251,10 +239,10 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata
|
||||
switch (dwReason)
|
||||
{
|
||||
case DLL_THREAD_DETACH:
|
||||
on_thread_exit();
|
||||
boost::on_thread_exit();
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
on_process_exit();
|
||||
boost::on_process_exit();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
@@ -265,8 +253,9 @@ extern "C"
|
||||
{
|
||||
extern BOOL (WINAPI * const _pRawDllMain)(HANDLE, DWORD, LPVOID)=&dll_callback;
|
||||
}
|
||||
|
||||
extern "C" void tss_cleanup_implemented(void)
|
||||
namespace boost
|
||||
{
|
||||
void tss_cleanup_implemented()
|
||||
{
|
||||
/*
|
||||
This function's sole purpose is to cause a link error in cases where
|
||||
@@ -282,6 +271,8 @@ extern "C"
|
||||
longer needed and can be removed.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#endif //defined(_MSC_VER) && !defined(UNDER_CE)
|
||||
|
||||
#endif //defined(BOOST_HAS_WINTHREADS) && defined(BOOST_THREAD_BUILD_LIB)
|
||||
|
||||
@@ -296,10 +296,80 @@ void test_lock_five_in_range()
|
||||
}
|
||||
}
|
||||
|
||||
void test_lock_ten_in_range()
|
||||
class dummy_iterator:
|
||||
public std::iterator<std::forward_iterator_tag,
|
||||
dummy_mutex>
|
||||
{
|
||||
private:
|
||||
dummy_mutex* p;
|
||||
public:
|
||||
explicit dummy_iterator(dummy_mutex* p_):
|
||||
p(p_)
|
||||
{}
|
||||
|
||||
bool operator==(dummy_iterator const& other) const
|
||||
{
|
||||
return p==other.p;
|
||||
}
|
||||
|
||||
bool operator!=(dummy_iterator const& other) const
|
||||
{
|
||||
return p!=other.p;
|
||||
}
|
||||
|
||||
bool operator<(dummy_iterator const& other) const
|
||||
{
|
||||
return p<other.p;
|
||||
}
|
||||
|
||||
dummy_mutex& operator*() const
|
||||
{
|
||||
return *p;
|
||||
}
|
||||
|
||||
dummy_mutex* operator->() const
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
dummy_iterator operator++(int)
|
||||
{
|
||||
dummy_iterator temp(*this);
|
||||
++p;
|
||||
return temp;
|
||||
}
|
||||
|
||||
dummy_iterator& operator++()
|
||||
{
|
||||
++p;
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
void test_lock_five_in_range_custom_iterator()
|
||||
{
|
||||
unsigned const num_mutexes=5;
|
||||
dummy_mutex mutexes[num_mutexes];
|
||||
|
||||
boost::lock(dummy_iterator(mutexes),dummy_iterator(mutexes+num_mutexes));
|
||||
|
||||
for(unsigned i=0;i<num_mutexes;++i)
|
||||
{
|
||||
BOOST_CHECK(mutexes[i].is_locked);
|
||||
}
|
||||
}
|
||||
|
||||
class dummy_mutex2:
|
||||
public dummy_mutex
|
||||
{};
|
||||
|
||||
|
||||
void test_lock_ten_in_range_inherited_mutex()
|
||||
{
|
||||
unsigned const num_mutexes=10;
|
||||
dummy_mutex mutexes[num_mutexes];
|
||||
dummy_mutex2 mutexes[num_mutexes];
|
||||
|
||||
boost::lock(mutexes,mutexes+num_mutexes);
|
||||
|
||||
@@ -510,7 +580,8 @@ boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
|
||||
test->add(BOOST_TEST_CASE(&test_lock_five_other_thread_locks_in_order));
|
||||
test->add(BOOST_TEST_CASE(&test_lock_five_other_thread_locks_in_different_order));
|
||||
test->add(BOOST_TEST_CASE(&test_lock_five_in_range));
|
||||
test->add(BOOST_TEST_CASE(&test_lock_ten_in_range));
|
||||
test->add(BOOST_TEST_CASE(&test_lock_five_in_range_custom_iterator));
|
||||
test->add(BOOST_TEST_CASE(&test_lock_ten_in_range_inherited_mutex));
|
||||
test->add(BOOST_TEST_CASE(&test_lock_ten_other_thread_locks_in_different_order));
|
||||
test->add(BOOST_TEST_CASE(&test_try_lock_two_uncontended));
|
||||
test->add(BOOST_TEST_CASE(&test_try_lock_two_first_locked));
|
||||
|
||||
Reference in New Issue
Block a user