scheduling_adaptor.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/detail/config.hpp>
  10. #if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION && defined BOOST_THREAD_PROVIDES_EXECUTORS && defined BOOST_THREAD_USES_MOVE
  11. #include <boost/thread/executors/detail/scheduled_executor_base.hpp>
  12. #if defined(BOOST_MSVC)
  13. # pragma warning(push)
  14. # pragma warning(disable: 4355) // 'this' : used in base member initializer list
  15. #endif
  16. namespace boost
  17. {
  18. namespace executors
  19. {
  20. template <typename Executor>
  21. class scheduling_adaptor : public detail::scheduled_executor_base<>
  22. {
  23. private:
  24. Executor& _exec;
  25. thread _scheduler;
  26. public:
  27. scheduling_adaptor(Executor& ex)
  28. : super(),
  29. _exec(ex),
  30. _scheduler(&super::loop, this) {}
  31. ~scheduling_adaptor()
  32. {
  33. this->close();
  34. _scheduler.interrupt();
  35. _scheduler.join();
  36. }
  37. Executor& underlying_executor()
  38. {
  39. return _exec;
  40. }
  41. private:
  42. typedef detail::scheduled_executor_base<> super;
  43. }; //end class
  44. } //end executors
  45. using executors::scheduling_adaptor;
  46. } //end boost
  47. #if defined(BOOST_MSVC)
  48. # pragma warning(pop)
  49. #endif
  50. #endif
  51. #endif