aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/executor_thread_service.h
blob: 8adb80889e79ce492222caebfb846830c2c5a201 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/searchcorespi/index/i_thread_service.h>
#include <vespa/vespalib/util/threadexecutor.h>

namespace proton {

namespace internal { struct ThreadId; }
/**
 * Implementation of IThreadService using an underlying thread stack executor
 * with a single thread.
 */
class ExecutorThreadService : public searchcorespi::index::IThreadService
{
private:
    vespalib::SyncableThreadExecutor &_executor;
    std::unique_ptr<internal::ThreadId>   _threadId;

public:
    ExecutorThreadService(vespalib::SyncableThreadExecutor &executor);
    ~ExecutorThreadService();

    Stats getStats() override;

    vespalib::Executor::Task::UP execute(vespalib::Executor::Task::UP task) override {
        return _executor.execute(std::move(task));
    }
    void run(vespalib::Runnable &runnable) override;
    vespalib::Syncable &sync() override {
        _executor.sync();
        return *this;
    }
    ExecutorThreadService & shutdown() override {
        _executor.shutdown();
        return *this;
    }
    bool isCurrentThread() const override;
    size_t getNumThreads() const override { return _executor.getNumThreads(); }

    void setTaskLimit(uint32_t taskLimit) override;
    uint32_t getTaskLimit() const override;
    void wakeup() override;
};

} // namespace proton