aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2015-11-22 11:34:08 +0100
committerXavier Noria <fxn@hashref.com>2015-11-22 11:34:08 +0100
commit0b9812bddea50f974d51175ae81bfd6d8407f946 (patch)
treef37bb776c994e4674580097025a393a79218c2b9 /activesupport/lib
parent4596c1a31902806a15c970a0e210942912b139b6 (diff)
downloadrails-0b9812bddea50f974d51175ae81bfd6d8407f946.tar.gz
rails-0b9812bddea50f974d51175ae81bfd6d8407f946.tar.bz2
rails-0b9812bddea50f974d51175ae81bfd6d8407f946.zip
removes the mutex around `changed`
This method needs to ensure that if a change happens, it is going to be registered. With this refactor suggested by @matthewd race conditions do not matter because if no file is watched, nothing is done. And as long as some invocation sets the flag to true, it will stay true. The refactor leaves a race condition in which two simultaneous threads that watch some of the files passed do the actual work in `any?`, whereas the mutex guaranteed that was done at most once. But this is considered to be a better tradeoff.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/file_evented_update_checker.rb9
1 files changed, 2 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/file_evented_update_checker.rb b/activesupport/lib/active_support/file_evented_update_checker.rb
index fbc3fa2147..bb0f26f874 100644
--- a/activesupport/lib/active_support/file_evented_update_checker.rb
+++ b/activesupport/lib/active_support/file_evented_update_checker.rb
@@ -1,7 +1,6 @@
require 'listen'
require 'set'
require 'pathname'
-require 'thread'
require 'concurrent/atomic/atomic_boolean'
module ActiveSupport
@@ -22,8 +21,6 @@ module ActiveSupport
if (dtw = directories_to_watch).any?
Listen.to(*dtw, &method(:changed)).start
end
-
- @mutex = Mutex.new
end
def updated?
@@ -45,10 +42,8 @@ module ActiveSupport
private
def changed(modified, added, removed)
- @mutex.synchronize do
- unless updated?
- @updated.value = (modified + added + removed).any? { |f| watching?(f) }
- end
+ unless updated?
+ @updated.make_true if (modified + added + removed).any? { |f| watching?(f) }
end
end