tr_queue.h 808 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef _TR_QUEUE_H_
  2. #define _TR_QUEUE_H_
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <string>
  7. #include <pthread.h>
  8. #include <iostream>
  9. using namespace std;
  10. class tr_queue
  11. {
  12. public:
  13. tr_queue(unsigned int size);
  14. ~tr_queue();
  15. bool initialize();
  16. unsigned int get(unsigned char *buffer, unsigned int len);
  17. unsigned int put(const unsigned char *buffer, unsigned int len);
  18. inline void clean()
  19. {
  20. m_nin = m_nout = 0;
  21. }
  22. inline unsigned int get_datalen() const
  23. {
  24. return m_nin - m_nout;
  25. }
  26. private:
  27. inline bool is_power_of_2(unsigned long n)
  28. {
  29. return (n != 0 && ((n & (n - 1)) == 0));
  30. }
  31. inline unsigned long roundup_power_of_two(unsigned long val);
  32. private:
  33. unsigned int m_nsize;
  34. unsigned int m_nin;
  35. unsigned int m_nout;
  36. unsigned char* m_pbuffer;
  37. };
  38. #endif