mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
trying to fix SERVER-1483
This commit is contained in:
parent
c5ca6d00ee
commit
9c19c738a4
@ -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; }
|
||||
|
@ -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;
|
||||
@ -144,5 +146,26 @@ 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;
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user