12 #include <boost/bind.hpp> 25 #if BOOST_VERSION < 105000 26 static boost::system_time toPosixTime(
const boost::chrono::system_clock::time_point& t)
30 return boost::posix_time::from_time_t(0) + boost::posix_time::milliseconds(boost::chrono::duration_cast<boost::chrono::milliseconds>(t.time_since_epoch()).count());
58 #if BOOST_VERSION < 105000 67 boost::chrono::system_clock::time_point timeToWaitFor =
taskQueue.begin()->first;
68 if (
newTaskScheduled.wait_until<>(lock, timeToWaitFor) == boost::cv_status::timeout)
118 schedule(f, boost::chrono::system_clock::now() + boost::chrono::milliseconds(deltaMilliSeconds));
124 s->
scheduleFromNow(boost::bind(&Repeat, s, f, deltaMilliSeconds), deltaMilliSeconds);
129 scheduleFromNow(boost::bind(&Repeat,
this, f, deltaMilliSeconds), deltaMilliSeconds);
133 boost::chrono::system_clock::time_point &last)
const 152 LOCK(m_cs_callbacks_pending);
156 if (m_are_callbacks_running)
return;
157 if (m_callbacks_pending.empty())
return;
163 std::function<void (void)> callback;
165 LOCK(m_cs_callbacks_pending);
166 if (m_are_callbacks_running)
return;
167 if (m_callbacks_pending.empty())
return;
168 m_are_callbacks_running =
true;
170 callback = std::move(m_callbacks_pending.front());
171 m_callbacks_pending.pop_front();
176 struct RAIICallbacksRunning {
179 ~RAIICallbacksRunning() {
186 } raiicallbacksrunning(
this);
192 assert(m_pscheduler);
195 LOCK(m_cs_callbacks_pending);
196 m_callbacks_pending.emplace_back(std::move(func));
198 MaybeScheduleProcessQueue();
202 assert(!m_pscheduler->AreThreadsServicingQueue());
203 bool should_continue =
true;
204 while (should_continue) {
206 LOCK(m_cs_callbacks_pending);
207 should_continue = !m_callbacks_pending.empty();
Class used by CScheduler clients which may schedule multiple jobs which are required to be run serial...
void RandAddSeedSleep()
Add a little bit of randomness to the output of GetStrongRangBytes.
std::multimap< boost::chrono::system_clock::time_point, Function > taskQueue
void MaybeScheduleProcessQueue()
void scheduleEvery(Function f, int64_t deltaMilliSeconds)
void scheduleFromNow(Function f, int64_t deltaMilliSeconds)
void schedule(Function f, boost::chrono::system_clock::time_point t=boost::chrono::system_clock::now())
void stop(bool drain=false)
std::function< void(void)> Function
boost::condition_variable newTaskScheduled
An RAII-style reverse lock.
bool m_are_callbacks_running
boost::mutex newTaskMutex
CCriticalSection m_cs_callbacks_pending
bool AreThreadsServicingQueue() const
int nThreadsServicingQueue
size_t getQueueInfo(boost::chrono::system_clock::time_point &first, boost::chrono::system_clock::time_point &last) const
void AddToProcessQueue(std::function< void(void)> func)