-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue.h
More file actions
36 lines (29 loc) · 949 Bytes
/
queue.h
File metadata and controls
36 lines (29 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef QUEUE_H
#define QUEUE_H
#include "config.h"
/*
* Bounded MPMC queue (mutex + condvar).
* Fast enough for our producer/consumer rates;
* producers: receiver threads (SYN+ACK handler)
* consumers: exploit worker threads
*/
typedef struct {
target_t *buf;
uint32_t cap;
uint32_t head;
uint32_t tail;
uint32_t count;
pthread_mutex_t lock;
pthread_cond_t not_full;
pthread_cond_t not_empty;
volatile int closed; /* set 1 when producers done */
} tqueue_t;
int tqueue_init (tqueue_t *q, uint32_t cap);
void tqueue_free (tqueue_t *q);
void tqueue_close(tqueue_t *q);
/* returns 0 on success, -1 if queue full (non-blocking) */
int tqueue_push (tqueue_t *q, target_t t);
/* returns 0 on success, -1 if queue empty+closed */
int tqueue_pop (tqueue_t *q, target_t *out);
uint32_t tqueue_size (tqueue_t *q);
#endif /* QUEUE_H */