Skip to content

Commit 73296f5

Browse files
committed
CScheduler boost->std::function, use millisecs for times, not secs
1 parent 72fb515 commit 73296f5

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2288,7 +2288,7 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c
22882288
threadMessageHandler = std::thread(&TraceThread<std::function<void()> >, "msghand", std::function<void()>(std::bind(&CConnman::ThreadMessageHandler, this)));
22892289

22902290
// Dump network addresses
2291-
scheduler.scheduleEvery(boost::bind(&CConnman::DumpData, this), DUMP_ADDRESSES_INTERVAL);
2291+
scheduler.scheduleEvery(std::bind(&CConnman::DumpData, this), DUMP_ADDRESSES_INTERVAL * 1000);
22922292

22932293
return true;
22942294
}

src/scheduler.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,20 @@ void CScheduler::schedule(CScheduler::Function f, boost::chrono::system_clock::t
104104
newTaskScheduled.notify_one();
105105
}
106106

107-
void CScheduler::scheduleFromNow(CScheduler::Function f, int64_t deltaSeconds)
107+
void CScheduler::scheduleFromNow(CScheduler::Function f, int64_t deltaMilliSeconds)
108108
{
109-
schedule(f, boost::chrono::system_clock::now() + boost::chrono::seconds(deltaSeconds));
109+
schedule(f, boost::chrono::system_clock::now() + boost::chrono::milliseconds(deltaMilliSeconds));
110110
}
111111

112-
static void Repeat(CScheduler* s, CScheduler::Function f, int64_t deltaSeconds)
112+
static void Repeat(CScheduler* s, CScheduler::Function f, int64_t deltaMilliSeconds)
113113
{
114114
f();
115-
s->scheduleFromNow(boost::bind(&Repeat, s, f, deltaSeconds), deltaSeconds);
115+
s->scheduleFromNow(boost::bind(&Repeat, s, f, deltaMilliSeconds), deltaMilliSeconds);
116116
}
117117

118-
void CScheduler::scheduleEvery(CScheduler::Function f, int64_t deltaSeconds)
118+
void CScheduler::scheduleEvery(CScheduler::Function f, int64_t deltaMilliSeconds)
119119
{
120-
scheduleFromNow(boost::bind(&Repeat, this, f, deltaSeconds), deltaSeconds);
120+
scheduleFromNow(boost::bind(&Repeat, this, f, deltaMilliSeconds), deltaMilliSeconds);
121121
}
122122

123123
size_t CScheduler::getQueueInfo(boost::chrono::system_clock::time_point &first,

src/scheduler.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
// boost::thread / boost::function / boost::chrono should be ported to
1111
// std::thread / std::function / std::chrono when we support C++11.
1212
//
13-
#include <boost/function.hpp>
1413
#include <boost/chrono/chrono.hpp>
1514
#include <boost/thread.hpp>
1615
#include <map>
@@ -23,7 +22,7 @@
2322
//
2423
// CScheduler* s = new CScheduler();
2524
// s->scheduleFromNow(doSomething, 11); // Assuming a: void doSomething() { }
26-
// s->scheduleFromNow(boost::bind(Class::func, this, argument), 3);
25+
// s->scheduleFromNow(std::bind(Class::func, this, argument), 3);
2726
// boost::thread* t = new boost::thread(boost::bind(CScheduler::serviceQueue, s));
2827
//
2928
// ... then at program shutdown, clean up the thread running serviceQueue:
@@ -39,20 +38,20 @@ class CScheduler
3938
CScheduler();
4039
~CScheduler();
4140

42-
typedef boost::function<void(void)> Function;
41+
typedef std::function<void(void)> Function;
4342

4443
// Call func at/after time t
4544
void schedule(Function f, boost::chrono::system_clock::time_point t);
4645

4746
// Convenience method: call f once deltaSeconds from now
48-
void scheduleFromNow(Function f, int64_t deltaSeconds);
47+
void scheduleFromNow(Function f, int64_t deltaMilliSeconds);
4948

5049
// Another convenience method: call f approximately
5150
// every deltaSeconds forever, starting deltaSeconds from now.
5251
// To be more precise: every time f is finished, it
5352
// is rescheduled to run deltaSeconds later. If you
5453
// need more accurate scheduling, don't use this method.
55-
void scheduleEvery(Function f, int64_t deltaSeconds);
54+
void scheduleEvery(Function f, int64_t deltaMilliSeconds);
5655

5756
// To keep things as simple as possible, there is no unschedule.
5857

0 commit comments

Comments
 (0)