Skip to content

Commit

Permalink
Renamed instance variable to reflect the fact that we now use a monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe Hanrigou committed Jan 19, 2010
1 parent ed90ff9 commit c529a26
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
9 changes: 8 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
=== 1.1.3/ 2009-29-11
=== 1.1.4/ 2010-01-18

* Changed from using Mutex to Monitor. Evidently Mutex causes thread join
errors when Ruby is compiled with -disable-pthreads
(Contributed by [Dmytro Shteflyuk](http://kpumuk.info/))


=== 1.1.3/ 2009-11-29

* Preparing GemCutter migration

Expand Down
12 changes: 10 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ a convenience shell wrapping a simple call to timeout.rb under the cover.
== Authors

* David Vollbracht <http://davidvollbracht.com>
* Philippe Hanrigou <http:/ph7spot.com>

* Philippe Hanrigou <http://ph7spot.com>

== Contributor

* Dmytro Shteflyuk <http://kpumuk.info/> :

- Changed from using Mutex to Monitor. Evidently Mutex causes thread
join errors when Ruby is compiled with -disable-pthreads
<http://github.com/ph7/system-timer/commit/50cfbb1177e2163295d34649e98205a3a26dc451>

== Copyright

Copyright:: (C) 2008 David Vollbracht & Philippe Hanrigou
Expand Down
12 changes: 6 additions & 6 deletions lib/system_timer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#
module SystemTimer

Thread.exclusive do # Avoid race conditions for mutex and pool creation
Thread.exclusive do # Avoid race conditions for monitor and pool creation
@timer_pool = ConcurrentTimerPool.new
@mutex = Monitor.new
@monitor = Monitor.new
end

class << self
Expand All @@ -43,7 +43,7 @@ class << self
# the execution and raises a +Timeout::Error+.
def timeout_after(seconds)
new_timer = nil # just for scope
@mutex.synchronize do
@monitor.synchronize do
new_timer = timer_pool.add_timer seconds
timer_interval = timer_pool.next_trigger_interval_in_seconds
debug "==== Install Timer ==== at #{Time.now.to_i}, next interval: #{timer_interval}"
Expand All @@ -55,7 +55,7 @@ def timeout_after(seconds)
end
return yield
ensure
@mutex.synchronize do
@monitor.synchronize do
debug "==== Cleanup Timer ==== at #{Time.now.to_i}, #{new_timer} "
timer_pool.cancel new_timer
timer_pool.log_registered_timers if debug_enabled?
Expand All @@ -76,7 +76,7 @@ def timeout_after(seconds)

def install_ruby_sigalrm_handler #:nodoc:
@original_ruby_sigalrm_handler = trap('SIGALRM') do
@mutex.synchronize do
@monitor.synchronize do
# Triggers timers one at a time to ensure more deterministic results
timer_pool.trigger_next_expired_timer
end
Expand Down Expand Up @@ -105,4 +105,4 @@ def debug(message) #:nodoc

end

require 'system_timer_native'
require 'system_timer_native'

0 comments on commit c529a26

Please sign in to comment.