BufferQueue.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <pthread.h>
  3. struct QueueMsg {
  4. int type;
  5. int len;
  6. unsigned char * buf;
  7. struct QueueMsg * next;
  8. };
  9. class BufferQueue{
  10. public:
  11. BufferQueue();
  12. virtual ~BufferQueue();
  13. public:
  14. void ClearBufferQueue();
  15. void WriteQueue(int type, unsigned char * msgBuf, int msgLen);
  16. int ReadQueue(int *pType, unsigned char ** msgBuf, int * msgLen);
  17. int GetQuequeSize();
  18. void SetQueueCond(pthread_cond_t * cond);
  19. void InitThread();
  20. bool IsExitedThread(pthread_t thread_id);
  21. void ExitedThread(pthread_t thread_id);
  22. void WakeUpThread(pthread_t thread_id);
  23. private:
  24. void ClearInnerBufferQueue(pthread_mutex_t * p_mutex,
  25. QueueMsg ** pQueueHead,
  26. QueueMsg ** pQueueTail,
  27. int * pQueueSize);
  28. void WriteInnerQueue(pthread_mutex_t * p_mutex,
  29. unsigned char * msgBuf,
  30. int msgLen,
  31. QueueMsg ** pQueueHead,
  32. QueueMsg ** pQueueTail,
  33. int * pQueueSize,
  34. int type);
  35. int ReadInnerQueue(pthread_mutex_t * p_mutex,
  36. unsigned char ** msgBuf,
  37. int * msgLen,
  38. QueueMsg ** pQueueHead,
  39. QueueMsg ** pQueueTail,
  40. int * pQueueSize,
  41. int *pType);
  42. private:
  43. pthread_mutex_t mQueueMutex;
  44. QueueMsg * mPtrQueueHead;
  45. QueueMsg * mPtrQueueTail;
  46. // pthread_cond_t* mPtrCondForQueue;
  47. int mQueueSize;
  48. pthread_mutex_t mThreadMutex;
  49. pthread_cond_t mThreadCond;
  50. bool mExitedThread;
  51. };