File indexing completed on 2025-01-30 10:01:11
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_THREAD_EXECUTORS_GENERIC_EXECUTOR_REF_HPP
0008 #define BOOST_THREAD_EXECUTORS_GENERIC_EXECUTOR_REF_HPP
0009
0010 #include <boost/thread/detail/config.hpp>
0011 #if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION && defined BOOST_THREAD_PROVIDES_EXECUTORS && defined BOOST_THREAD_USES_MOVE
0012
0013 #include <boost/thread/detail/delete.hpp>
0014 #include <boost/thread/detail/move.hpp>
0015 #include <boost/thread/executors/executor.hpp>
0016
0017 #include <boost/shared_ptr.hpp>
0018
0019 #include <boost/config/abi_prefix.hpp>
0020
0021 namespace boost
0022 {
0023 namespace executors
0024 {
0025
0026 template <class Executor>
0027 class executor_ref : public executor
0028 {
0029 Executor& ex;
0030 public:
0031
0032 typedef executors::work work;
0033
0034
0035 BOOST_THREAD_NO_COPYABLE(executor_ref)
0036 executor_ref(Executor& ex_) : ex(ex_) {}
0037
0038
0039
0040
0041
0042
0043
0044
0045 ~executor_ref() {}
0046
0047
0048
0049
0050
0051
0052 void close() { ex.close(); }
0053
0054
0055
0056
0057
0058 bool closed() { return ex.closed(); }
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 void submit(BOOST_THREAD_RV_REF(work) closure) {
0073 ex.submit(boost::move(closure));
0074 }
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 bool try_executing_one() { return ex.try_executing_one(); }
0091
0092 };
0093
0094 class generic_executor_ref
0095 {
0096 shared_ptr<executor> ex;
0097 public:
0098
0099 typedef executors::work work;
0100
0101 template<typename Executor>
0102 generic_executor_ref(Executor& ex_)
0103
0104 : ex( new executor_ref<Executor>(ex_) )
0105 {
0106 }
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 void close() { ex->close(); }
0118
0119
0120
0121
0122
0123 bool closed() { return ex->closed(); }
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 void submit(BOOST_THREAD_RV_REF(work) closure)
0142 {
0143 ex->submit(boost::move(closure));
0144 }
0145
0146 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0147 template <typename Closure>
0148 void submit(Closure & closure)
0149 {
0150
0151
0152 submit(work(closure));
0153 }
0154 #endif
0155 void submit(void (*closure)())
0156 {
0157 work w ((closure));
0158 submit(boost::move(w));
0159
0160 }
0161
0162 template <typename Closure>
0163 void submit(BOOST_THREAD_FWD_REF(Closure) closure)
0164 {
0165 work w((boost::forward<Closure>(closure)));
0166 submit(boost::move(w));
0167 }
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184 bool try_executing_one() { return ex->try_executing_one(); }
0185
0186
0187
0188
0189
0190
0191
0192
0193 template <typename Pred>
0194 bool reschedule_until(Pred const& pred)
0195 {
0196 do {
0197
0198 if ( ! try_executing_one())
0199 {
0200 return false;
0201 }
0202 } while (! pred());
0203 return true;
0204 }
0205
0206 };
0207 }
0208 using executors::executor_ref;
0209 using executors::generic_executor_ref;
0210 }
0211
0212 #include <boost/config/abi_suffix.hpp>
0213
0214 #endif
0215 #endif