Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
tool_root_lock.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
10
11static auto logger = entropic::log::get("mcp.tool_root_lock");
12
13namespace entropic {
14
27 const auto me = std::this_thread::get_id();
28 if (owner_.load(std::memory_order_acquire) == me) {
29 ++depth_;
30 return;
31 }
32 mutex_.lock();
33 owner_.store(me, std::memory_order_release);
34 depth_ = 1;
35}
36
44 if (--depth_ == 0) {
45 owner_.store(std::thread::id{}, std::memory_order_release);
46 mutex_.unlock();
47 }
48}
49
64bool ToolRootLock::lock_shared(const std::string& what) {
66 return false;
67 }
68 if (!mutex_.try_lock_shared()) {
69 logger->info("[{}] waiting: a sandboxed delegation has this server "
70 "set re-rooted; dispatching once it restores", what);
71 mutex_.lock_shared();
72 logger->info("[{}] working directory restored — dispatching", what);
73 }
74 return true;
75}
76
83 mutex_.unlock_shared();
84}
85
93 return owner_.load(std::memory_order_acquire)
94 == std::this_thread::get_id();
95}
96
105 : lock_(lock), held_(lock.lock_shared(what)) {}
106
113 if (held_) {
114 lock_.unlock_shared();
115 }
116}
117
118} // namespace entropic
Shared/exclusive lock whose exclusive side is re-entrant for its owner, and whose owner passes throug...
bool owned_by_this_thread() const
Whether the calling thread holds the exclusive side.
bool lock_shared(const std::string &what)
Acquire shared, unless this thread owns the exclusive side.
void unlock()
Release one exclusive level; the last one frees the lock.
void lock()
Acquire exclusively; re-entrant for the owning thread.
void unlock_shared()
Release a shared hold taken by lock_shared() == true.
~ToolRootShared()
Release the shared hold if one was taken.
ToolRootShared(ToolRootLock &lock, const std::string &what)
Take the shared side (or pass through as the owner).
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Definition logging.cpp:211
Activate model on GPU (WARM → ACTIVE).
@ optional
optional: every escape asks the host's path approver
The lock that guards the working directory one ServerManager's in-process and plugin servers resolve ...