All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
MPMCQueue.h
1 // Copyright eeGeo Ltd (2012-2022), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "SemaphoreEegeo.h"
7 #include <pthread.h>
8 #include <queue>
9 #include <list>
10 
11 namespace Eegeo
12 {
13  namespace Concurrency
14  {
15  template<typename T>
16  class MPMCQueue : protected Eegeo::NonCopyable
17  {
18  public:
19  MPMCQueue();
20  ~MPMCQueue();
21 
22  size_t Size() const;
23  void Enqueue(T message);
24  void EnqueueHead(T message);
25  T Dequeue();
26  bool TryDequeue(T& message);
27  private:
28  T DequeueMessageFromHead();
29  std::list<T> m_queue;
30  mutable pthread_mutex_t m_mutex;
31  Semaphore m_signal;
32  };
33 
34  }
35 }
36 
37 #include "MPMCQueueImpl.h"
38 
39