Class: RequireHooks::KernelPatch::Features::Locker
- Inherits:
-
Object
- Object
- RequireHooks::KernelPatch::Features::Locker
- Defined in:
- lib/require-hooks/mode/kernel_patch.rb
Defined Under Namespace
Classes: PathLock
Instance Attribute Summary collapse
-
#features ⇒ Object
readonly
Returns the value of attribute features.
-
#mu ⇒ Object
readonly
Returns the value of attribute mu.
Instance Method Summary collapse
-
#initialize ⇒ Locker
constructor
A new instance of Locker.
- #lock_feature(fname) ⇒ Object
- #locked_feature?(fname) ⇒ Boolean
Constructor Details
#initialize ⇒ Locker
Returns a new instance of Locker.
95 96 97 98 |
# File 'lib/require-hooks/mode/kernel_patch.rb', line 95 def initialize @mu = Mutex.new @features = {} end |
Instance Attribute Details
#features ⇒ Object (readonly)
Returns the value of attribute features.
93 94 95 |
# File 'lib/require-hooks/mode/kernel_patch.rb', line 93 def features @features end |
#mu ⇒ Object (readonly)
Returns the value of attribute mu.
93 94 95 |
# File 'lib/require-hooks/mode/kernel_patch.rb', line 93 def mu @mu end |
Instance Method Details
#lock_feature(fname) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/require-hooks/mode/kernel_patch.rb', line 100 def lock_feature(fname) lock = mu.synchronize do features[fname] ||= PathLock.new end # Can this even happen? return yield(true) if lock.resolved? # Recursive require if lock.owned? && lock.locked? warn "loading in progress, circular require considered harmful: #{fname}" if RequireHooks.print_warnings return yield(true) end lock.lock! begin yield(lock.resolved?).tap do lock.resolve! end ensure lock.unlock! mu.synchronize do features.delete(fname) end end end |
#locked_feature?(fname) ⇒ Boolean
128 129 130 |
# File 'lib/require-hooks/mode/kernel_patch.rb', line 128 def locked_feature?(fname) mu.synchronize { features.key?(fname) } end |