diff --git a/usb/ddk/host/src/ddk_uevent_queue.cpp b/usb/ddk/host/src/ddk_uevent_queue.cpp index aa83165442b1b28bf56fe4353776e6de63da95d3..2c30cb09bc6d745643c2e2ed18e95758ae30b447 100644 --- a/usb/ddk/host/src/ddk_uevent_queue.cpp +++ b/usb/ddk/host/src/ddk_uevent_queue.cpp @@ -54,6 +54,7 @@ class TaskQueue { public: TaskQueue() = default; void Init(void); + void UnInit(void); ~TaskQueue(); int32_t AddTask(const DdkUeventTaskInfo &task); @@ -153,7 +154,7 @@ void TaskQueue::Init(void) pthread_setname_np(pthread_self(), "ueventTaskQueue"); auto taskWork = [this]() -> void { while (threadRun_) { - std::unique_lock uniqueLock(queueLock_); + std::unique_lock uniqueLock(queueLock_); conditionVariable_.wait(uniqueLock, [this] { return (taskQueue_.size() > 0 || !threadRun_); }); @@ -171,10 +172,22 @@ void TaskQueue::Init(void) thd.detach(); } -TaskQueue::~TaskQueue() + + +void TaskQueue::UnInit(void) { threadRun_ = false; conditionVariable_.notify_one(); + + std::lock_guard lock(queueLock_); + while (!taskQueue_.empty()) { + taskQueue_.pop(); + } +} + +TaskQueue::~TaskQueue() +{ + UnInit(); } int32_t TaskQueue::AddTask(const DdkUeventTaskInfo &task) @@ -189,7 +202,7 @@ int32_t TaskQueue::AddTask(const DdkUeventTaskInfo &task) return HDF_SUCCESS; } -TaskQueue g_taskQueue; +static TaskQueue g_taskQueue; int32_t DdkUeventStartDispatchThread() {