82 lines
1.8 KiB
C++
82 lines
1.8 KiB
C++
/***************************************************************************
|
|
Fixed size Queue Class Header ( FixedQueue.h )
|
|
-----------------------------------------
|
|
begin : 2013/08/09
|
|
copyright : (C) 2005 SolutionBox Inc.
|
|
author : Development 1 Team
|
|
email : dev1@solbox.com
|
|
version : 3.2
|
|
|
|
CopyRight(C) 2005 SolutionBox Inc. All Rights reserved.
|
|
Redistribution and use in source and binary forms, with or with out
|
|
modification, are not permitted in outside of SolutionBox Inc.
|
|
***************************************************************************/
|
|
|
|
#ifndef __FIXED_SIZE_QUEUE_H__
|
|
#define __FIXED_SIZE_QUEUE_H__
|
|
|
|
#include <pthread.h>
|
|
#include <queue>
|
|
|
|
class CMutexLock
|
|
{
|
|
public:
|
|
CMutexLock(pthread_mutex_t * mutex);
|
|
~CMutexLock();
|
|
|
|
private:
|
|
pthread_mutex_t* m_plock;
|
|
};
|
|
|
|
class FixedQueueData
|
|
{
|
|
public:
|
|
size_t data_size;
|
|
char * data;
|
|
|
|
FixedQueueData ()
|
|
: data_size(0), data(NULL) {};
|
|
|
|
~FixedQueueData () { if(data) delete [] data; }
|
|
};
|
|
|
|
class CFixedQueue
|
|
{
|
|
public:
|
|
///@brief 생성자.
|
|
///@param bufferSize [in] 데이터 버퍼 크기
|
|
///@param qSzie [in] 큐의 크기
|
|
CFixedQueue (int bufferSize, int qSzie );
|
|
|
|
///@brief 소멸자.
|
|
~CFixedQueue();
|
|
|
|
///@brief 데이터 삽입
|
|
///@param buf [in] 데이터
|
|
///@param buffersize [in] 데이터 크기
|
|
///@return 0: 정상, 1:queue full, -1 : error
|
|
int Push(char* buf, size_t buffersize);
|
|
|
|
///@brief 데이터 추출
|
|
///@return 데이터 리턴(FIFO)
|
|
///@param buf [in] 데이터
|
|
///@param buffersize [in] 데이터 크기
|
|
///@return 0: 정상, 1: queue empty 나머지 : error
|
|
int Pop(char* buf, size_t buffersize);
|
|
|
|
|
|
protected:
|
|
///@brief 큐에 초기화
|
|
void ReleaseAll();
|
|
|
|
private:
|
|
int m_bufferSize;
|
|
int m_queueSize;
|
|
|
|
pthread_mutex_t m_mutex;
|
|
|
|
std::queue<FixedQueueData *> m_queue;
|
|
};
|
|
|
|
#endif // __FIXED_SIZE_QUEUE_H__
|