otsdaq-mu2e-stm  5.02.01
queue.hh
1 #ifndef queue_h_
2 #define queue_h_
3 
4 #include <iostream>
5 #include <cstring>
6 #include <thread>
7 #include <atomic>
8 #include <cinttypes>
9 
10 #include "dataVars.hh"
11 
12 // Ring buffer size
13 #define RING_BUFFER_SIZE 536870912
14 
16 
17 public :
18 
19  // Constructor
20  queue_buffer();
21 
22  // Try to push data to queue
23  int try_push(int chan, int16_t *data, int n);
24 
25  // Push data to queue
26  void push(int chan, int16_t *data, int n);
27 
28  // Try to pull data from queue
29  int try_pull(int chan, int16_t *&data);
30 
31  // Pull data from queue
32  // int pull(UDPsocket *udp, int chan, T *&data);
33  int pull(bool *timeout, int chan, int16_t *&data);
34 
35  // Atomic write pointer
36  std::atomic<int64_t> write[CHNUM];
37  // Atomic read pointer
38  std::atomic<int64_t> read[CHNUM];
39  // Atomic occupancy counter
40  std::atomic<int64_t> occupancy[CHNUM];
41 
42  // Current tail pointer
43  int64_t current_tail[CHNUM];
44  // Next tail pointer
45  int64_t next_tail[CHNUM];
46  // Current head pointer
47  int64_t current_head[CHNUM];
48 
49  // Number written to the buffer
50  int64_t write_num[CHNUM]; // in push
51  int64_t read_num[CHNUM]; // in pull
52 
53  // The buffer size
54  static const int64_t size = RING_BUFFER_SIZE;
55 
56  // The buffer
57  int16_t* buffer[CHNUM];
58 
59  // Increment function
60  int64_t increment(int n, int x){
61  return (n + x) % size;
62  }
63 
64 private :
65 
66 
67 };
68 
69 #endif
70 
Definition: data.hh:4