From 0b8bbd90d339c454fed0e49693de4a4b7db34a82 Mon Sep 17 00:00:00 2001 From: Stepland <10530295-Buggyroom@users.noreply.gitlab.com> Date: Mon, 24 Jul 2023 22:40:47 +0200 Subject: [PATCH] remove unused source file --- src/cache.hpp | 96 -------------------------------------------- src/editor_state.hpp | 2 - src/waveform.hpp | 1 - 3 files changed, 99 deletions(-) delete mode 100644 src/cache.hpp diff --git a/src/cache.hpp b/src/cache.hpp deleted file mode 100644 index e6b9146..0000000 --- a/src/cache.hpp +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace Toolkit { - /* Asynchronously Loads a Value associated with a Key in another thread and - stores it for later reuse */ - template - class Cache { - public: - using key_type = Key; - using value_type = Value; - using reference_type = std::reference_wrapper; - using const_reference_type = std::reference_wrapper; - Cache(std::function _load_resource): load_resource(_load_resource) {}; - - // Does not trigger loading - std::optional get(const Key& key) const { - std::shared_lock lock{mapping_mutex}; - if (has(key)) { - return std::cref(mapping.at(key)); - } else { - return {}; - } - } - - // Returns empty if not already loaded - std::optional async_load(const Key& key) { - if (not has(key)) { - if (not is_loading(key)) { - async_emplace(key); - } - return {}; - } else { - return get(key); - } - } - - void async_emplace(const Key& key) { - std::thread t(&Cache::blocking_emplace, this, key); - t.detach(); - } - - - void blocking_emplace(const Key& key) { - if (has(key) or is_loading(key)) { - return; - } - { - std::unique_lock lock{currently_loading_mutex}; - currently_loading.insert(key); - } - Value resource = load_resource(key); - { - std::scoped_lock lock{mapping_mutex, currently_loading_mutex}; - mapping.emplace(key, resource); - currently_loading.erase(key); - } - } - - reference_type blocking_load(const Key& key) { - std::shared_lock lock{mapping_mutex}; - blocking_emplace(key); - return mapping.at(key); - } - - bool has(const Key& key) const { - std::shared_lock lock{mapping_mutex}; - return mapping.find(key) != mapping.end(); - } - - bool is_loading(const Key& key) const { - std::shared_lock lock{currently_loading_mutex}; - return currently_loading.find(key) != currently_loading.end(); - } - - void reserve(const std::size_t& n) const { - std::scoped_lock lock{mapping_mutex, currently_loading_mutex}; - mapping.reserve(n); - currently_loading.reserve(n); - } - - private: - std::map mapping; - mutable std::shared_mutex mapping_mutex; - std::set currently_loading; - mutable std::shared_mutex currently_loading_mutex; - std::function load_resource; - }; -} diff --git a/src/editor_state.hpp b/src/editor_state.hpp index af2490c..89542bd 100644 --- a/src/editor_state.hpp +++ b/src/editor_state.hpp @@ -9,8 +9,6 @@ #include #include - -#include "cache.hpp" #include "config.hpp" #include "custom_sfml_audio/beat_ticks.hpp" #include "custom_sfml_audio/chord_claps.hpp" diff --git a/src/waveform.hpp b/src/waveform.hpp index cbe9bff..aadb74e 100644 --- a/src/waveform.hpp +++ b/src/waveform.hpp @@ -10,7 +10,6 @@ #include -#include "cache.hpp" #include "utf8_sfml_redefinitions.hpp" #include "variant_visitor.hpp"