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