blob: 814686eb4fa01afb5f9e1bb087154388a3037f0d (
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
66
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* \class storage::framework::Thread
* \ingroup thread
*
* \brief A wrapper for a thread class.
*
* This thread class exist to hide the actual implementation of threads used,
* and to give some extra information about the threads. This is in turned used
* by monitoring, to be able to see data about the threads running. One such
* monitoring tool is the deadlock detector.
*/
#pragma once
#include "runnable.h"
#include <vespa/vespalib/stllike/string.h>
#include <condition_variable>
namespace vespalib {
class Monitor;
}
namespace storage::framework {
class Thread : public ThreadHandle {
vespalib::string _id;
public:
typedef std::unique_ptr<Thread> UP;
Thread(vespalib::stringref id) : _id(id) {}
virtual ~Thread() {}
virtual const vespalib::string& getId() const { return _id; }
/** Check whether thread have been interrupted or not. */
virtual bool interrupted() const override = 0;
/** Check whether thread have been joined or not. */
virtual bool joined() const = 0;
/**
* Call this function to set interrupt flag, such that later calls to
* interrupt returns true. If called on already interrupted thread it is a
* noop.
*/
virtual void interrupt() = 0;
/**
* Call this function to wait until thread has finished processing. If
* called after thread has already finished, it is a noop.
*/
virtual void join() = 0;
virtual void updateParameters(uint64_t waitTime,
uint64_t maxProcessTime,
int ticksBeforeWait) = 0;
/**
* Utility function to interrupt and join a thread, possibly broadcasting
* through a monitor after the signalling face.
*/
void interruptAndJoin();
void interruptAndJoin(std::condition_variable &cv);
};
}
|