From 49a5b408c9e23b937e93f6355b7b0a49a4a23184 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 21 Nov 2015 18:08:14 +0100 Subject: make the @updated flag atomic in the evented monitor listen is calling us from its own thread, we need to synchronize reads and writes to this flag. --- .../lib/active_support/file_evented_update_checker.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 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 638458c6ce..85d392b265 100644 --- a/activesupport/lib/active_support/file_evented_update_checker.rb +++ b/activesupport/lib/active_support/file_evented_update_checker.rb @@ -1,6 +1,8 @@ require 'listen' require 'set' require 'pathname' +require 'thread' +require 'concurrent/atomic/atomic_boolean' module ActiveSupport class FileEventedUpdateChecker #:nodoc: all @@ -14,22 +16,24 @@ module ActiveSupport end @block = block - @updated = false + @updated = Concurrent::AtomicBoolean.new(false) @lcsp = @ph.longest_common_subpath(@dirs.keys) if (dtw = directories_to_watch).any? Listen.to(*dtw, &method(:changed)).start end + + @mutex = Mutex.new end def updated? - @updated + @updated.true? end def execute @block.call ensure - @updated = false + @updated.make_false end def execute_if_updated @@ -42,8 +46,10 @@ module ActiveSupport private def changed(modified, added, removed) - unless updated? - @updated = (modified + added + removed).any? { |f| watching?(f) } + @mutex.synchronize do + unless updated? + @updated.value = (modified + added + removed).any? { |f| watching?(f) } + end end end -- cgit v1.2.3