File indexing completed on 2025-01-30 10:01:11
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_THREAD_INLINE_EXECUTOR_HPP
0010 #define BOOST_THREAD_INLINE_EXECUTOR_HPP
0011
0012 #include <boost/thread/detail/config.hpp>
0013 #if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION && defined BOOST_THREAD_PROVIDES_EXECUTORS && defined BOOST_THREAD_USES_MOVE
0014
0015 #include <exception> // std::terminate
0016 #include <boost/throw_exception.hpp>
0017 #include <boost/thread/detail/delete.hpp>
0018 #include <boost/thread/detail/move.hpp>
0019 #include <boost/thread/executors/work.hpp>
0020 #include <boost/thread/mutex.hpp>
0021 #include <boost/thread/lock_guard.hpp>
0022 #include <boost/thread/concurrent_queues/queue_op_status.hpp> // sync_queue_is_closed
0023
0024 #include <boost/config/abi_prefix.hpp>
0025
0026 namespace boost
0027 {
0028 namespace executors
0029 {
0030 class inline_executor
0031 {
0032 public:
0033
0034 typedef executors::work work;
0035 bool closed_;
0036 mutable mutex mtx_;
0037
0038
0039
0040
0041
0042 bool try_executing_one()
0043 {
0044 return false;
0045 }
0046
0047 public:
0048
0049 BOOST_THREAD_NO_COPYABLE(inline_executor)
0050
0051
0052
0053
0054
0055
0056 inline_executor()
0057 : closed_(false)
0058 {
0059 }
0060
0061
0062
0063
0064
0065 ~inline_executor()
0066 {
0067
0068 close();
0069 }
0070
0071
0072
0073
0074
0075 void close()
0076 {
0077 lock_guard<mutex> lk(mtx_);
0078 closed_ = true;
0079 }
0080
0081
0082
0083
0084 bool closed(lock_guard<mutex>& )
0085 {
0086 return closed_;
0087 }
0088 bool closed()
0089 {
0090 lock_guard<mutex> lk(mtx_);
0091 return closed(lk);
0092 }
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0107 template <typename Closure>
0108 void submit(Closure & closure)
0109 {
0110 {
0111 lock_guard<mutex> lk(mtx_);
0112 if (closed(lk)) BOOST_THROW_EXCEPTION( sync_queue_is_closed() );
0113 }
0114 try
0115 {
0116 closure();
0117 }
0118 catch (...)
0119 {
0120 std::terminate();
0121 return;
0122 }
0123 }
0124 #endif
0125 void submit(void (*closure)())
0126 {
0127 {
0128 lock_guard<mutex> lk(mtx_);
0129 if (closed(lk)) BOOST_THROW_EXCEPTION( sync_queue_is_closed() );
0130 }
0131 try
0132 {
0133 closure();
0134 }
0135 catch (...)
0136 {
0137 std::terminate();
0138 return;
0139 }
0140 }
0141
0142 template <typename Closure>
0143 void submit(BOOST_THREAD_FWD_REF(Closure) closure)
0144 {
0145 {
0146 lock_guard<mutex> lk(mtx_);
0147 if (closed(lk)) BOOST_THROW_EXCEPTION( sync_queue_is_closed() );
0148 }
0149 try
0150 {
0151 closure();
0152 }
0153 catch (...)
0154 {
0155 std::terminate();
0156 return;
0157 }
0158 }
0159
0160
0161
0162
0163
0164
0165 template <typename Pred>
0166 bool reschedule_until(Pred const& )
0167 {
0168 return false;
0169 }
0170
0171 };
0172 }
0173 using executors::inline_executor;
0174 }
0175
0176 #include <boost/config/abi_suffix.hpp>
0177
0178 #endif
0179 #endif