]> git.sesse.net Git - nageru/commitdiff
Name the ImageInput update threads, too.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 25 Jan 2017 18:25:44 +0000 (19:25 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 25 Jan 2017 18:25:44 +0000 (19:25 +0100)
image_input.cpp
image_input.h

index 70bffb0f863225c1673a42d3df0f14757ae7c6f2..9f474c94b14ae2b8bf315e0d0a4b2308f153b8f3 100644 (file)
@@ -71,8 +71,9 @@ string search_for_file(const string &filename)
 ImageInput::ImageInput(const string &filename)
        : movit::FlatInput({movit::COLORSPACE_sRGB, movit::GAMMA_sRGB}, movit::FORMAT_RGBA_POSTMULTIPLIED_ALPHA,
                           GL_UNSIGNED_BYTE, 1280, 720),  // FIXME
+         filename(filename),
          pathname(search_for_file(filename)),
-         current_image(load_image(pathname))
+         current_image(load_image(filename, pathname))
 {
        if (current_image == nullptr) {  // Could happen even though search_for_file() returned.
                fprintf(stderr, "Couldn't load image, exiting.\n");
@@ -99,7 +100,7 @@ void ImageInput::set_gl_state(GLuint glsl_program_num, const string& prefix, uns
        movit::FlatInput::set_gl_state(glsl_program_num, prefix, sampler_num);
 }
 
-shared_ptr<const ImageInput::Image> ImageInput::load_image(const string &pathname)
+shared_ptr<const ImageInput::Image> ImageInput::load_image(const string &filename, const string &pathname)
 {
        unique_lock<mutex> lock(all_images_lock);  // Held also during loading.
        if (all_images.count(pathname)) {
@@ -109,7 +110,7 @@ shared_ptr<const ImageInput::Image> ImageInput::load_image(const string &pathnam
        all_images[pathname] = load_image_raw(pathname);
        timespec first_modified = all_images[pathname]->last_modified;
        update_threads[pathname] =
-               thread(bind(update_thread_func, pathname, first_modified));
+               thread(bind(update_thread_func, filename, pathname, first_modified));
 
        return all_images[pathname];
 }
@@ -235,8 +236,12 @@ shared_ptr<const ImageInput::Image> ImageInput::load_image_raw(const string &pat
 
 // 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)
+void ImageInput::update_thread_func(const std::string &filename, const std::string &pathname, const timespec &first_modified)
 {
+       char thread_name[16];
+       snprintf(thread_name, sizeof(thread_name), "Update_%s", filename.c_str());
+       pthread_setname_np(pthread_self(), thread_name);
+
        timespec last_modified = first_modified;
        struct stat buf;
        for ( ;; ) {
index 11c94ce9b626ce65f5fde9a2af895e1fa35de8ad..437d9c2db72ace8b45de8698d2f61c2147ce3786 100644 (file)
@@ -17,7 +17,7 @@
 // from disk about every second.
 class ImageInput : public movit::FlatInput {
 public:
-       ImageInput(const std::string &pathname);
+       ImageInput(const std::string &filename);
 
        std::string effect_type_id() const override { return "ImageInput"; }
        void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num) override;
@@ -29,12 +29,12 @@ private:
                timespec last_modified;
        };
 
-       std::string pathname;
+       std::string filename, pathname;
        std::shared_ptr<const Image> current_image;
 
-       static std::shared_ptr<const Image> load_image(const std::string &pathname);
+       static std::shared_ptr<const Image> load_image(const std::string &filename, const std::string &pathname);
        static std::shared_ptr<const Image> load_image_raw(const std::string &pathname);
-       static void update_thread_func(const std::string &pathname, const timespec &first_modified);
+       static void update_thread_func(const std::string &filename, const std::string &pathname, const timespec &first_modified);
        static std::mutex all_images_lock;
        static std::map<std::string, std::shared_ptr<const Image>> all_images;
        static std::map<std::string, std::thread> update_threads;