Class: Polyphony::Monitor
Overview
Implements a fiber-aware Monitor class. This class replaces the stock
Monitor
class.
Instance Method Summary
collapse
Methods inherited from Mutex
#conditional_reacquire, #conditional_release, #initialize, #lock, #locked?, #owned?, #sleep, #synchronize, #try_lock, #unlock
Instance Method Details
#enter ⇒ Object
Also known as:
mon_enter
139
140
141
142
143
144
145
146
|
# File 'lib/polyphony/core/sync.rb', line 139
def enter
if @holding_fiber == Fiber.current
@holding_count += 1
else
lock
@holding_count = 1
end
end
|
#exit ⇒ Object
Also known as:
mon_exit
149
150
151
152
153
154
|
# File 'lib/polyphony/core/sync.rb', line 149
def exit
raise ThreadError if !owned?
@holding_count -= 1
unlock if @holding_count == 0
end
|
#mon_check_owner ⇒ Object
157
158
159
160
161
162
163
|
# File 'lib/polyphony/core/sync.rb', line 157
def mon_check_owner
if Fiber.current == @holding_fiber
nil
else
raise ThreadError, 'current fiber not owner'
end
end
|
#mon_locked? ⇒ Boolean
165
166
167
|
# File 'lib/polyphony/core/sync.rb', line 165
def mon_locked?
!!@holding_fiber
end
|
#mon_owned? ⇒ Boolean
169
170
171
|
# File 'lib/polyphony/core/sync.rb', line 169
def mon_owned?
@holding_fiber == Fiber.current
end
|
175
176
177
|
# File 'lib/polyphony/core/sync.rb', line 175
def new_cond
MonitorMixin::ConditionVariable.new(self)
end
|
#try_enter ⇒ Object
Also known as:
try_mon_enter
179
180
181
182
183
184
185
|
# File 'lib/polyphony/core/sync.rb', line 179
def try_enter
check_dead_holder
return false if @holding_fiber
enter
true
end
|
#wait_for_cond(cond, timeout) ⇒ Object
188
189
190
|
# File 'lib/polyphony/core/sync.rb', line 188
def wait_for_cond(cond, timeout)
cond.wait(self, timeout)
end
|