Skip to content

Commit

Permalink
Simplify by removing locks.
Browse files Browse the repository at this point in the history
  • Loading branch information
birkirb committed Aug 23, 2012
1 parent e159960 commit 50d1737
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions lib/data_fabric/connection_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ def respond_to?(method)
super || connection.respond_to?(method)
end

def locks
Thread.current["#{@model_class}_locks"] ||= []
end

def method_missing(method, *args, &block)
DataFabric.logger.debug { "Calling #{method} on #{connection}" }
connection.send(method, *args, &block)
Expand Down Expand Up @@ -153,25 +149,15 @@ def current_pool

private

def fixed_role
Thread.current["#{@model_class}_fixed_role"]
end

def fixed_role=(arg)
Thread.current["#{@model_class}_fixed_role"] = arg
end

def with_fixed_role(new_role, &block)
# Allow nesting of with_master.
old_fixed_state = fixed_role
self.fixed_role = true
locks << true
old_role = current_role
set_role(new_role)
yield
ensure
locks.pop
set_role(old_role)
self.fixed_role = false if locks.empty?
self.fixed_role = old_fixed_state
end

def spec_for(config)
Expand Down Expand Up @@ -215,6 +201,14 @@ def current_role
Thread.current["#{@model_class}_role"] || 'slave'
end

def fixed_role=(arg)
Thread.current["#{@model_class}_fixed_role"] = arg
end

def fixed_role
Thread.current["#{@model_class}_fixed_role"] || false
end

def master
with_master { return connection }
end
Expand Down

0 comments on commit 50d1737

Please sign in to comment.