Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit lock scope to prevent recursive locking #53

Merged
merged 1 commit into from
Jun 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/nio/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def registered?(io)

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

@lock.synchronize do
readers, writers = [@wakeup], []

Expand All @@ -63,7 +65,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 @@ -88,15 +89,15 @@ def select(timeout = nil)
end
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