-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadSafeQueueInterface.h
More file actions
49 lines (34 loc) · 1.5 KB
/
ThreadSafeQueueInterface.h
File metadata and controls
49 lines (34 loc) · 1.5 KB
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
//
// Created by 陶睿 on 4/2/24.
//
#ifndef EVENTLOOPMANAGER_THREADSAFEQUEUE_H
#define EVENTLOOPMANAGER_THREADSAFEQUEUE_H
#include <mutex>
#include <condition_variable>
#include <queue>
template<typename T>
class ThreadSafeQueueInterface {
public:
virtual ~ThreadSafeQueueInterface() = default;
// Inserts the specified element into this queue.
virtual void push(const T& value) = 0;
// Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.
virtual T waitAndPop() = 0;
// Retrieves and removes the head of this queue. Throws an exception if the queue is empty.
virtual T pop() = 0;
// Retrieves, but does not remove, the head of this queue. Throws an exception if the queue is empty.
virtual T front() const = 0;
// Retrieves the head of this queue, waiting if necessary until an element becomes available.
virtual T waitAndFront() const = 0;
// Retrieves, but does not remove, the tail of this queue. Throws an exception if the queue is empty.
virtual T back() const = 0;
// Retrieves the tail of this queue, waiting if necessary until an element becomes available.
virtual T waitAndBack() const = 0;
// Returns true if this queue contains no elements.
virtual bool empty() const = 0;
// Returns the number of elements in this queue.
virtual size_t size() const = 0;
// Removes all of the elements from this queue.
virtual void clear() = 0;
};
#endif //EVENTLOOPMANAGER_THREADSAFEQUEUE_H