Skip to content

Commit

Permalink
Return early if packetqueue is empty instead of getting the lock. Ret…
Browse files Browse the repository at this point in the history
…urn early in clear() if we are not initialised
  • Loading branch information
Isaac Connor committed Jun 13, 2021
1 parent 28d813b commit 9f8c8a2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/zm_packetqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ void PacketQueue::clearPackets(const std::shared_ptr<ZMPacket> &add_packet) {
// So start at the beginning, counting video packets until the next keyframe.
// Then if deleting those packets doesn't break 1 and 2, then go ahead and delete them.
if (deleting) return;
if (!pktQueue.size()) return;

if (keep_keyframes and ! (
add_packet->packet.stream_index == video_stream_id
Expand All @@ -197,7 +198,6 @@ void PacketQueue::clearPackets(const std::shared_ptr<ZMPacket> &add_packet) {
return;
}
std::unique_lock<std::mutex> lck(mutex);
if (!pktQueue.size()) return;

// If analysis_it isn't at the end, we need to keep that many additional packets
int tail_count = 0;
Expand Down Expand Up @@ -325,6 +325,8 @@ void PacketQueue::clearPackets(const std::shared_ptr<ZMPacket> &add_packet) {
void PacketQueue::clear() {
deleting = true;
condition.notify_all();
if (!packet_counts) // special case, not initialised
return;
Debug(1, "Clearing packetqueue");
std::unique_lock<std::mutex> lck(mutex);

Expand Down

0 comments on commit 9f8c8a2

Please sign in to comment.