Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2008-07-06 17:58:12


Author: anthonyw
Date: 2008-07-06 17:58:11 EDT (Sun, 06 Jul 2008)
New Revision: 47149
URL: http://svn.boost.org/trac/boost/changeset/47149

Log:
Backwards compatibility with xtime --- test and fix for issue #2052
Text files modified:
   trunk/boost/thread/locks.hpp | 7 ++++++
   trunk/boost/thread/pthread/mutex.hpp | 5 ++++
   trunk/boost/thread/win32/basic_timed_mutex.hpp | 6 +++++
   trunk/libs/thread/test/test_xtime.cpp | 44 ++++++++++++++++++++++++++++++++++++++++
   4 files changed, 62 insertions(+), 0 deletions(-)

Modified: trunk/boost/thread/locks.hpp
==============================================================================
--- trunk/boost/thread/locks.hpp (original)
+++ trunk/boost/thread/locks.hpp 2008-07-06 17:58:11 EDT (Sun, 06 Jul 2008)
@@ -16,6 +16,8 @@
 
 namespace boost
 {
+ struct xtime;
+
     namespace detail
     {
         template<typename T>
@@ -265,6 +267,11 @@
             is_locked=m->timed_lock(absolute_time);
             return is_locked;
         }
+ bool timed_lock(::boost::xtime const& absolute_time)
+ {
+ is_locked=m->timed_lock(absolute_time);
+ return is_locked;
+ }
         void unlock()
         {
             if(!owns_lock())

Modified: trunk/boost/thread/pthread/mutex.hpp
==============================================================================
--- trunk/boost/thread/pthread/mutex.hpp (original)
+++ trunk/boost/thread/pthread/mutex.hpp 2008-07-06 17:58:11 EDT (Sun, 06 Jul 2008)
@@ -10,6 +10,7 @@
 #include <boost/thread/exceptions.hpp>
 #include <boost/thread/locks.hpp>
 #include <boost/thread/thread_time.hpp>
+#include <boost/thread/xtime.hpp>
 #include <boost/assert.hpp>
 #include <errno.h>
 #include "timespec.hpp"
@@ -113,6 +114,10 @@
         {
             return timed_lock(get_system_time()+relative_time);
         }
+ bool timed_lock(boost::xtime const & absolute_time)
+ {
+ return timed_lock(system_time(absolute_time));
+ }
 
 #ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
         void lock()

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-07-06 17:58:11 EDT (Sun, 06 Jul 2008)
@@ -13,6 +13,7 @@
 #include "thread_primitives.hpp"
 #include "interlocked_read.hpp"
 #include <boost/thread/thread_time.hpp>
+#include <boost/thread/xtime.hpp>
 #include <boost/detail/interlocked.hpp>
 
 #include <boost/config/abi_prefix.hpp>
@@ -117,6 +118,11 @@
                 return timed_lock(get_system_time()+timeout);
             }
 
+ bool timed_lock(boost::xtime const& timeout)
+ {
+ return timed_lock(system_time(timeout));
+ }
+
             long get_active_count()
             {
                 return ::boost::detail::interlocked_read_acquire(&active_count);

Modified: trunk/libs/thread/test/test_xtime.cpp
==============================================================================
--- trunk/libs/thread/test/test_xtime.cpp (original)
+++ trunk/libs/thread/test/test_xtime.cpp 2008-07-06 17:58:11 EDT (Sun, 06 Jul 2008)
@@ -1,5 +1,6 @@
 // Copyright (C) 2001-2003
 // William E. Kempf
+// Copyright (C) 2008 Anthony Williams
 //
 // 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)
@@ -9,6 +10,8 @@
 #include <boost/thread/xtime.hpp>
 
 #include <boost/test/unit_test.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/condition.hpp>
 
 void test_xtime_cmp()
 {
@@ -53,6 +56,45 @@
     }
 }
 
+void test_xtime_mutex_backwards_compatibility()
+{
+ boost::timed_mutex m;
+ BOOST_CHECK(m.timed_lock(boost::get_xtime(boost::get_system_time()+boost::posix_time::milliseconds(10))));
+ m.unlock();
+ boost::timed_mutex::scoped_timed_lock lk(m,boost::get_xtime(boost::get_system_time()+boost::posix_time::milliseconds(10)));
+ BOOST_CHECK(lk.owns_lock());
+ if(lk.owns_lock())
+ {
+ lk.unlock();
+ }
+ BOOST_CHECK(lk.timed_lock(boost::get_xtime(boost::get_system_time()+boost::posix_time::milliseconds(10))));
+ if(lk.owns_lock())
+ {
+ lk.unlock();
+ }
+}
+
+bool predicate()
+{
+ return false;
+}
+
+
+void test_xtime_condvar_backwards_compatibility()
+{
+ boost::condition_variable cond;
+ boost::condition_variable_any cond_any;
+ boost::mutex m;
+
+ boost::mutex::scoped_lock lk(m);
+ cond.timed_wait(lk,boost::get_xtime(boost::get_system_time()+boost::posix_time::milliseconds(10)));
+ cond.timed_wait(lk,boost::get_xtime(boost::get_system_time()+boost::posix_time::milliseconds(10)),predicate);
+ cond_any.timed_wait(lk,boost::get_xtime(boost::get_system_time()+boost::posix_time::milliseconds(10)));
+ cond_any.timed_wait(lk,boost::get_xtime(boost::get_system_time()+boost::posix_time::milliseconds(10)),predicate);
+}
+
+
+
 boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
 {
     boost::unit_test_framework::test_suite* test =
@@ -60,6 +102,8 @@
 
     test->add(BOOST_TEST_CASE(&test_xtime_cmp));
     test->add(BOOST_TEST_CASE(&test_xtime_get));
+ test->add(BOOST_TEST_CASE(&test_xtime_mutex_backwards_compatibility));
+ test->add(BOOST_TEST_CASE(&test_xtime_condvar_backwards_compatibility));
 
     return test;
 }


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