]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/include/boost/thread/executors/detail/priority_executor_base.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / thread / include / boost / thread / executors / detail / priority_executor_base.hpp
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_DETAIL_PRIORITY_EXECUTOR_BASE_HPP
9 #define BOOST_THREAD_EXECUTORS_DETAIL_PRIORITY_EXECUTOR_BASE_HPP
10
11 #include <boost/atomic.hpp>
12 #include <boost/function.hpp>
13 #include <boost/thread/thread.hpp>
14 #include <boost/thread/concurrent_queues/sync_timed_queue.hpp>
15 #include <boost/thread/executors/work.hpp>
16
17 namespace boost
18 {
19 namespace executors
20 {
21 namespace detail
22 {
23 template <class Queue>
24 class priority_executor_base
25 {
26 public:
27 //typedef boost::function<void()> work;
28 typedef executors::work_pq work;
29 protected:
30 typedef Queue queue_type;
31 queue_type _workq;
32
33 priority_executor_base() {}
34 public:
35
36 ~priority_executor_base()
37 {
38 if(!closed())
39 {
40 this->close();
41 }
42 }
43
44 void close()
45 {
46 _workq.close();
47 }
48
49 bool closed()
50 {
51 return _workq.closed();
52 }
53
54 void loop()
55 {
56 try
57 {
58 for(;;)
59 {
60 work task;
61 queue_op_status st = _workq.wait_pull(task);
62 if (st == queue_op_status::closed) return;
63 task();
64 }
65 }
66 catch (...)
67 {
68 std::terminate();
69 return;
70 }
71 }
72 }; //end class
73
74 } //end detail namespace
75 } //end executors namespace
76 } //end boost namespace
77 #endif