From 85afe4ef04f327862460570fb0aa4c30afcf7cc7 Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Tue, 11 Feb 2025 17:32:10 -0500 Subject: Progress: began adding parallel merging and locking of levels --- include/framework/scheduling/LockManager.h | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 include/framework/scheduling/LockManager.h (limited to 'include/framework/scheduling/LockManager.h') diff --git a/include/framework/scheduling/LockManager.h b/include/framework/scheduling/LockManager.h new file mode 100644 index 0000000..91ed778 --- /dev/null +++ b/include/framework/scheduling/LockManager.h @@ -0,0 +1,52 @@ +/* + * + */ + +#pragma once +#include +#include + +namespace de { +class LockManager { +public: + LockManager(size_t levels=1) { + for (size_t i=0; i < levels; i++) { + m_lks.emplace_back(false); + } + } + + ~LockManager() = default; + + void add_lock() { + m_lks.emplace_back(false); + } + + void release_lock(size_t idx) { + if (idx < m_lks.size()) { + m_lks[idx].store(false); + } + } + + bool is_locked(size_t idx) { + if (idx < m_lks.size()) { + return m_lks[idx].load(); + } + + return false; + } + + bool take_lock(size_t idx) { + if (idx < m_lks.size()) { + bool old = m_lks[idx].load(); + if (!old) { + return m_lks[idx].compare_exchange_strong(old, true); + } + } + + return false; + } + +private: + std::deque> m_lks; +}; +} -- cgit v1.2.3