Class: Semaphore
- Inherits:
-
Object
- Object
- Semaphore
- Defined in:
- lib/farcall/monitor_lock.rb
Overview
:nodoc:
Instance Method Summary collapse
- #clear ⇒ Object
- #clear? ⇒ Boolean
-
#initialize(state_set = false) ⇒ Semaphore
constructor
A new instance of Semaphore.
- #set(new_state = true) ⇒ Object
- #set? ⇒ Boolean
- #wait(state) ⇒ Object
- #wait_change(&block) ⇒ Object
- #wait_clear ⇒ Object
- #wait_set ⇒ Object
Constructor Details
#initialize(state_set = false) ⇒ Semaphore
Returns a new instance of Semaphore.
29 30 31 32 |
# File 'lib/farcall/monitor_lock.rb', line 29 def initialize state_set=false @monitor = MontorLock.new @state_set = state_set end |
Instance Method Details
#clear ⇒ Object
71 72 73 |
# File 'lib/farcall/monitor_lock.rb', line 71 def clear set false end |
#clear? ⇒ Boolean
38 39 40 |
# File 'lib/farcall/monitor_lock.rb', line 38 def clear? !set? end |
#set(new_state = true) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/farcall/monitor_lock.rb', line 64 def set new_state=true if @state_set != new_state @state_set = new_state @monitor.notify end end |
#set? ⇒ Boolean
34 35 36 |
# File 'lib/farcall/monitor_lock.rb', line 34 def set? @state_set end |
#wait(state) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/farcall/monitor_lock.rb', line 42 def wait state while @state_set != state do @monitor.wait end @state_set end |
#wait_change(&block) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/farcall/monitor_lock.rb', line 57 def wait_change &block @monitor.wait { block.call(@state_set) if block } @state_set end |
#wait_clear ⇒ Object
53 54 55 |
# File 'lib/farcall/monitor_lock.rb', line 53 def wait_clear wait false end |
#wait_set ⇒ Object
49 50 51 |
# File 'lib/farcall/monitor_lock.rb', line 49 def wait_set wait true end |