thread_functors.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // Based on the Anthony's idea of scoped_thread in CCiA
  7. #ifndef BOOST_THREAD_THREAD_FUNCTORS_HPP
  8. #define BOOST_THREAD_THREAD_FUNCTORS_HPP
  9. #include <boost/thread/detail/config.hpp>
  10. #include <boost/thread/detail/delete.hpp>
  11. #include <boost/thread/detail/move.hpp>
  12. #include <boost/thread/thread_only.hpp>
  13. #include <boost/config/abi_prefix.hpp>
  14. namespace boost
  15. {
  16. struct detach
  17. {
  18. void operator()(thread& t)
  19. {
  20. t.detach();
  21. }
  22. };
  23. struct join_if_joinable
  24. {
  25. void operator()(thread& t)
  26. {
  27. if (t.joinable())
  28. {
  29. t.join();
  30. }
  31. }
  32. };
  33. #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
  34. struct interrupt_and_join_if_joinable
  35. {
  36. void operator()(thread& t)
  37. {
  38. t.interrupt();
  39. if (t.joinable())
  40. {
  41. t.join();
  42. }
  43. }
  44. };
  45. #endif
  46. }
  47. #include <boost/config/abi_suffix.hpp>
  48. #endif