scheduled_executor_base.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef BOOST_THREAD_EXECUTORS_DETAIL_SCHEDULED_EXECUTOR_BASE_HPP
  8. #define BOOST_THREAD_EXECUTORS_DETAIL_SCHEDULED_EXECUTOR_BASE_HPP
  9. #include <boost/thread/concurrent_queues/sync_timed_queue.hpp>
  10. #include <boost/thread/executors/detail/priority_executor_base.hpp>
  11. #include <boost/thread/executors/work.hpp>
  12. #include <boost/thread/thread.hpp>
  13. #include <boost/atomic.hpp>
  14. #include <boost/function.hpp>
  15. #include <boost/config/abi_prefix.hpp>
  16. namespace boost
  17. {
  18. namespace executors
  19. {
  20. namespace detail
  21. {
  22. template <class Clock=chrono::steady_clock>
  23. class scheduled_executor_base : public priority_executor_base<concurrent::sync_timed_queue<executors::work_pq, Clock > >
  24. {
  25. public:
  26. typedef executors::work_pq work;
  27. typedef Clock clock;
  28. typedef typename clock::duration duration;
  29. typedef typename clock::time_point time_point;
  30. protected:
  31. scheduled_executor_base() {}
  32. public:
  33. ~scheduled_executor_base()
  34. {
  35. if(! this->closed())
  36. {
  37. this->close();
  38. }
  39. }
  40. void submit_at(work w, const time_point& tp)
  41. {
  42. this->_workq.push(boost::move(w), tp);
  43. }
  44. void submit_after(work w, const duration& dura)
  45. {
  46. this->_workq.push(boost::move(w), dura+clock::now());
  47. }
  48. }; //end class
  49. } //end detail namespace
  50. } //end executors namespace
  51. } //end boost namespace
  52. #include <boost/config/abi_suffix.hpp>
  53. #endif