aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storageframework/generic/thread/thread_properties.h
blob: 7d9f38ae519c7971953044ff6ee32f936fea83c2 (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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/vespalib/util/time.h>

namespace storage::framework {

/**
 * Each thread may have different properties, as to how long they wait between
 * ticks and how long they're supposed to use processing between ticks. To be
 * able to specify this per thread, a set of properties can be set by each
 * thread.
 */
class ThreadProperties {
private:
    /**
     * Time this thread should maximum use to process before a tick is
     * registered. (Including wait time if wait time is not set)
     */
    vespalib::duration _maxProcessTime;
    /**
     * Time this thread will wait in a non-interrupted wait cycle.
     * Used in cases where a wait cycle is registered. As long as no other
     * time consuming stuff is done in a wait cycle, you can just use the
     * wait time here. The deadlock detector should add a configurable
     * global time period before flagging deadlock anyways.
     */
    vespalib::duration _waitTime;
    /**
     * Number of ticks to be done before a wait.
     */
    uint32_t _ticksBeforeWait;

public:
    ThreadProperties(vespalib::duration waitTime,
                     vespalib::duration maxProcessTime,
                     int ticksBeforeWait);

    [[nodiscard]] vespalib::duration getMaxProcessTime() const { return _maxProcessTime; }
    [[nodiscard]] vespalib::duration getWaitTime() const { return _waitTime; }
    [[nodiscard]] int getTicksBeforeWait() const { return _ticksBeforeWait; }

    [[nodiscard]] vespalib::duration getMaxCycleTime() const {
        return std::max(_maxProcessTime, _waitTime);
    }
};

}