From 5aaf097fc0fd675f1744d1bbb401b5097670159e Mon Sep 17 00:00:00 2001 From: Lveyou <1339484752@qq.com> Date: Thu, 9 Jul 2026 16:00:27 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dl/base/dl_list_safe.h | 137 ----------------------------------------- 1 file changed, 137 deletions(-) delete mode 100644 dl/base/dl_list_safe.h diff --git a/dl/base/dl_list_safe.h b/dl/base/dl_list_safe.h deleted file mode 100644 index f9d64f55..00000000 --- a/dl/base/dl_list_safe.h +++ /dev/null @@ -1,137 +0,0 @@ -/** -* @file dl_list_mt.h -* @brief 多线程队列 -* -* -* @version 1.0 -* @author lveyou -* @date 26-03-04 -* -* @note 适用于一个线程(主要线程)添加任务,多个线程处理 -* 主要线程 调用Move将缓冲的任务立即刷新,否则任务可能不会执行 -* 例如,主线程Add增加任务,帧末尾调用Move,其他线程处理任务。参考 dl_thread_task.h -*/ -#pragma once - -#include - -namespace dl -{ - enum class QueueMode - { - FIFO, - FILO, - }; - - -//! 多线程队列 -template -class ListMultiThread -{ -public: - /** - * @brief 取第一个,顺序通过 SetQueueMode 指定,默认FIFO - * @note 线程B调用(处理线程) - * @retval 成功返回true,并弹出 - */ - bool PopFront(T& a) - { - _mutex.lock(); - if (_list.empty()) - { - _mutex.unlock(); - return false; - } - a = _list.front(); - _list.pop_front(); - _mutex.unlock(); - return true; - } - /** - * @brief 添加 - * @note 线程A调用 - */ - void Add(const T& buf) - { - if (_mutex.try_lock()) - { - _list.splice(_list.begin(), _listTemp); - _list.push_back(buf); - _mutex.unlock(); - return; - } - _listTemp.push_back(buf); - } - /** - * @brief 添加 - * @note 线程A调用 - */ - void Add(T&& buf) - { - if (_mutex.try_lock()) - { - _list.splice(_list.begin(), _listTemp); - _list.push_back(buf); - _mutex.unlock(); - return; - } - _listTemp.push_back(buf); - } - /** - * @brief 结束添加时调用,或立即刷新 - * @note 线程A调用 - */ - void Move() - { - if (_listTemp.empty()) - return; - _mutex.lock(); - _list.splice(_list.begin(), _listTemp); - _list.push_back(buf); - _mutex.unlock(); - } - /** - * @brief 添加 - * @note 线程A调用 - */ - size_t GetSize() - { - std::lock_guard guard{ _mutex }; - return _list.size() + _listTemp.size(); - } - /** - * @brief 所有任务完成 - * @note 线程A调用 - */ - bool IsEmpty() - { - std::lock_guard guard{ _mutex }; - return _list.empty() && _listTemp.empty(); - } - /** - * @brief 添加 - * @note 线程A调用 - */ - void Clear() - { - _mutex.lock(); - _list.clear(); - _mutex.unlock(); - _listTemp.clear(); - } - - void SetQueueMode(QueueMode mode) - { - _mode = mode; - } - - ListMultiThread(QueueMode mode = QueueMode::FIFO) : - _mode{ mode } - {} -private: - std::mutex _mutex;// 队列锁 - std::list _list;// 先入先出队列 - std::list _listTemp;// 主线程缓冲 - QueueMode _mode; -}; -} \ No newline at end of file