1、BlockingQueue类
#include "thread/Critical.h"
#include "thread/Codition.h"
#include "thread/Lock.h"
#include <vector>
using namespace std;
const unsigned int DEFAULT_MAX_SIZE = 100;
template<class T>
class BlockingQueue
{
public:
BlockingQueue(unsigned int uMaxSize = DEFAULT_MAX_SIZE);
~BlockingQueue(void);
public:
bool Add( T item);
bool Put( T item);
T Take();//获取不到数据,一直阻塞
bool Poll(unsigned long time, T& item);//time单位ms,time时间内获取不到队列数据,返回NULL
private:
vector<T> m_vecQueue;
CCodition m_oGetCondition;
CCodition m_oSetCondition;
CCritical m_oCriticalSection;
unsigned int m_uMaxSize;
};
template<class T>
BlockingQueue<T>::BlockingQueue( unsigned int uMaxSize )
:m_uMaxSize(uMaxSize)
{
}
template<class T>
BlockingQueue<T>::~BlockingQueue( void )
{
m_vecQueue.clear();
}
template<class T>
bool BlockingQueue<T>::Add( T i