From 0b9812bddea50f974d51175ae81bfd6d8407f946 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 22 Nov 2015 11:34:08 +0100 Subject: 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. --- activesupport/lib/active_support/file_evented_update_checker.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'activesupport/lib') 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 -- cgit v1.2.3