Skip to content

Commit

Permalink
Fix possible thread safety issue on non-GVL implementations in subcla…
Browse files Browse the repository at this point in the history
…sses plugin
  • Loading branch information
jeremyevans committed Apr 25, 2012
1 parent 45cd902 commit 11c05a5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/sequel/plugins/subclasses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,25 @@ module ClassMethods

# All descendent classes of this model.
def descendents
subclasses.map{|x| [x] + x.descendents}.flatten
Sequel.synchronize{_descendents}
end

# Add the subclass to this model's current subclasses,
# and initialize a new subclasses instance variable
# in the subclass.
def inherited(subclass)
super
subclasses << subclass
Sequel.synchronize{subclasses << subclass}
subclass.instance_variable_set(:@subclasses, [])
end

private

# Recursive, non-thread safe version of descendents, since
# the mutex Sequel uses isn't reentrant.
def _descendents
subclasses.map{|x| [x] + x.send(:_descendents)}.flatten
end
end
end
end
Expand Down

0 comments on commit 11c05a5

Please sign in to comment.