Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2008-07-07 18:19:29


Author: anthonyw
Date: 2008-07-07 18:19:28 EDT (Mon, 07 Jul 2008)
New Revision: 47199
URL: http://svn.boost.org/trac/boost/changeset/47199

Log:
test and fix for issue #2080
Text files modified:
   trunk/boost/thread/locks.hpp | 10 +++++
   trunk/libs/thread/test/test_lock_concept.cpp | 72 ++++++++++++++++++++++++++++++++++++++++
   2 files changed, 82 insertions(+), 0 deletions(-)

Modified: trunk/boost/thread/locks.hpp
==============================================================================
--- trunk/boost/thread/locks.hpp (original)
+++ trunk/boost/thread/locks.hpp 2008-07-07 18:19:28 EDT (Mon, 07 Jul 2008)
@@ -495,6 +495,16 @@
             is_locked=m->timed_lock_shared(target_time);
             return is_locked;
         }
+ template<typename Duration>
+ bool timed_lock(Duration const& target_time)
+ {
+ if(owns_lock())
+ {
+ throw boost::lock_error();
+ }
+ is_locked=m->timed_lock_shared(target_time);
+ return is_locked;
+ }
         void unlock()
         {
             if(!owns_lock())

Modified: trunk/libs/thread/test/test_lock_concept.cpp
==============================================================================
--- trunk/libs/thread/test/test_lock_concept.cpp (original)
+++ trunk/libs/thread/test/test_lock_concept.cpp 2008-07-07 18:19:28 EDT (Mon, 07 Jul 2008)
@@ -454,6 +454,68 @@
     test_locks_can_be_swapped<Mutex,Lock>()();
 }
 
+struct dummy_shared_mutex
+{
+ bool locked;
+ bool shared_locked;
+ bool shared_unlocked;
+ bool shared_timed_locked_relative;
+ bool shared_timed_locked_absolute;
+ bool timed_locked_relative;
+ bool timed_locked_absolute;
+
+ dummy_shared_mutex():
+ locked(false),shared_locked(false),shared_unlocked(false),
+ shared_timed_locked_relative(false),
+ shared_timed_locked_absolute(false),
+ timed_locked_relative(false),
+ timed_locked_absolute(false)
+ {}
+
+ void lock()
+ {
+ locked=true;
+ }
+
+ void lock_shared()
+ {
+ shared_locked=true;
+ }
+
+ void unlock()
+ {}
+
+ void unlock_shared()
+ {
+ shared_unlocked=true;
+ }
+
+ bool timed_lock_shared(boost::system_time)
+ {
+ shared_timed_locked_absolute=true;
+ return false;
+ }
+ template<typename Duration>
+ bool timed_lock_shared(Duration)
+ {
+ shared_timed_locked_relative=true;
+ return false;
+ }
+ bool timed_lock(boost::system_time)
+ {
+ timed_locked_absolute=true;
+ return false;
+ }
+ template<typename Duration>
+ bool timed_lock(Duration)
+ {
+ timed_locked_relative=true;
+ return false;
+ }
+
+};
+
+
 void test_shared_lock()
 {
     typedef boost::shared_mutex Mutex;
@@ -472,6 +534,16 @@
     test_throws_if_try_lock_called_when_already_locked<Mutex,Lock>()();
     test_throws_if_unlock_called_when_already_unlocked<Mutex,Lock>()();
     test_locks_can_be_swapped<Mutex,Lock>()();
+
+ dummy_shared_mutex dummy;
+ boost::shared_lock<dummy_shared_mutex> lk(dummy);
+ BOOST_CHECK(dummy.shared_locked);
+ lk.unlock();
+ BOOST_CHECK(dummy.shared_unlocked);
+ lk.timed_lock(boost::posix_time::milliseconds(5));
+ BOOST_CHECK(dummy.shared_timed_locked_relative);
+ lk.timed_lock(boost::get_system_time());
+ BOOST_CHECK(dummy.shared_timed_locked_absolute);
 }
 
 boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])


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