]> git.sesse.net Git - nageru/commitdiff
Yet more fixes for clean shutdown.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 2 May 2016 23:15:17 +0000 (01:15 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 2 May 2016 23:15:17 +0000 (01:15 +0200)
image_input.cpp
image_input.h
main.cpp
mixer.cpp
video_encoder.cpp
video_encoder.h

index 5c1bd8f1f536e5b561c5eb1cee4d7ef26a071e97..9a63c1eda09ae93f96cc059328375411b1a3c1ec 100644 (file)
@@ -220,7 +220,6 @@ shared_ptr<const ImageInput::Image> 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<string, shared_ptr<const ImageInput::Image>> ImageInput::all_images;
 map<string, thread> ImageInput::update_threads;
+volatile bool ImageInput::threads_should_quit = false;
index fbda72de6c36ddf69f660db77b78024afb5fc8cb..659404ea7c5954a191aeda2faf72e3ef774544e7 100644 (file)
@@ -20,7 +20,8 @@ public:
 
        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;
-
+       static void shutdown_updaters();
+       
 private:
        struct Image {
                std::unique_ptr<uint8_t[]> pixels;
@@ -36,6 +37,7 @@ private:
        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;
+       static volatile bool threads_should_quit;
 };
 
 #endif // !defined(_IMAGE_INPUT_H)
index 6cf1ddec055275855fd30bcd8824cfd4e0bd1aaf..a0d8f669ca083085deaca67119451303cd7226a4 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -14,6 +14,7 @@ extern "C" {
 
 #include "context.h"
 #include "flags.h"
+#include "image_input.h"
 #include "mainwindow.h"
 #include "mixer.h"
 
@@ -55,5 +56,6 @@ int main(int argc, char *argv[])
        global_mixer->quit();
        mainWindow.mixer_shutting_down();
        delete global_mixer;
+       ImageInput::shutdown_updaters();
        return rc;
 }
index fd982a5708d61d59f4dfca1204cd7dc6dda2e5d5..fa3a6de81086d4aa03bd7a8a83c3133f3909e151 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -828,7 +828,10 @@ void Mixer::audio_thread_func()
 
                {
                        unique_lock<mutex> lock(audio_mutex);
-                       audio_task_queue_changed.wait(lock, [this]{ return !audio_task_queue.empty(); });
+                       audio_task_queue_changed.wait(lock, [this]{ return should_quit || !audio_task_queue.empty(); });
+                       if (should_quit) {
+                               return;
+                       }
                        task = audio_task_queue.front();
                        audio_task_queue.pop();
                }
@@ -1078,6 +1081,7 @@ void Mixer::start()
 void Mixer::quit()
 {
        should_quit = true;
+       audio_task_queue_changed.notify_one();
        mixer_thread.join();
        audio_thread.join();
 }
index 63a7ba3b1e315363e4888039ac48158770b3b4b8..7719bbbc15c86d1ce2890a64e4117f7935c85a77 100644 (file)
@@ -64,7 +64,6 @@ VideoEncoder::~VideoEncoder()
        while (quicksync_encoders_in_shutdown.load() > 0) {
                usleep(10000);
        }
-       close_output_stream();
 }
 
 void VideoEncoder::do_cut(int frame)
@@ -144,11 +143,6 @@ void VideoEncoder::open_output_stream()
        stream_mux_header.clear();
 }
 
-void VideoEncoder::close_output_stream()
-{
-       stream_mux.reset();
-}
-
 int VideoEncoder::write_packet_thunk(void *opaque, uint8_t *buf, int buf_size)
 {
        VideoEncoder *video_encoder = (VideoEncoder *)opaque;
index 617b51842554b5db5f5325e4c1cfeafff94c591f..92f83572006ee8119fb102fb4b92b4d2638164f5 100644 (file)
@@ -43,7 +43,6 @@ public:
 
 private:
        void open_output_stream();
-       void close_output_stream();
        static int write_packet_thunk(void *opaque, uint8_t *buf, int buf_size);
        int write_packet(uint8_t *buf, int buf_size);