From a25538df12db4d6e5c21f7f5fe99de5c1024c5f4 Mon Sep 17 00:00:00 2001 From: Umar Arshad Date: Thu, 12 Apr 2018 22:37:24 -0400 Subject: [PATCH] The enqueue function returns the number of items in the work queue --- async_queue.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/async_queue.hpp b/async_queue.hpp index 1a85300..0d8f7d2 100644 --- a/async_queue.hpp +++ b/async_queue.hpp @@ -56,20 +56,23 @@ class async_queue { /// /// \param func A function which will be enqueued on the work queue /// \param args The argument of the funciton \p func + /// \returns The number of items in the work queue. If called from the + /// worker thread then 0 is returned template - void enqueue(const F func, Args... args) { - if(std::this_thread::get_id() == queue_thread.get_id()) { + int enqueue(const F func, Args... args) { + int count = 0; + if(is_worker()) { func(args...); } else { auto no_arg_func = std::bind(func, std::forward(args)...); { lock_guard lock(queue_mutex); work_queue.push(no_arg_func); + count = work_queue.size(); } - cond.notify_one(); } - return; + return count; } /// \brief Check if the current thread of execution is same as the queue thread