Shared/exclusive lock whose exclusive side is re-entrant for its owner, and whose owner passes through the shared side.
void entropic::ToolRootLock::lock()
Acquire exclusively; re-entrant for the owning thread.
Only the owner ever stores its own id into owner_, so a non-owner can never read its own id there and always takes the mutex — which is what makes the unlocked owner_ check sound.
void entropic::ToolRootLock::unlock()
Release one exclusive level; the last one frees the lock.
bool entropic::ToolRootLock::lock_shared(const std::string &what)
Acquire shared, unless this thread owns the exclusive side.
A dispatch that has to wait says so in the log, naming what waited: a tool call stalled behind another session's sandboxed delegation is otherwise indistinguishable from a slow tool. The owner passing through is the point, not a shortcut: a sandboxed child's own tool calls run on the thread that entered the sandbox, and they are the calls that must see it. Anyone else who finds the lock held logs the wait before and after, so a stalled dispatch is visible.
- Parameters
what — Label for the wait log line (the tool being dispatched).what — Label for the wait log line.
- Returns
- true when a shared hold was taken and must be released with unlock_shared(); false when this thread is the exclusive owner, which already excludes every re-rooting.
- true when a shared hold was taken; false for the owner.
void entropic::ToolRootLock::unlock_shared()
Release a shared hold taken by lock_shared() == true.
bool entropic::ToolRootLock::owned_by_this_thread() const
Whether the calling thread holds the exclusive side.
- Returns
- true for the owner, false for every other thread.
RAII shared hold on a ToolRootLock (owner pass-through aware).
entropic::ToolRootShared::ToolRootShared(ToolRootLock &lock, const std::string &what)
Take the shared side (or pass through as the owner).
- Parameters
lock — Lock to hold.what — Label for the wait log line (the tool being dispatched).what — Label for the wait log line.
ToolRootShared & entropic::ToolRootShared::operator=(const ToolRootShared &)=delete