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