aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/doom.h
blob: cbac7e2cfbd969a5b7fc4fd496587f1479f7b63b (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "clock.h"

namespace vespalib {

class Doom {
public:
    Doom(const Clock &clock, steady_time doom)
        : Doom(clock, doom, doom, false)
    {}
    Doom(const Clock &clock, steady_time softDoom,
         steady_time hardDoom, bool explicitSoftDoom);

    bool soft_doom() const { return (_clock.getTimeNS() > _softDoom); }
    bool hard_doom() const { return (_clock.getTimeNS() > _hardDoom); }
    duration soft_left() const { return _softDoom - _clock.getTimeNS(); }
    duration hard_left() const { return _hardDoom - _clock.getTimeNS(); }
    bool isExplicitSoftDoom() const { return _isExplicitSoftDoom; }
private:
    const Clock   &_clock;
    steady_time    _softDoom;
    steady_time    _hardDoom;
    bool           _isExplicitSoftDoom;
};

}