00001 // @file msg.h - interthread message passing 00002 00019 #pragma once 00020 00021 #include <deque> 00022 #include "task.h" 00023 00024 namespace mongo { 00025 00026 namespace task { 00027 00028 typedef boost::function<void()> lam; 00029 00031 class Server : public Task { 00032 public: 00034 void send(lam); 00035 00036 Server(string name) : _name(name), rq(false) { } 00037 virtual ~Server() { } 00038 00040 void call(const lam&); 00041 00042 void requeue() { rq = true; } 00043 00044 protected: 00045 /* REMINDER : for use in mongod, you will want to have this call Client::initThread(). */ 00046 virtual void starting() { } 00047 00048 private: 00049 virtual bool initClient() { return true; } 00050 virtual string name() const { return _name; } 00051 void doWork(); 00052 deque<lam> d; 00053 boost::mutex m; 00054 boost::condition c; 00055 string _name; 00056 bool rq; 00057 }; 00058 00059 } 00060 00061 }