X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=image_input.cpp;fp=image_input.cpp;h=5c9d7966cd7404b395ddab4ecaf40523c9215549;hb=18347d8325cadd11ce732c7cdcb9b55c727e4938;hp=a224af9d47e1d8fc5a0f16ac702f5ce66cbdd7d5;hpb=1cacf7d830e44a2e153ae9f15589666b5153e9b5;p=nageru diff --git a/image_input.cpp b/image_input.cpp index a224af9..5c9d796 100644 --- a/image_input.cpp +++ b/image_input.cpp @@ -246,7 +246,10 @@ void ImageInput::update_thread_func(const std::string &filename, const std::stri timespec last_modified = first_modified; struct stat buf; for ( ;; ) { - sleep(1); + { + unique_lock lock(threads_should_quit_mu); + threads_should_quit_modified.wait_for(lock, chrono::seconds(1), []() { return threads_should_quit; }); + } if (threads_should_quit) { return; @@ -275,9 +278,11 @@ void ImageInput::update_thread_func(const std::string &filename, const std::stri void ImageInput::shutdown_updaters() { - // TODO: Kick these out of the sleep before one second? - threads_should_quit = true; - + { + unique_lock lock(threads_should_quit_mu); + threads_should_quit = true; + threads_should_quit_modified.notify_all(); + } for (auto &it : update_threads) { it.second.join(); } @@ -286,4 +291,6 @@ void ImageInput::shutdown_updaters() mutex ImageInput::all_images_lock; map> ImageInput::all_images; map ImageInput::update_threads; -volatile bool ImageInput::threads_should_quit = false; +mutex ImageInput::threads_should_quit_mu; +bool ImageInput::threads_should_quit = false; +condition_variable ImageInput::threads_should_quit_modified;