diff options
| author | 2022-07-16 23:48:45 +0100 | |
|---|---|---|
| committer | 2022-07-22 01:11:32 +0100 | |
| commit | 458da8a94877677f086f06cdeecf959ec4283a33 (patch) | |
| tree | 583166d77602ad90a0d552f37de8729ad80fd6c1 /src/audio_core/audio_event.cpp | |
| parent | Merge pull request #8598 from Link4565/recv-dontwait (diff) | |
| download | yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.gz yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.xz yuzu-458da8a94877677f086f06cdeecf959ec4283a33.zip | |
Project Andio
Diffstat (limited to 'src/audio_core/audio_event.cpp')
| -rw-r--r-- | src/audio_core/audio_event.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/audio_core/audio_event.cpp b/src/audio_core/audio_event.cpp new file mode 100644 index 000000000..424049c7a --- /dev/null +++ b/src/audio_core/audio_event.cpp | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "audio_core/audio_event.h" | ||
| 5 | #include "common/assert.h" | ||
| 6 | |||
| 7 | namespace AudioCore { | ||
| 8 | |||
| 9 | size_t Event::GetManagerIndex(const Type type) const { | ||
| 10 | switch (type) { | ||
| 11 | case Type::AudioInManager: | ||
| 12 | return 0; | ||
| 13 | case Type::AudioOutManager: | ||
| 14 | return 1; | ||
| 15 | case Type::FinalOutputRecorderManager: | ||
| 16 | return 2; | ||
| 17 | case Type::Max: | ||
| 18 | return 3; | ||
| 19 | default: | ||
| 20 | UNREACHABLE(); | ||
| 21 | } | ||
| 22 | return 3; | ||
| 23 | } | ||
| 24 | |||
| 25 | void Event::SetAudioEvent(const Type type, const bool signalled) { | ||
| 26 | events_signalled[GetManagerIndex(type)] = signalled; | ||
| 27 | if (signalled) { | ||
| 28 | manager_event.notify_one(); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | bool Event::CheckAudioEventSet(const Type type) const { | ||
| 33 | return events_signalled[GetManagerIndex(type)]; | ||
| 34 | } | ||
| 35 | |||
| 36 | std::mutex& Event::GetAudioEventLock() { | ||
| 37 | return event_lock; | ||
| 38 | } | ||
| 39 | |||
| 40 | std::condition_variable_any& Event::GetAudioEvent() { | ||
| 41 | return manager_event; | ||
| 42 | } | ||
| 43 | |||
| 44 | bool Event::Wait(std::unique_lock<std::mutex>& l, const std::chrono::seconds timeout) { | ||
| 45 | bool timed_out{false}; | ||
| 46 | if (!manager_event.wait_for(l, timeout, [&]() { | ||
| 47 | return std::ranges::any_of(events_signalled, [](bool x) { return x; }); | ||
| 48 | })) { | ||
| 49 | timed_out = true; | ||
| 50 | } | ||
| 51 | return timed_out; | ||
| 52 | } | ||
| 53 | |||
| 54 | void Event::ClearEvents() { | ||
| 55 | events_signalled[0] = false; | ||
| 56 | events_signalled[1] = false; | ||
| 57 | events_signalled[2] = false; | ||
| 58 | events_signalled[3] = false; | ||
| 59 | } | ||
| 60 | |||
| 61 | } // namespace AudioCore | ||