Changeset View
Changeset View
Standalone View
Standalone View
src/scheduler.h
// Copyright (c) 2015 The Bitcoin Core developers | // Copyright (c) 2015 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_SCHEDULER_H | #ifndef BITCOIN_SCHEDULER_H | ||||
#define BITCOIN_SCHEDULER_H | #define BITCOIN_SCHEDULER_H | ||||
// | // | ||||
// NOTE: | // NOTE: | ||||
// boost::thread / boost::function / boost::chrono should be ported to | // boost::thread / boost::chrono should be ported to | ||||
// std::thread / std::function / std::chrono when we support C++11. | // std::thread / std::chrono when we support C++11. | ||||
// | // | ||||
#include <boost/chrono/chrono.hpp> | #include <boost/chrono/chrono.hpp> | ||||
#include <boost/function.hpp> | |||||
#include <boost/thread.hpp> | #include <boost/thread.hpp> | ||||
#include <map> | #include <map> | ||||
// | // | ||||
// Simple class for background tasks that should be run periodically or once | // Simple class for background tasks that should be run periodically or once | ||||
// "after a while" | // "after a while" | ||||
// | // | ||||
// Usage: | // Usage: | ||||
Show All 11 Lines | |||||
// delete s; // Must be done after thread is interrupted/joined. | // delete s; // Must be done after thread is interrupted/joined. | ||||
// | // | ||||
class CScheduler { | class CScheduler { | ||||
public: | public: | ||||
CScheduler(); | CScheduler(); | ||||
~CScheduler(); | ~CScheduler(); | ||||
typedef boost::function<void(void)> Function; | typedef std::function<void(void)> Function; | ||||
// Call func at/after time t | // Call func at/after time t | ||||
void schedule(Function f, boost::chrono::system_clock::time_point t); | void schedule(Function f, boost::chrono::system_clock::time_point t); | ||||
// Convenience method: call f once deltaSeconds from now | // Convenience method: call f once deltaSeconds from now | ||||
void scheduleFromNow(Function f, int64_t deltaSeconds); | void scheduleFromNow(Function f, int64_t deltaSeconds); | ||||
// Another convenience method: call f approximately every deltaSeconds | // Another convenience method: call f approximately every deltaSeconds | ||||
Show All 34 Lines |