2007-12-01 04:08:34 +00:00
|
|
|
#ifndef _MAILBOX_H_
|
|
|
|
#define _MAILBOX_H_
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <deque>
|
|
|
|
#include <boost/thread.hpp>
|
2008-12-15 02:57:21 +00:00
|
|
|
#include <boost/thread/condition.hpp>
|
2007-12-01 04:08:34 +00:00
|
|
|
|
|
|
|
class CMailBox
|
|
|
|
{
|
|
|
|
public:
|
2012-03-11 20:06:14 +00:00
|
|
|
CMailBox();
|
|
|
|
virtual ~CMailBox();
|
2007-12-01 04:08:34 +00:00
|
|
|
|
2012-03-11 20:06:14 +00:00
|
|
|
typedef std::function<void ()> FunctionType;
|
2007-12-01 04:08:34 +00:00
|
|
|
|
2012-03-11 20:06:14 +00:00
|
|
|
void SendCall(const FunctionType&, bool = false);
|
2007-12-01 04:08:34 +00:00
|
|
|
|
2012-03-11 20:06:14 +00:00
|
|
|
bool IsPending() const;
|
|
|
|
void ReceiveCall();
|
|
|
|
void WaitForCall();
|
|
|
|
void WaitForCall(unsigned int);
|
2007-12-01 04:08:34 +00:00
|
|
|
|
|
|
|
private:
|
2008-12-13 00:30:38 +00:00
|
|
|
struct MESSAGE
|
|
|
|
{
|
|
|
|
FunctionType function;
|
|
|
|
bool sync;
|
|
|
|
};
|
|
|
|
|
2012-03-11 20:06:14 +00:00
|
|
|
typedef std::deque<MESSAGE> FunctionCallQueue;
|
2007-12-01 04:08:34 +00:00
|
|
|
|
2012-03-11 20:06:14 +00:00
|
|
|
FunctionCallQueue m_calls;
|
|
|
|
boost::mutex m_waitMutex;
|
|
|
|
boost::mutex m_doneNotifyMutex;
|
|
|
|
boost::condition m_callFinished;
|
|
|
|
boost::condition m_waitCondition;
|
|
|
|
bool m_callDone;
|
2007-12-01 04:08:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|