]> git.sesse.net Git - casparcg/blobdiff - common/polling_filesystem_monitor.cpp
[streaming_consumer] Started the process of retiring ffmpeg_consumer so that streamin...
[casparcg] / common / polling_filesystem_monitor.cpp
index c5013fcd7d8d931024ece682f536658a2cd7050a..c189218ea31ab0d450ef545009477131c33e241f 100644 (file)
@@ -88,13 +88,18 @@ public:
        {
        }
 
-       void reemmit_all()
+       void reemmit_all(const tbb::atomic<bool>& running)
        {
                if (static_cast<int>(events_mask_ & filesystem_event::MODIFIED) == 0)
                        return;
 
                for (auto& file : files_)
+               {
+                       if (!running)
+                               return;
+
                        handler_(filesystem_event::MODIFIED, file.first);
+               }
        }
 
        void reemmit(const boost::filesystem::path& file)
@@ -200,15 +205,15 @@ private:
 
 class polling_filesystem_monitor : public filesystem_monitor
 {
+       tbb::atomic<bool> running_;
        std::shared_ptr<boost::asio::io_service> scheduler_;
        directory_monitor root_monitor_;
-       executor executor_;
        boost::asio::deadline_timer timer_;
-       tbb::atomic<bool> running_;
        int scan_interval_millis_;
        std::promise<void> initial_scan_completion_;
        tbb::concurrent_queue<boost::filesystem::path> to_reemmit_;
        tbb::atomic<bool> reemmit_all_;
+       executor executor_;
 public:
        polling_filesystem_monitor(
                        const boost::filesystem::path& folder_to_watch,
@@ -220,9 +225,9 @@ public:
                        const initial_files_handler& initial_files_handler)
                : scheduler_(std::move(scheduler))
                , root_monitor_(report_already_existing, folder_to_watch, events_of_interest_mask, handler, initial_files_handler)
-               , executor_(L"polling_filesystem_monitor")
                , timer_(*scheduler_)
                , scan_interval_millis_(scan_interval_millis)
+               , executor_(L"polling_filesystem_monitor")
        {
                running_ = true;
                reemmit_all_ = false;
@@ -289,10 +294,10 @@ private:
                try
                {
                        if (reemmit_all_.fetch_and_store(false))
-                               root_monitor_.reemmit_all();
+                               root_monitor_.reemmit_all(running_);
                        else
                        {
-                               boost::filesystem::wpath file;
+                               boost::filesystem::path file;
 
                                while (to_reemmit_.try_pop(file))
                                        root_monitor_.reemmit(file);