diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2022-07-23 21:20:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-23 21:20:39 +0200 |
commit | 97729fd8e9c2f8cabc626ab03a666c9428e01c5e (patch) | |
tree | f6a2f3b6c71b51a646d1502c01a4f6be92a3ed26 /src/audio_core/audio_event.cpp | |
parent | Merge pull request #8629 from Docteh/test_transifex (diff) | |
parent | Project Andio (diff) | |
download | yuzu-97729fd8e9c2f8cabc626ab03a666c9428e01c5e.tar yuzu-97729fd8e9c2f8cabc626ab03a666c9428e01c5e.tar.gz yuzu-97729fd8e9c2f8cabc626ab03a666c9428e01c5e.tar.bz2 yuzu-97729fd8e9c2f8cabc626ab03a666c9428e01c5e.tar.lz yuzu-97729fd8e9c2f8cabc626ab03a666c9428e01c5e.tar.xz yuzu-97729fd8e9c2f8cabc626ab03a666c9428e01c5e.tar.zst yuzu-97729fd8e9c2f8cabc626ab03a666c9428e01c5e.zip |
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 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "audio_core/audio_event.h" +#include "common/assert.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 std::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 |