FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
node-webrtc/src/node/event_queue.hh at develop · node-webrtc/node-webrtc · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
node-webrtc
/
node-webrtc
Public
Notifications
You must be signed in to change notification settings
Fork
479
Star
2.8k
Code
Issues
103
Pull requests
7
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
node-webrtc
/
src
/
node
/
event_queue.hh
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (50 loc) · 1.35 KB
Breadcrumbs
node-webrtc
/
src
/
node
/
event_queue.hh
Copy path
File metadata and controls
57 lines (50 loc) · 1.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
Copyright (c) 2019 The node-webrtc project authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license that can be found
* in the LICENSE.md file in the root of the source tree. All contributing
* project authors may be found in the AUTHORS file in the root of the source
* tree.
*/
#
pragma
once
#
include
<
memory
>
#
include
<
mutex
>
#
include
<
queue
>
#
include
"
events.hh
"
namespace
node_webrtc
{
/*
*
* EventQueue is a thread-safe Event queue. It allows you to enqueue events
* from one thread and dequeue them from another (or the same).
* @tparam T the Event target type
*/
template
<
typename
T>
class
EventQueue
{
public:
/*
*
* Enqueue an Event.
* @param event the event to enqueue
*/
void
Enqueue
(std::unique_ptr<Event<T>> event) {
_mutex.
lock
();
_events.
push
(
std::move
(event));
_mutex.
unlock
();
}
/*
*
* Attempt to dequeue an Event. If the EventQueue is empty, this method
* returns nullptr.
* @return the dequeued Event or nullptr
*/
std::unique_ptr<Event<T>>
Dequeue
() {
_mutex.
lock
();
if
(_events.
empty
()) {
_mutex.
unlock
();
return
nullptr
;
}
auto
event =
std::move
(_events.
front
());
_events.
pop
();
_mutex.
unlock
();
return
event;
}
private:
std::queue<std::unique_ptr<Event<T>>> _events;
std::mutex _mutex;
};
}
//
namespace node_webrtc
Back
|
FazBrowse Home
|
New Git URL