-
Notifications
You must be signed in to change notification settings - Fork 82
/
threadsafequeue.hh
79 lines (50 loc) · 1.78 KB
/
threadsafequeue.hh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// -*- c-basic-offset: 4 -*-
#ifndef CLICK_THREADSAFEQUEUE_HH
#define CLICK_THREADSAFEQUEUE_HH
#include "fullnotequeue.hh"
CLICK_DECLS
/*
=c
ThreadSafeQueue
ThreadSafeQueue(CAPACITY)
=s storage
stores packets in a FIFO queue
=d
Stores incoming packets in a first-in-first-out queue.
Drops incoming packets if the queue already holds CAPACITY packets.
The default for CAPACITY is 1000.
This variant of the default Queue is (should be) completely thread safe, in
that it supports multiple concurrent pushers and pullers. In all respects
other than thread safety it behaves just like Queue, and like Queue it has
non-full and non-empty notifiers.
=h length read-only
Returns the current number of packets in the queue.
=h highwater_length read-only
Returns the maximum number of packets that have ever been in the queue at once.
=h capacity read/write
Returns or sets the queue's capacity.
=h drops read-only
Returns the number of packets dropped by the queue so far.
=h reset_counts write-only
When written, resets the C<drops> and C<highwater_length> counters.
=h reset write-only
When written, drops all packets in the queue.
=a Queue, SimpleQueue, NotifierQueue, MixedQueue, FrontDropQueue */
class ThreadSafeQueue : public FullNoteQueue { public:
ThreadSafeQueue() CLICK_COLD;
const char *class_name() const override { return "ThreadSafeQueue"; }
void *cast(const char *);
int live_reconfigure(Vector<String> &conf, ErrorHandler *errh);
void take_state(Element*, ErrorHandler*);
void push(int port, Packet *) final;
Packet *pull(int port) final;
#if HAVE_BATCH
void push_batch(int port, PacketBatch *);
PacketBatch* pull_batch(int port,unsigned max);
#endif
private:
atomic_uint32_t _xhead;
atomic_uint32_t _xtail;
};
CLICK_ENDDECLS
#endif