Skip to content

Commit

Permalink
[squash] implement bnoordhuis suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Sep 20, 2017
1 parent a0a1c07 commit 75bb3c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
16 changes: 6 additions & 10 deletions src/node_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ static void RunForegroundTask(uv_timer_t* handle) {
}

void NodePlatform::DrainBackgroundTasks() {
do {
FlushForegroundTasksInternal();
while (FlushForegroundTasksInternal())
background_tasks_.BlockingDrain();
} while (foreground_tasks_.HasPending());
}

void NodePlatform::FlushForegroundTasksInternal() {
bool NodePlatform::FlushForegroundTasksInternal() {
bool did_work = false;
while (auto delayed = foreground_delayed_tasks_.Pop()) {
did_work = true;
uint64_t delay_millis =
static_cast<uint64_t>(delayed->second + 0.5) * 1000;
uv_timer_t* handle = new uv_timer_t();
Expand All @@ -106,8 +106,10 @@ void NodePlatform::FlushForegroundTasksInternal() {
delete delayed;
}
while (Task* task = foreground_tasks_.Pop()) {
did_work = true;
RunForegroundTask(task);
}
return did_work;
}

void NodePlatform::CallOnBackgroundThread(Task* task,
Expand Down Expand Up @@ -200,10 +202,4 @@ void TaskQueue<T>::Stop() {
tasks_available_.Broadcast(scoped_lock);
}

template <class T>
bool TaskQueue<T>::HasPending() {
Mutex::ScopedLock scoped_lock(lock_);
return !task_queue_.empty();
}

} // namespace node
4 changes: 2 additions & 2 deletions src/node_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class TaskQueue {
void NotifyOfCompletion();
void BlockingDrain();
void Stop();
bool HasPending();

private:
Mutex lock_;
Expand All @@ -40,7 +39,8 @@ class NodePlatform : public v8::Platform {
virtual ~NodePlatform() {}

void DrainBackgroundTasks();
void FlushForegroundTasksInternal();
// returns true iff work was dispatched or executed
bool FlushForegroundTasksInternal();
void Shutdown();

// v8::Platform implementation.
Expand Down

0 comments on commit 75bb3c4

Please sign in to comment.