]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright (C) 2014 Ian Forbed |
2 | // Copyright (C) 2014-2015 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_DETAIL_SCHEDULED_EXECUTOR_BASE_HPP | |
9 | #define BOOST_THREAD_EXECUTORS_DETAIL_SCHEDULED_EXECUTOR_BASE_HPP | |
10 | ||
11 | #include <boost/thread/concurrent_queues/sync_timed_queue.hpp> | |
12 | #include <boost/thread/executors/detail/priority_executor_base.hpp> | |
13 | #include <boost/thread/executors/work.hpp> | |
14 | #include <boost/thread/thread.hpp> | |
15 | ||
16 | #include <boost/atomic.hpp> | |
17 | #include <boost/function.hpp> | |
18 | ||
19 | #include <boost/config/abi_prefix.hpp> | |
20 | ||
21 | namespace boost | |
22 | { | |
23 | namespace executors | |
24 | { | |
25 | namespace detail | |
26 | { | |
27 | template <class Clock=chrono::steady_clock> | |
28 | class scheduled_executor_base : public priority_executor_base<concurrent::sync_timed_queue<executors::work_pq, Clock > > | |
29 | { | |
30 | public: | |
31 | typedef executors::work_pq work; | |
32 | typedef Clock clock; | |
33 | typedef typename clock::duration duration; | |
34 | typedef typename clock::time_point time_point; | |
35 | protected: | |
36 | ||
37 | scheduled_executor_base() {} | |
38 | public: | |
39 | ||
40 | ~scheduled_executor_base() | |
41 | { | |
42 | if(! this->closed()) | |
43 | { | |
44 | this->close(); | |
45 | } | |
46 | } | |
47 | ||
48 | void submit_at(work w, const time_point& tp) | |
49 | { | |
50 | this->_workq.push(boost::move(w), tp); | |
51 | } | |
52 | ||
53 | void submit_after(work w, const duration& dura) | |
54 | { | |
55 | this->_workq.push(boost::move(w), dura+clock::now()); | |
56 | } | |
57 | ||
58 | }; //end class | |
59 | ||
60 | } //end detail namespace | |
61 | } //end executors namespace | |
62 | } //end boost namespace | |
63 | ||
64 | #include <boost/config/abi_suffix.hpp> | |
65 | ||
66 | #endif |