2
0
mirror of https://github.com/boostorg/thread.git synced 2026-01-30 08:22:13 +00:00

Renamed internal bind stuff to invoker, as more expressive

[SVN r48209]
This commit is contained in:
Anthony Williams
2008-08-19 07:03:22 +00:00
parent 0d776bcd26
commit dcebae6d4a

View File

@@ -7,6 +7,7 @@
#include <boost/thread/detail/config.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/thread_time.hpp>
#include <boost/thread/condition.hpp>
@@ -109,6 +110,8 @@ struct test_timedlock
void operator()()
{
test_lock_times_out_if_other_thread_has_lock<mutex_type>()();
mutex_type mutex;
boost::condition condition;
@@ -178,6 +181,67 @@ struct test_recursive_lock
}
};
template<typename Mutex>
struct test_lock_times_out_if_other_thread_has_lock
{
typedef boost::unique_lock<Mutex> Lock;
Mutex m;
boost::mutex done_mutex;
bool done;
bool locked;
boost::condition_variable done_cond;
test_lock_times_out_if_other_thread_has_lock():
done(false),locked(false)
{}
void locking_thread()
{
Lock lock(m,boost::defer_lock);
lock.timed_lock(boost::posix_time::milliseconds(50));
boost::lock_guard<boost::mutex> lk(done_mutex);
locked=lock.owns_lock();
done=true;
done_cond.notify_one();
}
bool is_done() const
{
return done;
}
void operator()()
{
Lock lock(m);
typedef test_lock_times_out_if_other_thread_has_lock<Mutex> this_type;
boost::thread t(&this_type::locking_thread,this);
try
{
{
boost::mutex::scoped_lock lk(done_mutex);
BOOST_CHECK(done_cond.timed_wait(lk,boost::posix_time::seconds(2),
boost::bind(&this_type::is_done,this)));
BOOST_CHECK(!locked);
}
lock.unlock();
t.join();
}
catch(...)
{
lock.unlock();
t.join();
throw;
}
}
};
void do_test_mutex()
{
test_lock<boost::mutex>()();