Page MenuHomePhabricator

D3167.diff
No OneTemporary

D3167.diff

diff --git a/src/scheduler.h b/src/scheduler.h
--- a/src/scheduler.h
+++ b/src/scheduler.h
@@ -26,8 +26,7 @@
// CScheduler* s = new CScheduler();
// s->scheduleFromNow(doSomething, 11); // Assuming a: void doSomething() { }
// s->scheduleFromNow(std::bind(Class::func, this, argument), 3);
-// boost::thread* t = new boost::thread(boost::bind(CScheduler::serviceQueue,
-// s));
+// boost::thread* t = new boost::thread(std::bind(CScheduler::serviceQueue, s));
//
// ... then at program shutdown, clean up the thread running serviceQueue:
// t->interrupt();
@@ -41,8 +40,8 @@
CScheduler();
~CScheduler();
- typedef std::function<void(void)> Function;
- typedef std::function<bool(void)> Predicate;
+ typedef std::function<void()> Function;
+ typedef std::function<bool()> Predicate;
// Call func at/after time t
void schedule(Function f, boost::chrono::system_clock::time_point t =
@@ -51,10 +50,11 @@
// Convenience method: call f once deltaMilliSeconds from now
void scheduleFromNow(Function f, int64_t deltaMilliSeconds);
- // Another convenience method: call f approximately every deltaMilliSeconds
- // forever, starting deltaMilliSeconds from now. To be more precise: every
- // time f is finished, it is rescheduled to run deltaMilliSeconds later. If
- // you need more accurate scheduling, don't use this method.
+ // Another convenience method: call p approximately every deltaMilliSeconds
+ // forever, starting deltaMilliSeconds from now untill p returns false. To
+ // be more precise: every time p is finished, it is rescheduled to run
+ // deltaMilliSeconds later. If you need more accurate scheduling, don't use
+ // this method.
void scheduleEvery(Predicate p, int64_t deltaMilliSeconds);
// To keep things as simple as possible, there is no unschedule.
@@ -99,7 +99,7 @@
CScheduler *m_pscheduler;
CCriticalSection m_cs_callbacks_pending;
- std::list<std::function<void(void)>>
+ std::list<std::function<void()>>
m_callbacks_pending GUARDED_BY(m_cs_callbacks_pending);
bool m_are_callbacks_running GUARDED_BY(m_cs_callbacks_pending) = false;
@@ -109,11 +109,11 @@
public:
explicit SingleThreadedSchedulerClient(CScheduler *pschedulerIn)
: m_pscheduler(pschedulerIn) {}
- void AddToProcessQueue(std::function<void(void)> func);
+ void AddToProcessQueue(std::function<void()> func);
// Processes all remaining queue members on the calling thread, blocking
- // until queue is empty
- // Must be called after the CScheduler has no remaining processing threads!
+ // until queue is empty. Must be called after the CScheduler has no
+ // remaining processing threads!
void EmptyQueue();
size_t CallbacksPending();
diff --git a/src/scheduler.cpp b/src/scheduler.cpp
--- a/src/scheduler.cpp
+++ b/src/scheduler.cpp
@@ -7,8 +7,6 @@
#include <random.h>
#include <reverselock.h>
-#include <boost/bind.hpp>
-
#include <cassert>
#include <utility>
@@ -107,14 +105,14 @@
static void Repeat(CScheduler *s, CScheduler::Predicate p,
int64_t deltaMilliSeconds) {
if (p()) {
- s->scheduleFromNow(boost::bind(&Repeat, s, p, deltaMilliSeconds),
+ s->scheduleFromNow(std::bind(&Repeat, s, p, deltaMilliSeconds),
deltaMilliSeconds);
}
}
void CScheduler::scheduleEvery(CScheduler::Predicate p,
int64_t deltaMilliSeconds) {
- scheduleFromNow(boost::bind(&Repeat, this, p, deltaMilliSeconds),
+ scheduleFromNow(std::bind(&Repeat, this, p, deltaMilliSeconds),
deltaMilliSeconds);
}
@@ -141,19 +139,27 @@
// Try to avoid scheduling too many copies here, but if we
// accidentally have two ProcessQueue's scheduled at once its
// not a big deal.
- if (m_are_callbacks_running) return;
- if (m_callbacks_pending.empty()) return;
+ if (m_are_callbacks_running) {
+ return;
+ }
+ if (m_callbacks_pending.empty()) {
+ return;
+ }
}
m_pscheduler->schedule(
std::bind(&SingleThreadedSchedulerClient::ProcessQueue, this));
}
void SingleThreadedSchedulerClient::ProcessQueue() {
- std::function<void(void)> callback;
+ std::function<void()> callback;
{
LOCK(m_cs_callbacks_pending);
- if (m_are_callbacks_running) return;
- if (m_callbacks_pending.empty()) return;
+ if (m_are_callbacks_running) {
+ return;
+ }
+ if (m_callbacks_pending.empty()) {
+ return;
+ }
m_are_callbacks_running = true;
callback = std::move(m_callbacks_pending.front());
@@ -161,8 +167,8 @@
}
// RAII the setting of fCallbacksRunning and calling
- // MaybeScheduleProcessQueue
- // to ensure both happen safely even if callback() throws.
+ // MaybeScheduleProcessQueue to ensure both happen safely even if callback()
+ // throws.
struct RAIICallbacksRunning {
SingleThreadedSchedulerClient *instance;
explicit RAIICallbacksRunning(SingleThreadedSchedulerClient *_instance)
@@ -180,7 +186,7 @@
}
void SingleThreadedSchedulerClient::AddToProcessQueue(
- std::function<void(void)> func) {
+ std::function<void()> func) {
assert(m_pscheduler);
{

File Metadata

Mime Type
text/plain
Expires
Sat, Apr 26, 11:50 (2 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5573456
Default Alt Text
D3167.diff (5 KB)

Event Timeline