Files
mongo/util/concurrency/msg.h

63 lines
1.7 KiB
C
Raw Normal View History

2010-05-18 17:21:11 -04:00
// @file msg.h - interthread message passing
/**
* Copyright (C) 2008 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,b
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
2010-05-19 11:56:58 -04:00
#include <deque>
2010-05-18 17:21:11 -04:00
#include "task.h"
namespace mongo {
namespace task {
2010-05-25 08:34:49 -04:00
typedef boost::function<void()> lam;
2010-07-28 11:06:04 -04:00
/** typical usage is: task::fork( serverPtr ); */
class Server : public Task {
2010-05-18 17:21:11 -04:00
public:
/** send a message to the port */
2010-05-25 08:34:49 -04:00
void send(lam);
2010-05-18 17:21:11 -04:00
Server(string name) : _name(name) { }
virtual ~Server() { }
2010-05-18 17:21:11 -04:00
2010-05-25 08:34:49 -04:00
/** send message but block until function completes */
void call(const lam&);
2010-05-25 08:34:49 -04:00
2010-06-29 15:52:35 -04:00
void requeue() { rq = true; }
2010-06-26 13:05:32 -04:00
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;
2010-05-18 17:21:11 -04:00
private:
2010-06-22 20:05:11 -04:00
virtual bool initClient() { return true; }
2010-05-24 08:06:05 -04:00
virtual string name() { return _name; }
2010-05-18 17:21:11 -04:00
void doWork();
2010-05-25 08:34:49 -04:00
deque<lam> d;
2010-05-19 11:56:58 -04:00
boost::mutex m;
boost::condition c;
2010-05-24 08:06:05 -04:00
string _name;
2010-06-29 15:52:35 -04:00
bool rq;
2010-05-18 17:21:11 -04:00
};
}
}