Skip to content

Commit

Permalink
Merge pull request #53 from MagLev/johnnyt/recursive-lock-fix
Browse files Browse the repository at this point in the history
Limit lock scope to prevent recursive locking
  • Loading branch information
tarcieri committed Jun 6, 2016
2 parents 75ad716 + d22d0b9 commit 3d45160
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/nio/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def registered?(io)

# Select which monitors are ready
def select(timeout = nil)
selected_monitors = Set.new

@lock.synchronize do
readers = [@wakeup]
writers = []
Expand All @@ -61,7 +63,6 @@ def select(timeout = nil)
ready_readers, ready_writers = Kernel.select readers, writers, [], timeout
return unless ready_readers # timeout or wakeup

selected_monitors = Set.new

ready_readers.each do |io|
if io == @wakeup
Expand All @@ -81,15 +82,15 @@ def select(timeout = nil)
monitor.readiness = (monitor.readiness == :r) ? :rw : :w
selected_monitors << monitor
end
end

if block_given?
selected_monitors.each do |m|
yield m
end
selected_monitors.size
else
selected_monitors
if block_given?
selected_monitors.each do |m|
yield m
end
selected_monitors.size
else
selected_monitors
end
end

Expand Down

0 comments on commit 3d45160

Please sign in to comment.