tool_root_lock.cpp¶
src/mcp/tool_root_lock.cpp
@file tool_root_lock.cpp @brief ToolRootLock implementation (gh#158, gh#160).
Owners: @tvanfossen
lock
void entropic::ToolRootLock::lock()
Acquire exclusively; re-entrant for the owning thread.
src/mcp/tool_root_lock.cpp:26
Source · 10 lines
void ToolRootLock::lock() {
const auto me = std::this_thread::get_id();
if (owner_.load(std::memory_order_acquire) == me) {
++depth_;
return;
}
mutex_.lock();
owner_.store(me, std::memory_order_release);
depth_ = 1;
}Activity · 7 steps
Requirements
owned_by_this_thread
bool entropic::ToolRootLock::owned_by_this_thread() const
Whether the calling thread holds the exclusive side.
src/mcp/tool_root_lock.cpp:92
Source · 4 lines
bool ToolRootLock::owned_by_this_thread() const {
return owner_.load(std::memory_order_acquire)
== std::this_thread::get_id();
}Activity · 1 steps
Requirements
unlock
void entropic::ToolRootLock::unlock()
Release one exclusive level; the last one frees the lock.
src/mcp/tool_root_lock.cpp:43
Source · 6 lines
void ToolRootLock::unlock() {
if (--depth_ == 0) {
owner_.store(std::thread::id{}, std::memory_order_release);
mutex_.unlock();
}
}