diff options
author | Dwight <dwight@10gen.com> | 2010-08-04 12:13:22 -0400 |
---|---|---|
committer | Dwight <dwight@10gen.com> | 2010-08-04 12:13:22 -0400 |
commit | 9c19c738a489e3dd50f2a3f7d6db6b2a49579b7d (patch) | |
tree | c883fce29ab569bad201adb687f3b4e7dab37ff9 | |
parent | c5ca6d00eec9d6b5c636fcd6e9fc85ee3b5a5aa9 (diff) | |
download | mongo-9c19c738a489e3dd50f2a3f7d6db6b2a49579b7d.tar.gz |
trying to fix SERVER-1483
-rw-r--r-- | util/concurrency/msg.h | 9 | ||||
-rw-r--r-- | util/concurrency/task.cpp | 29 |
2 files changed, 30 insertions, 8 deletions
diff --git a/util/concurrency/msg.h b/util/concurrency/msg.h index 4711ec35583..a5b07d3e2d8 100644 --- a/util/concurrency/msg.h +++ b/util/concurrency/msg.h @@ -27,13 +27,13 @@ namespace mongo { typedef boost::function<void()> lam; - /** typical usage is: task::fork( serverPtr ); */ + /** typical usage is: task::fork( new Server("threadname") ); */ class Server : public Task { public: /** send a message to the port */ void send(lam); - Server(string name) : _name(name) { } + Server(string name) : _name(name), rq(false) { } virtual ~Server() { } /** send message but block until function completes */ @@ -42,9 +42,8 @@ namespace mongo { void requeue() { rq = true; } protected: - /* this needn't be abstract; i left it that way for now so i remember - to call Client::initThread() when using in mongo... */ - virtual void starting() = 0; + /* REMINDER : for use in mongod, you will want to have this call Client::initThread(). */ + virtual void starting() { } private: virtual bool initClient() { return true; } diff --git a/util/concurrency/task.cpp b/util/concurrency/task.cpp index 6102666654e..05e43e582fd 100644 --- a/util/concurrency/task.cpp +++ b/util/concurrency/task.cpp @@ -117,7 +117,6 @@ namespace mongo { void Server::doWork() { starting(); - rq = false; while( 1 ) { lam f; try { @@ -134,7 +133,10 @@ namespace mongo { f(); if( rq ) { rq = false; - send(f); + { + boost::mutex::scoped_lock lk(m); + d.push_back(f); + } } } catch(std::exception& e) { log() << "Server::doWork() exception " << e.what() << endl; @@ -143,6 +145,27 @@ namespace mongo { } } } - + + static Server *s; + static void abc(int i) { + cout << "Hello " << i << endl; + s->requeue(); + } + class TaskUnitTest : public mongo::UnitTest { + public: + virtual void run() { + lam f = boost::bind(abc, 3); + //f(); + + s = new Server("unittest"); + fork(s); + s->send(f); + + sleepsecs(30); + cout <<" done" << endl; + + } + }; // not running. taskunittest; + } } |