📄 bufferqueue.h
字号:
// BufferQueue.h: interface for the BufferQueue class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_BUFFERQUEUE_H__9DF6BAD7_769D_4482_BC1E_8CDDDED73C00__INCLUDED_)
#define AFX_BUFFERQUEUE_H__9DF6BAD7_769D_4482_BC1E_8CDDDED73C00__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Buffer.h"
#ifdef WIN32
#include <Process.h>
#include <afxmt.h>
#else
#include <pthread.h>
#endif
#define BUFFERNUM 5
class BufferQueue
{
public:
BufferQueue();
virtual ~BufferQueue();
Buffer *getReadBuffer();
Buffer *getWriteBuffer();
bool moveReadBuffer(bool);
bool moveWriteBuffer(bool);
void invalidate();
protected:
Buffer buffers[BUFFERNUM];
int readPos;
int num;
bool validFlag;
/*Define two events to synchronize between input thread and output thread
**hFullEvent is defined for the circumstance when the buffer queue is full
**and input thread is waiting for output thread to retrieve data from buffer queue
**hEmptyEvent is defined for the circumstance when the buffer queue is empty
**and output thread is waiting for input thread puts data in buffer queue
*/
#ifdef WIN32
HANDLE hFullEvent; //event on buffer queue full
HANDLE hEmptyEvent; //event on buffer queue empty
#else
#endif
#ifdef WIN32
CCriticalSection accessMutex; //Synchronize access to the buffer queue
#else
pthread_mutex_t accessMutex = PTHREAD_MUTEX_INITIALIZER;
#endif
int lockAccessMutex();
int unLockAccessMutex();
static int numOfBuffers(){return BUFFERNUM;}
};
#endif // !defined(AFX_BUFFERQUEUE_H__9DF6BAD7_769D_4482_BC1E_8CDDDED73C00__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -