X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=image_input.cpp;fp=image_input.cpp;h=9a63c1eda09ae93f96cc059328375411b1a3c1ec;hb=7017a3bd997cbf5d7c327187afecfecd610bf24d;hp=5c1bd8f1f536e5b561c5eb1cee4d7ef26a071e97;hpb=8693cbdedf4c989ccbb1b31fb08e42c7a53c52b1;p=nageru diff --git a/image_input.cpp b/image_input.cpp index 5c1bd8f..9a63c1e 100644 --- a/image_input.cpp +++ b/image_input.cpp @@ -220,7 +220,6 @@ shared_ptr ImageInput::load_image_raw(const string &fil // Fire up a thread to update the image every second. // We could do inotify, but this is good enough for now. -// TODO: These don't really quit, ever. Should they? void ImageInput::update_thread_func(const std::string &filename, const timespec &first_modified) { timespec last_modified = first_modified; @@ -228,6 +227,10 @@ void ImageInput::update_thread_func(const std::string &filename, const timespec for ( ;; ) { sleep(1); + if (threads_should_quit) { + return; + } + if (stat(filename.c_str(), &buf) != 0) { fprintf(stderr, "%s: Couldn't check for new version, leaving the old in place.\n", filename.c_str()); continue; @@ -249,6 +252,17 @@ void ImageInput::update_thread_func(const std::string &filename, const timespec } } +void ImageInput::shutdown_updaters() +{ + // TODO: Kick these out of the sleep before one second? + threads_should_quit = true; + + for (auto &it : update_threads) { + it.second.join(); + } +} + mutex ImageInput::all_images_lock; map> ImageInput::all_images; map ImageInput::update_threads; +volatile bool ImageInput::threads_should_quit = false;