otsdaq-mu2e-stm  5.02.01
testQueueMAIN.h
1 #ifndef testQueueMAIN_h_
2 #define testQueueMAIN_h_
3 
4 #include <iostream>
5 #include <thread>
6 #include <atomic>
7 #include <cinttypes>
8 #include <cstring>
9 #include <thread>
10 #include <mutex>
11 
12 static const int CHNUM = 2;
13 //static const int buffer_size = 65537; //65536; // power of 2 for efficient %
14 static const int buffer_size = 131072; //65536; // power of 2 for efficient %
15 static const int m_num = 100*buffer_size;
16 static const int push_max = 65536;
17 template <typename T> class queue_buffer{
18 
19 public :
20  // Constructor
21  queue_buffer();
22  // Try to push data to queue
23  int try_push(int chan, T *data, int n, int index);
24  // Push data to queue
25  void push(int chan, T *data, int n);
26  // Try to pull data from queue
27  int try_pull(int chan, T *&data);
28  // Pull data from queue
29  // int pull(UDPsocket *udp, int chan, T *&data);
30  int pull(int chan, T *&data);
31  // Atomic write pointer
32  std::atomic<int64_t> write[CHNUM];
33  // Atomic read pointer
34  std::atomic<int64_t> read[CHNUM];
35  // Atomic memory checker
36  std::atomic<int64_t> numInBuffer[CHNUM];
37  // Current tail pointer
38  int64_t current_tail[CHNUM];
39  // Next tail pointer
40  int64_t next_tail[CHNUM];
41  // Current head pointer
42  int64_t current_head[CHNUM];
43  // number in push buffer
44  int64_t writeNum[CHNUM];
45  // number in pull buffer
46  int64_t readNum[CHNUM];
47  // Atomic fetch_add write pointer
48  int64_t writeNumInBuffer[CHNUM];
49  // Atomic fetch_sub read pointer
50  int64_t readNumInBuffer[CHNUM];
51  // The buffer size
52  static const int64_t size = buffer_size;
53  // The maximum number of datagrams to pull
54  int pull_max = m_num;
55  // Pull data pointer array
56  T pdata[CHNUM];
57  // The buffer
58  T* buffer[CHNUM];
59  // Increment function
60  int64_t increment(int n, int x){
61  return (n + x) % (size);
62  }
63  int64_t memPercent(int n, int x){
64  return n*(n / x);
65  }
66  bool startOfRun[CHNUM] = {true, true};
67 private :
68 };
69 
70 #endif
Definition: data.hh:4