2007-12-01 04:08:34 +00:00
|
|
|
#ifndef _MAILBOX_H_
|
|
|
|
#define _MAILBOX_H_
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <deque>
|
|
|
|
#include <boost/thread.hpp>
|
|
|
|
|
|
|
|
class CMailBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CMailBox();
|
|
|
|
virtual ~CMailBox();
|
|
|
|
|
|
|
|
typedef std::tr1::function<void ()> FunctionType;
|
|
|
|
|
2007-12-09 02:28:28 +00:00
|
|
|
void SendCall(const FunctionType&, bool = false);
|
2007-12-01 04:08:34 +00:00
|
|
|
|
|
|
|
bool IsPending() const;
|
|
|
|
void ReceiveCall();
|
|
|
|
void WaitForCall();
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::deque<FunctionType> FunctionCallQueue;
|
|
|
|
|
|
|
|
FunctionCallQueue m_calls;
|
|
|
|
boost::mutex m_waitMutex;
|
2007-12-09 02:28:28 +00:00
|
|
|
boost::mutex m_doneNotifyMutex;
|
2007-12-01 04:08:34 +00:00
|
|
|
boost::condition m_callFinished;
|
|
|
|
boost::condition m_waitCondition;
|
2007-12-09 02:28:28 +00:00
|
|
|
bool m_callDone;
|
2007-12-01 04:08:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|