更新队列长度为1,避免残留问题
This commit is contained in:
parent
c30ae1e12d
commit
a212ca4d4d
@ -58,13 +58,18 @@ struct DetectionResult {
|
||||
extern DetectionResult g_detection_result[2];
|
||||
|
||||
// 线程安全队列模板类
|
||||
// 线程安全队列模板类,最大长度为1避免队列数据或者结果的积压
|
||||
template <typename T>
|
||||
class ThreadSafeQueue{
|
||||
class ThreadSafeQueue {
|
||||
public:
|
||||
// 添加元素到队列
|
||||
// 添加元素到队列,如果队列已满(长度为1),则移除旧元素
|
||||
void enqueue(const T& item)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
if (queue_.size() >= 1)
|
||||
{
|
||||
queue_.pop(); // 移除旧的元素
|
||||
}
|
||||
queue_.push(item);
|
||||
cond_var_.notify_one();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user