mirror of
https://github.com/jpd002/Play-.git
synced 2025-04-28 21:57:57 +03:00
41 lines
951 B
C++
41 lines
951 B
C++
#ifndef _MAILBOX_H_
|
|
#define _MAILBOX_H_
|
|
|
|
#include <functional>
|
|
#include <deque>
|
|
#include <boost/thread.hpp>
|
|
#include <boost/thread/condition.hpp>
|
|
|
|
class CMailBox
|
|
{
|
|
public:
|
|
CMailBox();
|
|
virtual ~CMailBox();
|
|
|
|
typedef std::tr1::function<void ()> FunctionType;
|
|
|
|
void SendCall(const FunctionType&, bool = false);
|
|
|
|
bool IsPending() const;
|
|
void ReceiveCall();
|
|
void WaitForCall();
|
|
void WaitForCall(unsigned int);
|
|
|
|
private:
|
|
struct MESSAGE
|
|
{
|
|
FunctionType function;
|
|
bool sync;
|
|
};
|
|
|
|
typedef std::deque<MESSAGE> FunctionCallQueue;
|
|
|
|
FunctionCallQueue m_calls;
|
|
boost::mutex m_waitMutex;
|
|
boost::mutex m_doneNotifyMutex;
|
|
boost::condition m_callFinished;
|
|
boost::condition m_waitCondition;
|
|
bool m_callDone;
|
|
};
|
|
|
|
#endif
|