Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2008-02-04 08:16:32


Author: anthonyw
Date: 2008-02-04 08:16:32 EST (Mon, 04 Feb 2008)
New Revision: 43094
URL: http://svn.boost.org/trac/boost/changeset/43094

Log:
added test for duration overloads of timed_lock, and added missing implementation to win32 version
Text files modified:
   trunk/boost/thread/win32/basic_recursive_mutex.hpp | 6 ++++++
   trunk/boost/thread/win32/basic_timed_mutex.hpp | 6 ++++++
   trunk/libs/thread/test/test_mutex.cpp | 11 +++++++++++
   3 files changed, 23 insertions(+), 0 deletions(-)

Modified: trunk/boost/thread/win32/basic_recursive_mutex.hpp
==============================================================================
--- trunk/boost/thread/win32/basic_recursive_mutex.hpp (original)
+++ trunk/boost/thread/win32/basic_recursive_mutex.hpp 2008-02-04 08:16:32 EST (Mon, 04 Feb 2008)
@@ -56,6 +56,12 @@
                 long const current_thread_id=win32::GetCurrentThreadId();
                 return try_recursive_lock(current_thread_id) || try_timed_lock(current_thread_id,target);
             }
+ template<typename Duration>
+ bool timed_lock(Duration const& timeout)
+ {
+ return timed_lock(get_system_time()+timeout);
+ }
+
             long get_active_count()
             {
                 return mutex.get_active_count();

Modified: trunk/boost/thread/win32/basic_timed_mutex.hpp
==============================================================================
--- trunk/boost/thread/win32/basic_timed_mutex.hpp (original)
+++ trunk/boost/thread/win32/basic_timed_mutex.hpp 2008-02-04 08:16:32 EST (Mon, 04 Feb 2008)
@@ -104,6 +104,12 @@
                 return true;
             }
 
+ template<typename Duration>
+ 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);

Modified: trunk/libs/thread/test/test_mutex.cpp
==============================================================================
--- trunk/libs/thread/test/test_mutex.cpp (original)
+++ trunk/libs/thread/test/test_mutex.cpp 2008-02-04 08:16:32 EST (Mon, 04 Feb 2008)
@@ -150,6 +150,17 @@
         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);
+
     }
 };
 


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