+// Fire up a thread to update the image every second.
+// We could do inotify, but this is good enough for now.
+void ImageInput::update_thread_func(const std::string &pathname, const timespec &first_modified)
+{
+ timespec last_modified = first_modified;
+ struct stat buf;
+ for ( ;; ) {
+ sleep(1);
+
+ if (threads_should_quit) {
+ return;
+ }
+
+ if (stat(pathname.c_str(), &buf) != 0) {
+ fprintf(stderr, "%s: Couldn't check for new version, leaving the old in place.\n", pathname.c_str());
+ continue;
+ }
+ if (buf.st_mtim.tv_sec == last_modified.tv_sec &&
+ buf.st_mtim.tv_nsec == last_modified.tv_nsec) {
+ // Not changed.
+ continue;
+ }
+ shared_ptr<const Image> image = load_image_raw(pathname);
+ if (image == nullptr) {
+ fprintf(stderr, "Couldn't load image, leaving the old in place.\n");
+ continue;
+ }
+ fprintf(stderr, "Loaded new version of %s from disk.\n", pathname.c_str());
+ unique_lock<mutex> lock(all_images_lock);
+ all_images[pathname] = image;
+ last_modified = image->last_modified;
+ }
+}
+
+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();
+ }