]> git.sesse.net Git - nageru/commitdiff
Make quitting a tad bit more robust.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 11 Oct 2015 22:16:28 +0000 (00:16 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 11 Oct 2015 22:16:28 +0000 (00:16 +0200)
mixer.cpp
mixer.h

index 5b2d0da6324eb6e2485a8674afb182a44b75b575..1f83215bf05152c52fd1bd2dee263b879651bf5d 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -151,8 +151,11 @@ Mixer::~Mixer()
        BMUSBCapture::stop_bm_thread();
 
        for (int card_index = 0; card_index < NUM_CARDS; ++card_index) {
-               cards[card_index].new_data_ready = false;  // Unblock thread.
-               cards[card_index].new_data_ready_changed.notify_all();
+               {
+                       std::unique_lock<std::mutex> lock(bmusb_mutex);
+                       cards[card_index].should_quit = true;  // Unblock thread.
+                       cards[card_index].new_data_ready_changed.notify_all();
+               }
                cards[card_index].usb->stop_dequeue_thread();
        }
 }
@@ -176,7 +179,8 @@ void Mixer::bm_frame(int card_index, uint16_t timecode,
        {
                // Wait until the previous frame was consumed.
                std::unique_lock<std::mutex> lock(bmusb_mutex);
-               card->new_data_ready_changed.wait(lock, [card]{ return !card->new_data_ready; });
+               card->new_data_ready_changed.wait(lock, [card]{ return !card->new_data_ready || card->should_quit; });
+               if (card->should_quit) return;
        }
        const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)video_frame.userdata;
        GLuint pbo = userdata->pbo;
diff --git a/mixer.h b/mixer.h
index 9b631e4766071d35e6f0d215cd3f4442f46cdf2e..3275b24a85c66c1529086e4df23b48d0ba29d89b 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -114,6 +114,7 @@ private:
                QOpenGLContext *context;
 
                bool new_data_ready = false;  // Whether new_frame and new_frame_audio contains anything.
+               bool should_quit = false;
                RefCountedFrame new_frame;
                GLsync new_data_ready_fence;  // Whether new_frame is ready for rendering.
                std::vector<float> new_frame_audio;