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