thread_functors.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. template <class Thread>
  19. void operator()(Thread& t)
  20. {
  21. t.detach();
  22. }
  23. };
  24. struct detach_if_joinable
  25. {
  26. template <class Thread>
  27. void operator()(Thread& t)
  28. {
  29. if (t.joinable())
  30. {
  31. t.detach();
  32. }
  33. }
  34. };
  35. struct join_if_joinable
  36. {
  37. template <class Thread>
  38. void operator()(Thread& t)
  39. {
  40. if (t.joinable())
  41. {
  42. t.join();
  43. }
  44. }
  45. };
  46. #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
  47. struct interrupt_and_join_if_joinable
  48. {
  49. template <class Thread>
  50. void operator()(Thread& t)
  51. {
  52. if (t.joinable())
  53. {
  54. t.interrupt();
  55. t.join();
  56. }
  57. }
  58. };
  59. #endif
  60. }
  61. #include <boost/config/abi_suffix.hpp>
  62. #endif