Skip to content

Commit

Permalink
Weakbucket is now thread-safe on the jrubies. Closes #355.
Browse files Browse the repository at this point in the history
Thanks to John Shahid for finding the root cause, and Charlie Nutter for feedback on the patch.
  • Loading branch information
flavorjones committed Dec 21, 2010
1 parent 702affb commit 54e1fca
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/nokogiri/ffi/weak_bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
require 'weakling'
Nokogiri::VERSION_INFO['refs'] = "weakling"
end
require 'singleton'

module Nokogiri
class WeakBucket
include Singleton

if Nokogiri::VERSION_INFO['refs'] == "weakling"
attr_accessor :bucket

def initialize
@bucket = Weakling::IdHash.new
end
@@bucket = Weakling::IdHash.new
@@semaphore = Mutex.new

def WeakBucket.get_object(cstruct)
instance.bucket[cstruct.ruby_node_pointer]
@@semaphore.synchronize do
@@bucket[cstruct.ruby_node_pointer]
end
end

def WeakBucket.set_object(cstruct, object)
cstruct.ruby_node_pointer = instance.bucket.add(object)
@@semaphore.synchronize do
cstruct.ruby_node_pointer = @@bucket.add(object)
end
end

else

def WeakBucket.get_object(cstruct)
ptr = cstruct.ruby_node_pointer
ptr != 0 ? ObjectSpace._id2ref(ptr) : nil
Expand Down

0 comments on commit 54e1fca

Please sign in to comment.