⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmq_queue.h

📁 Generic template class library for message queue implementation, uses pthread mutex.
💻 H
字号:
#ifndef __TMQ_QUEUE_H__#define __TMQ_QUEUE_H__#include <JTC/JTC.h>#include <cassert>#include "CountingSemaphore.h"template <class T, class Container>class TMQ_Queue{  public:    void post(        T& theData    )    {	theMutex.lock();	theContainer.push( theData );	theSemaphore.post();	theMutex.unlock();    }    bool get(        T& theData,         bool block = true    )    {	if ( block == true )	{	    theSemaphore.wait();	}	else	{	    bool theWaitResult;	    theWaitResult = theSemaphore.trywait();	    return theWaitResult;	}	theMutex.lock();	assert( theContainer.size() > 0 );	theData = theContainer.front();	theContainer.pop();	theMutex.unlock();	return true;    }  private:    JTCRecursiveMutex theMutex;    Container theContainer;    CountingSemaphore theSemaphore;};#endif /* __TMQ_QUEUE_H__ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -