From a89c4f01ad02b70cd76528bc61ae682f62addd55 Mon Sep 17 00:00:00 2001 From: Anthony Williams Date: Sat, 15 Dec 2007 22:36:43 +0000 Subject: [PATCH] explicit move functions for threads, with a test [SVN r42087] --- include/boost/thread/detail/move.hpp | 6 ---- include/boost/thread/pthread/thread.hpp | 11 +++++++ include/boost/thread/win32/thread.hpp | 10 ++++++ test/Jamfile.v2 | 1 + test/test_move_function.cpp | 42 +++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 test/test_move_function.cpp diff --git a/include/boost/thread/detail/move.hpp b/include/boost/thread/detail/move.hpp index 4c90abc3..011ae4ea 100644 --- a/include/boost/thread/detail/move.hpp +++ b/include/boost/thread/detail/move.hpp @@ -23,12 +23,6 @@ namespace boost return &t; } }; - - template - thread_move_t thread_move(T& t) - { - return thread_move_t(t); - } } } diff --git a/include/boost/thread/pthread/thread.hpp b/include/boost/thread/pthread/thread.hpp index ad497230..f0df9476 100644 --- a/include/boost/thread/pthread/thread.hpp +++ b/include/boost/thread/pthread/thread.hpp @@ -169,6 +169,17 @@ namespace boost bool interruption_requested() const; }; + inline detail::thread_move_t move(thread& x) + { + return x.move(); + } + + inline detail::thread_move_t move(detail::thread_move_t x) + { + return x; + } + + template struct thread::thread_data >: detail::thread_data_base diff --git a/include/boost/thread/win32/thread.hpp b/include/boost/thread/win32/thread.hpp index 14d93f83..574eacaa 100644 --- a/include/boost/thread/win32/thread.hpp +++ b/include/boost/thread/win32/thread.hpp @@ -245,6 +245,16 @@ namespace boost bool interruption_requested() const; }; + inline detail::thread_move_t move(thread& x) + { + return x.move(); + } + + inline detail::thread_move_t move(detail::thread_move_t x) + { + return x; + } + template struct thread::thread_data >: detail::thread_data_base diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 4ff2d48f..022e5574 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -36,6 +36,7 @@ rule thread-run ( sources ) test-suite "threads" : [ thread-run test_thread.cpp ] [ thread-run test_thread_move.cpp ] + [ thread-run test_move_function.cpp ] [ thread-run test_mutex.cpp ] [ thread-run test_condition_notify_one.cpp ] [ thread-run test_condition_timed_wait_times_out.cpp ] diff --git a/test/test_move_function.cpp b/test/test_move_function.cpp new file mode 100644 index 00000000..8e71dd7a --- /dev/null +++ b/test/test_move_function.cpp @@ -0,0 +1,42 @@ +// 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 +#include + +void do_nothing() +{} + +void test_thread_move_from_lvalue_on_construction() +{ + boost::thread src(do_nothing); + boost::thread::id src_id=src.get_id(); + boost::thread dest=boost::move(src); + boost::thread::id dest_id=dest.get_id(); + BOOST_CHECK(src_id==dest_id); + BOOST_CHECK(src.get_id()==boost::thread::id()); + dest.join(); +} + +boost::thread make_thread() +{ + return boost::thread(do_nothing); +} + +void test_thread_move_from_function_return() +{ + boost::thread x=boost::move(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_thread_move_from_lvalue_on_construction)); + test->add(BOOST_TEST_CASE(test_thread_move_from_function_return)); + return test; +}