|
Boost-Commit : |
From: anthony_at_[hidden]
Date: 2007-12-04 08:02:59
Author: anthonyw
Date: 2007-12-04 08:02:58 EST (Tue, 04 Dec 2007)
New Revision: 41686
URL: http://svn.boost.org/trac/boost/changeset/41686
Log:
Added test for thread move constructor; implemented move on pthreads
Added:
trunk/libs/thread/test/test_thread_move.cpp (contents, props changed)
Text files modified:
trunk/boost/thread/pthread/thread.hpp | 2 +-
trunk/boost/thread/win32/thread.hpp | 2 +-
trunk/libs/thread/src/pthread/thread.cpp | 31 +++++++++++++++++++++++++++++++
trunk/libs/thread/src/win32/thread.cpp | 10 ++++------
trunk/libs/thread/test/Jamfile.v2 | 1 +
5 files changed, 38 insertions(+), 8 deletions(-)
Modified: trunk/boost/thread/pthread/thread.hpp
==============================================================================
--- trunk/boost/thread/pthread/thread.hpp (original)
+++ trunk/boost/thread/pthread/thread.hpp 2007-12-04 08:02:58 EST (Tue, 04 Dec 2007)
@@ -133,7 +133,7 @@
start_thread();
}
- explicit thread(detail::thread_move_t<thread> x);
+ thread(detail::thread_move_t<thread> x);
thread& operator=(detail::thread_move_t<thread> x);
operator detail::thread_move_t<thread>();
detail::thread_move_t<thread> move();
Modified: trunk/boost/thread/win32/thread.hpp
==============================================================================
--- trunk/boost/thread/win32/thread.hpp (original)
+++ trunk/boost/thread/win32/thread.hpp 2007-12-04 08:02:58 EST (Tue, 04 Dec 2007)
@@ -200,7 +200,7 @@
start_thread();
}
template <class F>
- explicit thread(detail::thread_move_t<F> f):
+ thread(detail::thread_move_t<F> f):
thread_info(detail::heap_new<thread_data<F> >(f))
{
start_thread();
Modified: trunk/libs/thread/src/pthread/thread.cpp
==============================================================================
--- trunk/libs/thread/src/pthread/thread.cpp (original)
+++ trunk/libs/thread/src/pthread/thread.cpp 2007-12-04 08:02:58 EST (Tue, 04 Dec 2007)
@@ -188,6 +188,37 @@
detach();
}
+ thread::thread(detail::thread_move_t<thread> x)
+ {
+ lock_guard<mutex> lock(x->thread_info_mutex);
+ thread_info=x->thread_info;
+ x->thread_info.reset();
+ }
+
+ thread& thread::operator=(detail::thread_move_t<thread> x)
+ {
+ thread new_thread(x);
+ swap(new_thread);
+ return *this;
+ }
+
+ thread::operator detail::thread_move_t<thread>()
+ {
+ return move();
+ }
+
+ detail::thread_move_t<thread> thread::move()
+ {
+ detail::thread_move_t<thread> x(*this);
+ return x;
+ }
+
+ void thread::swap(thread& x)
+ {
+ thread_info.swap(x.thread_info);
+ }
+
+
bool thread::operator==(const thread& other) const
{
return get_id()==other.get_id();
Modified: trunk/libs/thread/src/win32/thread.cpp
==============================================================================
--- trunk/libs/thread/src/win32/thread.cpp (original)
+++ trunk/libs/thread/src/win32/thread.cpp 2007-12-04 08:02:58 EST (Tue, 04 Dec 2007)
@@ -246,11 +246,9 @@
thread::thread(detail::thread_move_t<thread> x)
{
- {
- boost::mutex::scoped_lock l(x->thread_info_mutex);
- thread_info=x->thread_info;
- }
- x->release_handle();
+ lock_guard<mutex> lock(x->thread_info_mutex);
+ thread_info=x->thread_info;
+ x->thread_info=0;
}
thread& thread::operator=(detail::thread_move_t<thread> x)
@@ -317,7 +315,7 @@
void thread::release_handle()
{
- boost::mutex::scoped_lock l1(thread_info_mutex);
+ lock_guard<mutex> l1(thread_info_mutex);
thread_info=0;
}
Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2007-12-04 08:02:58 EST (Tue, 04 Dec 2007)
@@ -35,6 +35,7 @@
{
test-suite "threads"
: [ thread-run test_thread.cpp ]
+ [ thread-run test_thread_move.cpp ]
[ thread-run test_mutex.cpp ]
[ thread-run test_condition_notify_one.cpp ]
[ thread-run test_condition_timed_wait_times_out.cpp ]
Added: trunk/libs/thread/test/test_thread_move.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/test_thread_move.cpp 2007-12-04 08:02:58 EST (Tue, 04 Dec 2007)
@@ -0,0 +1,37 @@
+// Copyright (C) 2007 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)
+#include <boost/thread/thread.hpp>
+#include <boost/test/unit_test.hpp>
+
+void do_nothing()
+{}
+
+void test_move_on_construction()
+{
+ boost::thread x=boost::thread(do_nothing);
+ x.join();
+}
+
+boost::thread make_thread()
+{
+ return boost::thread(do_nothing);
+}
+
+void test_move_from_function_return()
+{
+ boost::thread x=make_thread();
+ x.join();
+}
+
+
+boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
+{
+ boost::unit_test_framework::test_suite* test =
+ BOOST_TEST_SUITE("Boost.Threads: thread move test suite");
+
+ test->add(BOOST_TEST_CASE(test_move_on_construction));
+ test->add(BOOST_TEST_CASE(test_move_from_function_return));
+ 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