MongoDB  2.7.0
task.h
1 // @file task.h
2 
31 #pragma once
32 
33 #include "mongo/util/background.h"
34 
35 namespace mongo {
36 
37  namespace task {
38 
42  class Task : private BackgroundJob {
43  protected:
44  virtual void setUp(); // Override to perform any do-once work for the task.
45  virtual void doWork() = 0; // implement the task here.
46  virtual string name() const = 0; // name the thread
47  public:
48  Task();
49 
53  void halt();
54  private:
55  unsigned n, repeat;
56  friend void fork(Task* t);
57  friend void repeat(Task* t, unsigned millis);
58  virtual void run();
59  //virtual void ending() { }
60  void begin();
61  };
62 
64  void fork(Task *t);
65 
67  void repeat(Task *t, unsigned millis);
68 
69  /*** Example ***
70  inline void sample() {
71  class Sample : public Task {
72  public:
73  int result;
74  virtual void doWork() { result = 1234; }
75  Sample() : result(0) { }
76  };
77  shared_ptr<Sample> q( new Sample() );
78  fork(q);
79  cout << q->result << endl; // could print 1234 or 0.
80  }
81  */
82 
83  }
84 
85 }
void halt()
for a repeating task, stop after current invocation ends.
Definition: task.cpp:47
friend void fork(Task *t)
run once
Definition: task.cpp:74
Background thread dispatching.
Definition: background.h:44
abstraction around threads.
Definition: task.h:42