From: Razvan Becheriu Date: Wed, 18 Sep 2019 11:27:26 +0000 (+0300) Subject: [#883, !506] use nullptr for empty task X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c982135373ace88182303513a25b916c5a6c4ca8;p=thirdparty%2Fkea.git [#883, !506] use nullptr for empty task --- diff --git a/src/lib/dhcpsrv/thread_pool.cc b/src/lib/dhcpsrv/thread_pool.cc index 2b2c7db484..0a5c206d01 100644 --- a/src/lib/dhcpsrv/thread_pool.cc +++ b/src/lib/dhcpsrv/thread_pool.cc @@ -58,6 +58,9 @@ struct ThreadPoolQueue { /// /// @param item the new item to be added to the queue void push(WorkItem& item) { + if (item == nullptr) { + return; + } std::lock_guard lock(mutex_); queue_.push(item); // Notify pop function so that it can effectively remove a work item. @@ -77,7 +80,7 @@ struct ThreadPoolQueue { /// /// @return true if there was a work item removed from the queue, false /// otherwise - WorkItem pop(bool& found) { + WorkItem pop() { std::unique_lock lock(mutex_); while (!exit_) { if (queue_.empty()) { @@ -88,12 +91,10 @@ struct ThreadPoolQueue { WorkItem item = queue_.front(); queue_.pop(); - found = true; return item; } - found = false; - return WorkItem(); + return nullptr; } /// @brief count number of work items in the queue @@ -232,9 +233,8 @@ void ThreadPool::run() { LOG_INFO(dhcpsrv_logger, "Thread pool thread started. id: %1").arg(th_id); while (!exit_) { - bool found = false; - WorkItemCallBack item = queue_->pop(found); - if (found) { + WorkItemCallBack item = queue_->pop(); + if (item != nullptr) { item(); } }