Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / thread / thread_guard.hpp
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 thread_joiner in CCiA
8
9 #ifndef BOOST_THREAD_THREAD_GUARD_HPP
10 #define BOOST_THREAD_THREAD_GUARD_HPP
11
12 #include <boost/thread/detail/delete.hpp>
13 #include <boost/thread/detail/move.hpp>
14 #include <boost/thread/thread_functors.hpp>
15
16 #include <boost/config/abi_prefix.hpp>
17
18 namespace boost
19 {
20
21   /**
22    * Non-copyable RAII scoped thread guard joiner which join the thread if joinable when destroyed.
23    */
24   template <class CallableThread = join_if_joinable>
25   class thread_guard
26   {
27     thread& t_;
28   public:
29     BOOST_THREAD_NO_COPYABLE( thread_guard)
30
31     explicit thread_guard(thread& t) :
32     t_(t)
33     {
34     }
35     ~thread_guard()
36     {
37       CallableThread on_destructor;
38
39       on_destructor(t_);
40     }
41   };
42
43 }
44 #include <boost/config/abi_suffix.hpp>
45
46 #endif