-
Notifications
You must be signed in to change notification settings - Fork 6
/
audio_event.cpp
63 lines (53 loc) · 1.53 KB
/
audio_event.cpp
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
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: MPL-2.0
#include <range/v3/algorithm.hpp>
#include <audio_core/audio_event.h>
#include <audio_core/common/assert.h>
#include <audio_core/common/polyfill_ranges.h>
namespace AudioCore {
size_t Event::GetManagerIndex(const Type type) const {
switch (type) {
case Type::AudioInManager:
return 0;
case Type::AudioOutManager:
return 1;
case Type::FinalOutputRecorderManager:
return 2;
case Type::Max:
return 3;
default:
UNREACHABLE();
}
return 3;
}
void Event::SetAudioEvent(const Type type, const bool signalled) {
events_signalled[GetManagerIndex(type)] = signalled;
if (signalled) {
manager_event.notify_one();
}
}
bool Event::CheckAudioEventSet(const Type type) const {
return events_signalled[GetManagerIndex(type)];
}
std::mutex& Event::GetAudioEventLock() {
return event_lock;
}
std::condition_variable_any& Event::GetAudioEvent() {
return manager_event;
}
bool Event::Wait(std::unique_lock<std::mutex>& l, const std::chrono::seconds timeout) {
bool timed_out{false};
if (!manager_event.wait_for(l, timeout, [&]() {
return ranges::any_of(events_signalled, [](bool x) { return x; });
})) {
timed_out = true;
}
return timed_out;
}
void Event::ClearEvents() {
events_signalled[0] = false;
events_signalled[1] = false;
events_signalled[2] = false;
events_signalled[3] = false;
}
} // namespace AudioCore