diff --git a/include/boost/thread/win32/basic_recursive_mutex.hpp b/include/boost/thread/win32/basic_recursive_mutex.hpp index e5f79981..d2b8e77d 100644 --- a/include/boost/thread/win32/basic_recursive_mutex.hpp +++ b/include/boost/thread/win32/basic_recursive_mutex.hpp @@ -56,6 +56,12 @@ namespace boost long const current_thread_id=win32::GetCurrentThreadId(); return try_recursive_lock(current_thread_id) || try_timed_lock(current_thread_id,target); } + template + bool timed_lock(Duration const& timeout) + { + return timed_lock(get_system_time()+timeout); + } + long get_active_count() { return mutex.get_active_count(); diff --git a/include/boost/thread/win32/basic_timed_mutex.hpp b/include/boost/thread/win32/basic_timed_mutex.hpp index fef19d7b..8ee199df 100644 --- a/include/boost/thread/win32/basic_timed_mutex.hpp +++ b/include/boost/thread/win32/basic_timed_mutex.hpp @@ -104,6 +104,12 @@ namespace boost return true; } + template + bool timed_lock(Duration const& timeout) + { + return timed_lock(get_system_time()+timeout); + } + long get_active_count() { return ::boost::detail::interlocked_read_acquire(&active_count); diff --git a/test/test_mutex.cpp b/test/test_mutex.cpp index 5dae38ee..e85459c4 100644 --- a/test/test_mutex.cpp +++ b/test/test_mutex.cpp @@ -150,6 +150,17 @@ struct test_timedlock boost::system_time target = boost::get_system_time()+boost::posix_time::milliseconds(100); BOOST_CHECK(lock.timed_lock(target)); BOOST_CHECK(lock ? true : false); + lock.unlock(); + BOOST_CHECK(!lock); + + BOOST_CHECK(mutex.timed_lock(boost::posix_time::milliseconds(100))); + mutex.unlock(); + + BOOST_CHECK(lock.timed_lock(boost::posix_time::milliseconds(100))); + BOOST_CHECK(lock ? true : false); + lock.unlock(); + BOOST_CHECK(!lock); + } };