1 // Distributed under the Boost Software License, Version 1.0. (See 2 // accompanying file LICENSE_1_0.txt or copy at 3 // http://www.boost.org/LICENSE_1_0.txt) 4 // (C) Copyright 2009-2012 Anthony Williams 5 // (C) Copyright 2012 Vicente J. Botet Escriba 6 7 // Based on the Anthony's idea of scoped_thread in CCiA 8 9 #ifndef BOOST_THREAD_THREAD_FUNCTORS_HPP 10 #define BOOST_THREAD_THREAD_FUNCTORS_HPP 11 12 #include <boost/thread/detail/config.hpp> 13 #include <boost/thread/detail/delete.hpp> 14 #include <boost/thread/detail/move.hpp> 15 #include <boost/thread/thread_only.hpp> 16 17 #include <boost/config/abi_prefix.hpp> 18 19 namespace boost 20 { 21 22 struct detach 23 { 24 template <class Thread> operator ()boost::detach25 void operator()(Thread& t) 26 { 27 t.detach(); 28 } 29 }; 30 31 struct detach_if_joinable 32 { 33 template <class Thread> operator ()boost::detach_if_joinable34 void operator()(Thread& t) 35 { 36 if (t.joinable()) 37 { 38 t.detach(); 39 } 40 } 41 }; 42 43 struct join_if_joinable 44 { 45 template <class Thread> operator ()boost::join_if_joinable46 void operator()(Thread& t) 47 { 48 if (t.joinable()) 49 { 50 t.join(); 51 } 52 } 53 }; 54 55 #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS 56 struct interrupt_and_join_if_joinable 57 { 58 template <class Thread> operator ()boost::interrupt_and_join_if_joinable59 void operator()(Thread& t) 60 { 61 if (t.joinable()) 62 { 63 t.interrupt(); 64 t.join(); 65 } 66 } 67 }; 68 #endif 69 } 70 #include <boost/config/abi_suffix.hpp> 71 72 #endif 73