summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/hid/ring_lifo.h
diff options
context:
space:
mode:
authorFernando S <fsahmkow27@gmail.com>2021-11-27 11:52:08 +0100
committerGitHub <noreply@github.com>2021-11-27 11:52:08 +0100
commit564f10527745f870621c08bbb5d16badee0ed861 (patch)
treee8ac8dee60086facf1837393882865f5df18c95e /src/core/hle/service/hid/ring_lifo.h
parentMerge pull request #7431 from liushuyu/fix-linux-decoding (diff)
parentconfig: Remove vibration configuration (diff)
downloadyuzu-564f10527745f870621c08bbb5d16badee0ed861.tar
yuzu-564f10527745f870621c08bbb5d16badee0ed861.tar.gz
yuzu-564f10527745f870621c08bbb5d16badee0ed861.tar.bz2
yuzu-564f10527745f870621c08bbb5d16badee0ed861.tar.lz
yuzu-564f10527745f870621c08bbb5d16badee0ed861.tar.xz
yuzu-564f10527745f870621c08bbb5d16badee0ed861.tar.zst
yuzu-564f10527745f870621c08bbb5d16badee0ed861.zip
Diffstat (limited to '')
-rw-r--r--src/core/hle/service/hid/ring_lifo.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/core/hle/service/hid/ring_lifo.h b/src/core/hle/service/hid/ring_lifo.h
new file mode 100644
index 000000000..44c20d967
--- /dev/null
+++ b/src/core/hle/service/hid/ring_lifo.h
@@ -0,0 +1,54 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included
+
+#pragma once
+
+#include <array>
+
+#include "common/common_types.h"
+
+namespace Service::HID {
+
+template <typename State>
+struct AtomicStorage {
+ s64 sampling_number;
+ State state;
+};
+
+template <typename State, std::size_t max_buffer_size>
+struct Lifo {
+ s64 timestamp{};
+ s64 total_buffer_count = static_cast<s64>(max_buffer_size);
+ s64 buffer_tail{};
+ s64 buffer_count{};
+ std::array<AtomicStorage<State>, max_buffer_size> entries{};
+
+ const AtomicStorage<State>& ReadCurrentEntry() const {
+ return entries[buffer_tail];
+ }
+
+ const AtomicStorage<State>& ReadPreviousEntry() const {
+ return entries[GetPreviousEntryIndex()];
+ }
+
+ std::size_t GetPreviousEntryIndex() const {
+ return static_cast<size_t>((buffer_tail + total_buffer_count - 1) % total_buffer_count);
+ }
+
+ std::size_t GetNextEntryIndex() const {
+ return static_cast<size_t>((buffer_tail + 1) % total_buffer_count);
+ }
+
+ void WriteNextEntry(const State& new_state) {
+ if (buffer_count < total_buffer_count - 1) {
+ buffer_count++;
+ }
+ buffer_tail = GetNextEntryIndex();
+ const auto& previous_entry = ReadPreviousEntry();
+ entries[buffer_tail].sampling_number = previous_entry.sampling_number + 1;
+ entries[buffer_tail].state = new_state;
+ }
+};
+
+} // namespace Service::HID