diff options
| author | Douglas Rumbaugh <dbr4@psu.edu> | 2025-02-11 17:32:10 -0500 |
|---|---|---|
| committer | Douglas Rumbaugh <dbr4@psu.edu> | 2025-02-11 17:32:10 -0500 |
| commit | 85afe4ef04f327862460570fb0aa4c30afcf7cc7 (patch) | |
| tree | aba55db313b752df4ac073db117900e0128c22fb /include/framework/scheduling/LockManager.h | |
| parent | c04efb2640421be7a24f851c08e290c89b7b46f2 (diff) | |
| download | dynamic-extension-85afe4ef04f327862460570fb0aa4c30afcf7cc7.tar.gz | |
Progress: began adding parallel merging and locking of levels
Diffstat (limited to 'include/framework/scheduling/LockManager.h')
| -rw-r--r-- | include/framework/scheduling/LockManager.h | 52 |
1 files changed, 52 insertions, 0 deletions
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 <deque> +#include <atomic> + +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<std::atomic<bool>> m_lks; +}; +} |