Skip to content

Commit 23c1158

Browse files
committed
Add "enqueued" state to base::task
1 parent bccb4f2 commit 23c1158

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

base/task.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ task_token& task::start(thread_pool& pool)
3636

3737
// Reset flags for a running task
3838
m_running = true;
39+
m_enqueued = true;
3940
m_completed = false;
4041
m_token.reset();
4142

@@ -45,6 +46,7 @@ task_token& task::start(thread_pool& pool)
4546

4647
void task::in_worker_thread()
4748
{
49+
m_enqueued = false;
4850
try {
4951
if (!m_token.canceled())
5052
m_execute(m_token);

base/task.h

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class task {
6767

6868
bool running() const { return m_running; }
6969

70+
// Returns true when the task is enqueued in the thread pool's work queue,
71+
// and false when the task is actually being executed.
72+
bool enqueued() const { return m_enqueued; }
73+
7074
// Returns true when the task is completed (whether it was
7175
// canceled or not). If this is true, it's safe to delete the task
7276
// instance (it will not be used anymore by any othe background
@@ -77,6 +81,7 @@ class task {
7781
void in_worker_thread();
7882

7983
std::atomic<bool> m_running;
84+
std::atomic<bool> m_enqueued;
8085
std::atomic<bool> m_completed;
8186
task_token m_token;
8287
func_t m_execute;

0 commit comments

Comments
 (0)