summaryrefslogtreecommitdiff
path: root/src/thread_utils.h
diff options
context:
space:
mode:
authorAl <26797547+Al12rs@users.noreply.github.com>2020-11-28 06:32:09 -0800
committerGitHub <noreply@github.com>2020-11-28 06:32:09 -0800
commit2c115e48cc42f89250bbca7e2b5b75d5dcad8695 (patch)
treebff3fc474a4527331c99ddb981f88c49cb7fd286 /src/thread_utils.h
parentdffec4fd9dfa6860a62b4c59fe75c03006a37146 (diff)
parentef1188811633e8c1403f960c9196de92d0a81020 (diff)
Merge pull request #1301 from ModOrganizer2/iplugingame-saves
IPluginGame::listSaves
Diffstat (limited to 'src/thread_utils.h')
-rw-r--r--src/thread_utils.h45
1 files changed, 0 insertions, 45 deletions
diff --git a/src/thread_utils.h b/src/thread_utils.h
index f64dd601..e816a4e2 100644
--- a/src/thread_utils.h
+++ b/src/thread_utils.h
@@ -24,51 +24,6 @@ std::thread startSafeThread(F&& f)
});
}
-
-/**
- * Class that can be used to perform thread-safe memoization.
- *
- * Each instance hold a flag indicating if the current value is up-to-date
- * or not. This flag can be reset using `invalidate()`. When the value is queried,
- * the flag is checked, and if it is not up-to-date, the given callback is used
- * to compute the value.
- *
- * The computation and update of the value is locked to avoid concurrent modifications.
- *
- * @tparam T Type of value ot memoized.
- * @tparam Fn Type of the callback.
- */
-template <class T, class Fn = std::function<T()>>
-struct MemoizedLocked {
-
- template <class Callable>
- MemoizedLocked(Callable &&callable, T value = {}) :
- m_Fn{ std::forward<Callable>(callable) }, m_Value{ std::move(value) } { }
-
- template <class... Args>
- T& value(Args&&... args) const {
- if (m_NeedUpdating) {
- std::scoped_lock lock(m_Mutex);
- if (m_NeedUpdating) {
- m_Value = std::invoke(m_Fn, std::forward<Args>(args)... );
- m_NeedUpdating = false;
- }
- }
- return m_Value;
- }
-
- void invalidate() {
- m_NeedUpdating = true;
- }
-
-private:
- mutable std::mutex m_Mutex;
- mutable std::atomic<bool> m_NeedUpdating{ true };
-
- Fn m_Fn;
- mutable T m_Value;
-};
-
/**
* @brief Apply the given callable to each element between the two given iterators
* in a parallel way.