blob: 245522a74211b66b4e645211108b0d8d9b992023 (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* \class storage::framework::Runnable
* \ingroup thread
*
* \brief Minimal API for something that can be run.
*
* Minimum API to implement to be able to be run by a thread.
*/
#pragma once
#include <vespa/storageframework/generic/clock/time.h>
namespace storage::framework {
/**
* A cycle type can be given when registering ticks. This is useful for
* monitoring, to see the difference between cycles that is just waiting and
* cycles that are processing. If this information is known, the monitoring
* tools can see that the longest process cycle have been 5 ms, even though
* the thread is waiting for 1000 ms when it is idle.
*/
enum CycleType { UNKNOWN_CYCLE, WAIT_CYCLE, PROCESS_CYCLE };
const char* getCycleTypeName(CycleType);
struct ThreadHandle {
virtual ~ThreadHandle() {}
/** Check whether thread have been interrupted or not. */
virtual bool interrupted() const = 0;
/**
* Register a tick. Useful such that a deadlock detector can detect that
* threads are actually doing something. If cycle types are specified,
* deadlock detector can specifically know what thread has been doing and
* used appropriate max limit. On unknown cycles, less information is
* available, and deadlock detector will use sum of wait and process time.
*
* The cycle type specified is for the cycle that just passed.
*
* @param currentTime Callers can set current time such that backend does
* not need to calculate clock. (Too avoid additional
* clock fetches if client already knows current time)
*/
virtual void registerTick(CycleType = UNKNOWN_CYCLE,
MilliSecTime currentTime = MilliSecTime(0)) = 0;
virtual uint64_t getWaitTime() const = 0;
virtual uint64_t getMaxProcessTime() const = 0;
/**
* The number of ticks done before wait is called when no more work is
* reported.
*/
virtual int getTicksBeforeWait() const = 0;
};
struct Runnable {
virtual ~Runnable() {}
virtual void run(ThreadHandle&) = 0;
};
} // storage::framework
|