aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storageframework/generic/thread/threadpool.h
blob: e4adc26d099e9c52a11da3183d38845d50b029a9 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 * \class storage::framework::ThreadPool
 * \ingroup thread
 *
 * \brief A threadpool implementation usable by storage components.
 *
 * Using this threadpool interface, we can use a threadpool without depending
 * on the actual implementation. Also, as information is provided of the
 * threads, monitoring tools, like the deadlock detector can extract information
 * about the threads.
 */
#pragma once

#include <atomic>
#include <vespa/vespalib/util/cpu_usage.h>
#include <optional>
#include <vector>

namespace storage::framework {

class Thread;
struct Runnable;

/** Interface used to access data for the existing threads. */
struct ThreadVisitor {
    virtual ~ThreadVisitor() = default;
    virtual void visitThread(const Thread& thread) = 0;
};

struct ThreadPool {
    virtual ~ThreadPool() = default;

    virtual std::unique_ptr<Thread>
    startThread(Runnable&, vespalib::stringref id, vespalib::duration waitTime,
                vespalib::duration maxProcessTime, int ticksBeforeWait,
                std::optional<vespalib::CpuUsage::Category> cpu_category) = 0;

    virtual void visitThreads(ThreadVisitor&) const = 0;
};

}