Class: ModSpox::Monitors::Boolean

Inherits:
Object
  • Object
show all
Defined in:
lib/mod_spox/Monitors.rb

Overview

The Boolean is a boolean based monitor (thus the “Boolean” part of the name)

Instance Method Summary collapse

Constructor Details

#initializeBoolean

Create a new Boolean Monitor



42
43
44
# File 'lib/mod_spox/Monitors.rb', line 42

def initialize
    @threads = []
end

Instance Method Details

#remove_thread(thread) ⇒ Object

Removes a thread from the list of waiting. Will be removed automatically if thread has been killed on next call to wakeup



72
73
74
# File 'lib/mod_spox/Monitors.rb', line 72

def remove_thread(thread)
    @threads.delete(thread) if @threads.include?(thread)
end

#thread_waiting?(thread) ⇒ Boolean

Returns if a thread is currently waiting in this monitor

Returns:



66
67
68
# File 'lib/mod_spox/Monitors.rb', line 66

def thread_waiting?(thread)
    return @threads.include?(thread)
end

#waitObject

Start waiting



60
61
62
63
# File 'lib/mod_spox/Monitors.rb', line 60

def wait
    @threads << Thread.current
    sleep
end

#wakeupObject

Stop waiting



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mod_spox/Monitors.rb', line 47

def wakeup
    return if @threads.empty?
    @threads.each do |t|
        begin
            t.wakeup
        rescue Object => boom
            # thread was dead #
        end
    end
    @threads.clear
end