File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,10 +39,20 @@ void Worker::Join(void) {
3939void Worker::_Run (void * data) {
4040 TaskQueue* queue = static_cast <TaskQueue*>(data);
4141 while (std::unique_ptr<Task> task = queue->BlockingPop ()) {
42+ task->UpdateState (Task::ASSIGNED );
4243 task->Run ();
44+ task->UpdateState (Task::COMPLETED );
4345 }
4446}
4547
48+ /* *************
49+ * Task
50+ ***************/
51+
52+ void Task::UpdateState (enum State state) {
53+ state_ = state;
54+ }
55+
4656/* *************
4757 * LibuvExecutor
4858 ***************/
@@ -139,8 +149,10 @@ bool TaskQueue::Push(std::unique_ptr<Task> task) {
139149 return false ;
140150 }
141151
152+ task->UpdateState (Task::QUEUED );
142153 queue_.push (std::move (task));
143154 tasks_available_.Signal (scoped_lock);
155+
144156 return true ;
145157}
146158
Original file line number Diff line number Diff line change @@ -73,17 +73,28 @@ class TaskDetails {
7373// - User work from the N-API
7474class Task {
7575 public:
76+ enum State {
77+ QUEUED
78+ , ASSIGNED
79+ , COMPLETED
80+ };
81+
7682 Task () {}
7783 // Invoked after Run().
7884 virtual ~Task () {}
7985
8086 // Invoked on some thread in the Threadpool.
8187 virtual void Run () = 0;
8288
89+ // Different Threadpool components should update this as the Task travels around.
90+ void UpdateState (enum State state);
91+
8392 // Run() can access details.
8493 // Should be set in subclass constructor.
8594 TaskDetails details_;
86- private:
95+
96+ protected:
97+ enum State state_;
8798};
8899
89100// Shim that we plug into the libuv "pluggable TP" interface.
You can’t perform that action at this time.
0 commit comments