Module: Salus::Lockable
- Included in:
- CountDownLatch, Group, Metric, ObserversSet
- Defined in:
- lib/salus/thread/lockable.rb
Overview
Based on code from github.com/ruby-concurrency/concurrent-ruby/
Instance Method Summary collapse
- #broadcast ⇒ Object
- #signal ⇒ Object
- #synchronize ⇒ Object
- #wait(timeout = nil) ⇒ Object
- #wait_until(timeout = nil, &condition) ⇒ Object
Instance Method Details
#broadcast ⇒ Object
17 18 19 20 |
# File 'lib/salus/thread/lockable.rb', line 17 def broadcast __condition.broadcast self end |
#signal ⇒ Object
12 13 14 15 |
# File 'lib/salus/thread/lockable.rb', line 12 def signal __condition.signal self end |
#synchronize ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/salus/thread/lockable.rb', line 4 def synchronize if __lock.owned? yield else __lock.synchronize { yield } end end |
#wait(timeout = nil) ⇒ Object
37 38 39 |
# File 'lib/salus/thread/lockable.rb', line 37 def wait(timeout=nil) __wait(timeout) end |
#wait_until(timeout = nil, &condition) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/salus/thread/lockable.rb', line 22 def wait_until(timeout=nil, &condition) if timeout wait_until = MonotonicTime.get + timeout loop do now = MonotonicTime.get res = condition.call return res if now >= wait_until || res __wait(wait_until - now) end else __wait(timeout) until condition.call true end end |