Module: FiberAudit::Runtime::ExecutionContext
- Defined in:
- lib/fiber_audit/runtime/execution_context.rb
Overview
Fiber-local execution context stack. Uses fiber instance variables for isolation without Thread#[] visibility. PID-aware to handle fork correctly.
Constant Summary collapse
- MAX_DEPTH =
32- IVAR_KEY =
:@__fiber_audit_execution_context__- IVAR_PID_KEY =
:@__fiber_audit_execution_context_pid__
Class Method Summary collapse
Class Method Details
.after_fork! ⇒ Object
42 43 44 |
# File 'lib/fiber_audit/runtime/execution_context.rb', line 42 def after_fork! reset! end |
.current ⇒ Object
16 17 18 19 20 21 |
# File 'lib/fiber_audit/runtime/execution_context.rb', line 16 def current state = current_state return Context::UNKNOWN unless state state[:stack].last || Context::UNKNOWN end |
.reset! ⇒ Object
36 37 38 39 40 |
# File 'lib/fiber_audit/runtime/execution_context.rb', line 36 def reset! fiber = Fiber.current fiber.remove_instance_variable(IVAR_KEY) if fiber.instance_variable_defined?(IVAR_KEY) fiber.remove_instance_variable(IVAR_PID_KEY) if fiber.instance_variable_defined?(IVAR_PID_KEY) end |
.with(context) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fiber_audit/runtime/execution_context.rb', line 23 def with(context) normalized = validate_context(context) state = ensure_state return yield if state[:stack].size >= MAX_DEPTH state[:stack].push(normalized) begin yield ensure state[:stack].pop end end |