📄 tmq_queue.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 + -