blob: 3bd5ca3d49a64e540219ea8db77ce0d44f4a9da2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/vespalib/util/threadexecutor.h>
#include <atomic>
namespace vespalib {
/**
* Implementation of the ThreadExecutor interface that runs all tasks in the foreground by the calling thread.
*/
class ForegroundThreadExecutor : public vespalib::ThreadExecutor {
private:
std::atomic<size_t> _accepted;
public:
ForegroundThreadExecutor() : _accepted(0) { }
Task::UP execute(Task::UP task) override {
task->run();
++_accepted;
return Task::UP();
}
size_t getNumThreads() const override { return 0; }
ExecutorStats getStats() override {
return ExecutorStats(ExecutorStats::QueueSizeT(), _accepted.load(std::memory_order_relaxed), 0);
}
void setTaskLimit(uint32_t taskLimit) override { (void) taskLimit; }
uint32_t getTaskLimit() const override { return std::numeric_limits<uint32_t>::max(); }
void wakeup() override { }
};
}
|