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 | ||||
#include <sync.h> | #include <sync.h> | ||||
// | |||||
// NOTE: | |||||
// boost::thread should be ported to std::thread | |||||
// when we support C++11. | |||||
// | |||||
#include <condition_variable> | #include <condition_variable> | ||||
#include <functional> | #include <functional> | ||||
#include <list> | #include <list> | ||||
#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: | ||||
// | // | ||||
// CScheduler* s = new CScheduler(); | // CScheduler* s = new CScheduler(); | ||||
// // Assuming a: void doSomething() { } | // // Assuming a: void doSomething() { } | ||||
// s->scheduleFromNow(doSomething, std::chrono::milliseconds{11}); | // s->scheduleFromNow(doSomething, std::chrono::milliseconds{11}); | ||||
// s->scheduleFromNow([=] { this->func(argument); }, | // s->scheduleFromNow([=] { this->func(argument); }, | ||||
// std::chrono::milliseconds{3}); | // std::chrono::milliseconds{3}); | ||||
// boost::thread *t = new boost::thread(std::bind(CScheduler::serviceQueue, s)); | // std::thread *t = new std::thread([?] { s->serviceQueue(); }); | ||||
// | // | ||||
// ... then at program shutdown, make sure to call stop() to clean up the | // ... then at program shutdown, make sure to call stop() to clean up the | ||||
// thread(s) running serviceQueue: | // thread(s) running serviceQueue: | ||||
// s->stop(); | // s->stop(); | ||||
// t->join(); | // t->join(); | ||||
// delete t; | // delete t; | ||||
// delete s; // Must be done after thread is interrupted/joined. | // delete s; // Must be done after thread is interrupted/joined. | ||||
// | // | ||||
▲ Show 20 Lines • Show All 108 Lines • Show Last 20 Lines |