diff options
Diffstat (limited to 'util/background.h')
-rw-r--r-- | util/background.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/util/background.h b/util/background.h index 861df9b..496a1f4 100644 --- a/util/background.h +++ b/util/background.h @@ -17,6 +17,8 @@ #pragma once +#include "concurrency/spin_lock.h" + namespace mongo { /** @@ -102,5 +104,52 @@ namespace mongo { void jobBody( boost::shared_ptr<JobStatus> status ); }; + + /** + * these run "roughly" every minute + * instantiate statically + * class MyTask : public PeriodicTask { + * public: + * virtual string name() const { return "MyTask; " } + * virtual void doWork() { log() << "hi" << endl; } + * } myTask; + */ + class PeriodicTask { + public: + PeriodicTask(); + virtual ~PeriodicTask(); + + virtual void taskDoWork() = 0; + virtual string taskName() const = 0; + + class Runner : public BackgroundJob { + public: + virtual ~Runner(){} + + virtual string name() const { return "PeriodicTask::Runner"; } + + virtual void run(); + + void add( PeriodicTask* task ); + void remove( PeriodicTask* task ); + + private: + + SpinLock _lock; + + // these are NOT owned by Runner + // Runner will not delete these + // this never gets smaller + // only fields replaced with nulls + vector<PeriodicTask*> _tasks; + + }; + + static Runner* theRunner; + + }; + + + } // namespace mongo |