Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82823 - in trunk: boost/thread libs/thread/test libs/thread/test/sync/mutual_exclusion/null_mutex
From: vicente.botet_at_[hidden]
Date: 2013-02-11 13:43:34


Author: viboes
Date: 2013-02-11 13:43:33 EST (Mon, 11 Feb 2013)
New Revision: 82823
URL: http://svn.boost.org/trac/boost/changeset/82823

Log:
Thread: Fixed null_mutex initialization + added tests some tests.
Added:
   trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/assign_fail.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/copy_fail.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/default_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/lock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_for_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_until_pass.cpp (contents, props changed)
Text files modified:
   trunk/boost/thread/null_mutex.hpp | 3 +++
   trunk/libs/thread/test/Jamfile.v2 | 13 +++++++++++++
   2 files changed, 16 insertions(+), 0 deletions(-)

Modified: trunk/boost/thread/null_mutex.hpp
==============================================================================
--- trunk/boost/thread/null_mutex.hpp (original)
+++ trunk/boost/thread/null_mutex.hpp 2013-02-11 13:43:33 EST (Mon, 11 Feb 2013)
@@ -11,6 +11,7 @@
 #ifndef BOOST_THREAD_NULL_MUTEX_HPP
 #define BOOST_THREAD_NULL_MUTEX_HPP
 
+#include <boost/thread/detail/config.hpp>
 #include <boost/thread/detail/delete.hpp>
 #include <boost/chrono/chrono.hpp>
 
@@ -28,6 +29,8 @@
 
     BOOST_THREAD_NO_COPYABLE( null_mutex) /*< no copyable >*/
 
+ null_mutex() {}
+
     /// Simulates a mutex lock() operation. Empty function.
     void lock()
     {

Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2013-02-11 13:43:33 EST (Mon, 11 Feb 2013)
@@ -580,6 +580,19 @@
           #[ thread-run2-h ./sync/mutual_exclusion/shared_mutex/default_pass.cpp : shared_mutex__default_p ]
     ;
 
+ #explicit ts_null_mutex ;
+ test-suite ts_null_mutex
+ :
+ [ thread-compile-fail ./sync/mutual_exclusion/null_mutex/assign_fail.cpp : : null_mutex__assign_f ]
+ [ thread-compile-fail ./sync/mutual_exclusion/null_mutex/copy_fail.cpp : : null_mutex__copy_f ]
+ [ thread-run2-noit ./sync/mutual_exclusion/null_mutex/default_pass.cpp : null_mutex__default_p ]
+ [ thread-run2-noit ./sync/mutual_exclusion/null_mutex/lock_pass.cpp : null_mutex__lock_p ]
+ [ thread-run2-noit ./sync/mutual_exclusion/null_mutex/try_lock_for_pass.cpp : null_mutex__try_lock_for_p ]
+ [ thread-run2-noit ./sync/mutual_exclusion/null_mutex/try_lock_pass.cpp : null_mutex__try_lock_p ]
+ [ thread-run2-noit ./sync/mutual_exclusion/null_mutex/try_lock_until_pass.cpp : null_mutex__try_lock_until_p ]
+ ;
+
+
     #explicit ts_this_thread ;
     test-suite ts_this_thread
     :

Added: trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/assign_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/assign_fail.cpp 2013-02-11 13:43:33 EST (Mon, 11 Feb 2013)
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/null_mutex.hpp>
+
+// class null_mutex;
+
+// null_mutex& operator=(const null_mutex&) = delete;
+
+#include <boost/thread/null_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ boost::null_mutex m0;
+ boost::null_mutex m1(m0);
+}
+
+#include "../../../remove_error_code_unused_warning.hpp"

Added: trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/copy_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/copy_fail.cpp 2013-02-11 13:43:33 EST (Mon, 11 Feb 2013)
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/null_mutex.hpp>
+
+// class null_mutex;
+
+// null_mutex(const null_mutex&) = delete;
+
+#include <boost/thread/null_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ boost::null_mutex m0;
+ boost::null_mutex m1(m0);
+}
+
+#include "../../../remove_error_code_unused_warning.hpp"
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/default_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/default_pass.cpp 2013-02-11 13:43:33 EST (Mon, 11 Feb 2013)
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/null_mutex.hpp>
+
+// class null_mutex;
+
+// null_mutex();
+
+#include <boost/thread/null_mutex.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ boost::null_mutex m0;
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/lock_pass.cpp 2013-02-11 13:43:33 EST (Mon, 11 Feb 2013)
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/null_mutex.hpp>
+
+// class null_mutex;
+
+// void lock();
+
+#include <boost/thread/null_mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+
+
+boost::null_mutex m;
+
+#if defined BOOST_THREAD_USES_CHRONO
+typedef boost::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+#else
+#endif
+
+void f()
+{
+#if defined BOOST_THREAD_USES_CHRONO
+ time_point t0 = Clock::now();
+ m.lock();
+ time_point t1 = Clock::now();
+ m.lock();
+ m.unlock();
+ m.unlock();
+ ns d = t1 - t0 ;
+ // This test is spurious as it depends on the time the thread system switches the threads
+ BOOST_TEST(d < ns(2500000)); // within 2.5ms
+#else
+ //time_point t0 = Clock::now();
+ m.lock();
+ //time_point t1 = Clock::now();
+ m.lock();
+ m.unlock();
+ m.unlock();
+ //ns d = t1 - t0 ;
+ // This test is spurious as it depends on the time the thread system switches the threads
+ //BOOST_TEST(d < ns(2500000)); // within 2.5ms
+#endif
+}
+
+int main()
+{
+ m.lock();
+ boost::thread t(f);
+ m.unlock();
+ t.join();
+
+ return boost::report_errors();
+}
+
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_for_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_for_pass.cpp 2013-02-11 13:43:33 EST (Mon, 11 Feb 2013)
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/null_mutex.hpp>
+
+// class null_mutex;
+
+// template <class Rep, class Period>
+// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
+
+#include <boost/thread/null_mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#if defined BOOST_THREAD_USES_CHRONO
+
+
+boost::null_mutex m;
+
+typedef boost::chrono::steady_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+
+void f1()
+{
+ time_point t0 = Clock::now();
+ // This test is spurious as it depends on the time the thread system switches the threads
+ BOOST_TEST(m.try_lock_for(ms(100)) == true);
+ time_point t1 = Clock::now();
+ BOOST_TEST(m.try_lock());
+ m.unlock();
+ m.unlock();
+ ns d = t1 - t0 ;
+ // This test is spurious as it depends on the time the thread system switches the threads
+ BOOST_TEST(d < ns(5000000)); // within 5ms
+}
+
+
+int main()
+{
+ {
+ m.lock();
+ boost::thread t(f1);
+ m.unlock();
+ t.join();
+ }
+
+ return boost::report_errors();
+}
+
+#else
+#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
+#endif
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_pass.cpp 2013-02-11 13:43:33 EST (Mon, 11 Feb 2013)
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/null_mutex.hpp>
+
+// class null_mutex;
+
+// bool try_lock();
+
+#include <boost/thread/null_mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+
+
+boost::null_mutex m;
+
+#if defined BOOST_THREAD_USES_CHRONO
+typedef boost::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+#else
+#endif
+
+void f()
+{
+#if defined BOOST_THREAD_USES_CHRONO
+ time_point t0 = Clock::now();
+ BOOST_TEST(m.try_lock());
+ time_point t1 = Clock::now();
+ BOOST_TEST(m.try_lock());
+ m.unlock();
+ m.unlock();
+ ns d = t1 - t0;
+ // This test is spurious as it depends on the time the thread system switches the threads
+ BOOST_TEST(d < ns(50000000)); // within 50ms
+#else
+ BOOST_TEST(m.try_lock());
+ BOOST_TEST(m.try_lock());
+ m.unlock();
+ m.unlock();
+#endif
+}
+
+int main()
+{
+ m.lock();
+ boost::thread t(f);
+ m.unlock();
+ t.join();
+
+ return boost::report_errors();
+}
+
+

Added: trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_until_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/mutual_exclusion/null_mutex/try_lock_until_pass.cpp 2013-02-11 13:43:33 EST (Mon, 11 Feb 2013)
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/null_mutex>
+
+// class null_mutex;
+
+// template <class Clock, class Duration>
+// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
+
+#include <boost/thread/null_mutex.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#if defined BOOST_THREAD_USES_CHRONO
+
+boost::null_mutex m;
+
+typedef boost::chrono::steady_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef boost::chrono::milliseconds ms;
+typedef boost::chrono::nanoseconds ns;
+
+void f1()
+{
+ time_point t0 = Clock::now();
+ BOOST_TEST(m.try_lock_until(Clock::now() + ms(300) ) == true);
+ time_point t1 = Clock::now();
+ m.unlock();
+ ns d = t1 - t0 ;
+ BOOST_TEST(d < ns(5000000)); // within 5ms
+}
+
+
+int main()
+{
+ {
+ m.lock();
+ boost::thread t(f1);
+ m.unlock();
+ t.join();
+ }
+
+ return boost::report_errors();
+}
+
+#else
+#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
+#endif
+


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