scheduling_adaptor.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (C) 2014 Ian Forbed
  2. // Copyright (C) 2014 Vicente J. Botet Escriba
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_THREAD_EXECUTORS_SCHEDULING_ADAPTOR_HPP
  8. #define BOOST_THREAD_EXECUTORS_SCHEDULING_ADAPTOR_HPP
  9. #include <boost/thread/executors/detail/scheduled_executor_base.hpp>
  10. #if defined(BOOST_MSVC)
  11. # pragma warning(push)
  12. # pragma warning(disable: 4355) // 'this' : used in base member initializer list
  13. #endif
  14. namespace boost
  15. {
  16. namespace executors
  17. {
  18. template <typename Executor>
  19. class scheduling_adaptor : public detail::scheduled_executor_base<>
  20. {
  21. private:
  22. Executor& _exec;
  23. thread _scheduler;
  24. public:
  25. scheduling_adaptor(Executor& ex)
  26. : super(),
  27. _exec(ex),
  28. _scheduler(&super::loop, this) {}
  29. ~scheduling_adaptor()
  30. {
  31. this->close();
  32. _scheduler.interrupt();
  33. _scheduler.join();
  34. }
  35. Executor& underlying_executor()
  36. {
  37. return _exec;
  38. }
  39. private:
  40. typedef detail::scheduled_executor_base<> super;
  41. }; //end class
  42. } //end executors
  43. using executors::scheduling_adaptor;
  44. } //end boost
  45. #if defined(BOOST_MSVC)
  46. # pragma warning(pop)
  47. #endif
  48. #endif