]> git.sesse.net Git - bmusb/commitdiff
Fix a queue access not under a mutex.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 14 Nov 2015 12:55:22 +0000 (13:55 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 14 Nov 2015 12:55:22 +0000 (13:55 +0100)
bmusb.cpp

index 8639b938969bb0169640e8266c53afcdfb60afea..0582b99631b5d30de538adb5e50b12002504e66e 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -120,6 +120,7 @@ bool uint16_less_than_with_wraparound(uint16_t a, uint16_t b)
 
 void BMUSBCapture::queue_frame(uint16_t format, uint16_t timecode, FrameAllocator::Frame frame, deque<QueuedFrame> *q)
 {
+       unique_lock<mutex> lock(queue_lock);
        if (!q->empty() && !uint16_less_than_with_wraparound(q->back().timecode, timecode)) {
                printf("Blocks going backwards: prev=0x%04x, cur=0x%04x (dropped)\n",
                        q->back().timecode, timecode);
@@ -131,11 +132,7 @@ void BMUSBCapture::queue_frame(uint16_t format, uint16_t timecode, FrameAllocato
        qf.format = format;
        qf.timecode = timecode;
        qf.frame = frame;
-
-       {
-               unique_lock<mutex> lock(queue_lock);
-               q->push_back(move(qf));
-       }
+       q->push_back(move(qf));
        queues_not_empty.notify_one();  // might be spurious
 }