summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-10-22 10:03:30 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-10-22 10:03:30 +0000
commit4060207695d6b8ebb22fee8274a83cfb78ec84fd (patch)
tree55bd02d2b8fa5dc73346043821b349a5583d5e1a
parent0e4d9d83d10891dcb34beda2ac9e1209a9b2e489 (diff)
Do accounting when you are put to be, and when you are woken up.
Not when you fall asleep, and when you wake up.
-rw-r--r--vespalib/src/vespa/vespalib/util/threadstackexecutorbase.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.cpp b/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.cpp
index aeaeea51746..53777ee6e6b 100644
--- a/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.cpp
+++ b/vespalib/src/vespa/vespalib/util/threadstackexecutorbase.cpp
@@ -122,17 +122,12 @@ ThreadStackExecutorBase::obtainTask(Worker &worker)
return false;
}
_workers.push(&worker);
- //TODO Not entirely correct as this counts working days, not wakeUps.
- //But it should be the same, and here it is thread safe.
- _stats.wakeupCount++;
+ worker.idleTracker.set_idle(steady_clock::now());
}
{
unique_lock guard(worker.lock);
while (worker.idle) {
- worker.idleTracker.set_idle(steady_clock::now());
worker.cond.wait(guard);
- //TODO: _idleTracker.was_idle is not thread safe !!!! Must find other solution. Atomic ?
- _idleTracker.was_idle(worker.idleTracker.set_active(steady_clock::now()));
}
}
worker.idle = !worker.task.task;
@@ -260,6 +255,8 @@ ThreadStackExecutorBase::execute(Task::UP task)
if (!_workers.empty()) {
Worker *worker = _workers.back();
_workers.popBack();
+ _idleTracker.was_idle(worker->idleTracker.set_active(steady_clock::now()));
+ _stats.wakeupCount++;
guard.unlock(); // <- UNLOCK
assignTask(std::move(taggedTask), *worker);
} else {