otsdaq-mu2e-stm
5.02.01
Return to top level
queue.hh
1
#ifndef queue_h_
2
#define queue_h_
3
4
#include <stdint.h>
5
#include <pthread.h>
6
9
// struct message_t {
10
// size_t len;
11
// // size_t seq;
12
// };
13
14
// Blocking queue data structure
15
struct
queue_t
{
16
17
// Backing buffer and size
18
uint8_t *buffer;
19
size_t
size;
20
21
// Backing buffer's memfd descriptor
22
int
fd;
23
24
// Read / write indices
25
size_t
head;
26
size_t
tail;
27
28
// Sequence number of next consumable message
29
// size_t head_seq;
30
31
// Sequence number of last written message
32
// size_t tail_seq;
33
34
// Synchronization primitives
35
pthread_cond_t readable;
36
pthread_cond_t writeable;
37
pthread_mutex_t lock;
38
39
};
40
41
//template <typename T, size_t buffer_size>
42
class
queue
{
43
44
public
:
45
46
// Initalise queue struct
47
queue_t
q;
48
49
// Initialize a blocking queue *q* of size
50
void
init(
size_t
s);
51
52
// Destroy the blocking queue *q*
53
void
destroy();
54
55
// Insert into queue *q* a message of *size* bytes from *buffer*
56
// Blocks until sufficient space is available in the queue.
57
void
put(int16_t *
data
, int16_t size);
58
59
// Retrieves a message of at most *max* bytes from queue *q* and writes it to *buffer*.
60
// Blocks until a message of no more than *max* bytes is available.
61
// Returns the number of bytes in the written message.
62
size_t
get(int16_t *
data
, int16_t max);
63
64
private
:
65
66
};
67
68
#endif
69
data
Definition:
data.hh:4
queue
Definition:
queue.hh:42
queue_t
Definition:
queue.hh:15
otsdaq-mu2e-stm
Mu2e-STMDAQ
OLD_BUT_DONT_DELETE_YET
NOT_NEEDED
UDPtesting
circBuff
queue
queue.hh
Generated by
1.9.1 at 2026-10-06T07:29:55