Skip to content
Browse files

Add a separate mutex for state

  • Loading branch information...
1 parent 13c89eb commit 7a15f967c505b7869591717f4708a4b8f0a8069a @eric eric committed Dec 1, 2013
Showing with 11 additions and 7 deletions.
  1. +11 −7 ext/c_zookeeper.rb
View
18 ext/c_zookeeper.rb
@@ -73,7 +73,8 @@ def initialize(host, event_queue, opts={})
@running_cond = @mutex.new_cond
# used to signal we've received the connected event
- @state_cond = @mutex.new_cond
+ @state_mutex = Monitor.new
+ @state_cond = @state_mutex.new_cond
# the current state of the connection
@state = ZOO_CLOSED_STATE
@@ -121,7 +122,7 @@ def associating?
end
def unhealthy?
- @_closed || @_shutting_down || is_unrecoverable
+ closed? || shutting_down? || is_unrecoverable
end
def healthy?
@@ -172,7 +173,7 @@ def resume_after_fork_in_parent
def state
return ZOO_CLOSED_STATE if closed?
- @mutex.synchronize { @state }
+ @state_mutex.synchronize { @state }
end
# this implementation is gross, but i don't really see another way of doing it
@@ -187,7 +188,7 @@ def wait_until_connected(timeout=10)
return false unless wait_until_running(timeout)
- @mutex.synchronize do
+ @state_mutex.synchronize do
while true
if timeout
now = Time.now
@@ -329,8 +330,8 @@ def iterate_event_delivery
if (hash[:req_id] == ZKRB_GLOBAL_CB_REQ) && (hash[:type] == -1)
ev_state = hash[:state]
- if @state != ev_state
- @mutex.synchronize do
+ @state_mutex.synchronize do
+ if @state != ev_state
@state = ev_state
@state_cond.broadcast
end
@@ -368,9 +369,12 @@ def shut_down!
@mutex.synchronize do
@_shutting_down = true
# ollie ollie oxen all home free!
- @state_cond.broadcast
@running_cond.broadcast
end
+
+ @state_mutex.synchronize do
+ @state_cond.broadcast
+ end
end
# called by underlying C code to signal we're running

0 comments on commit 7a15f96

Please sign in to comment.
Something went wrong with that request. Please try again.