diff options
author | Xavier Noria <fxn@hashref.com> | 2015-11-21 18:08:14 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2015-11-21 18:08:14 +0100 |
commit | 49a5b408c9e23b937e93f6355b7b0a49a4a23184 (patch) | |
tree | 190f6e5a3c1c0fca6f0a0b5871aad67c836aed61 | |
parent | 96cc2e8335ab3e4166e476415753125864d88196 (diff) | |
download | rails-49a5b408c9e23b937e93f6355b7b0a49a4a23184.tar.gz rails-49a5b408c9e23b937e93f6355b7b0a49a4a23184.tar.bz2 rails-49a5b408c9e23b937e93f6355b7b0a49a4a23184.zip |
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.
-rw-r--r-- | activesupport/lib/active_support/file_evented_update_checker.rb | 16 |
1 files changed, 11 insertions, 5 deletions
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 |