aboutsummaryrefslogtreecommitdiffstats
path: root/staging_vespalib/src/vespa/vespalib/util/shutdownguard.cpp
blob: da608447d35d092b63dec78e527bff2f3e53ceef (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "shutdownguard.h"

#include <vespa/log/log.h>
LOG_SETUP(".vespalib.shutdownguard");

namespace vespalib {

void ShutdownGuard::Run(FastOS_ThreadInterface *, void *)
{
    while (_dieAtTime > getTimeInMillis()) {
        FastOS_Thread::Sleep(5);
    }
    if (_dieAtTime != 0) {
        LOG(warning, "ShutdownGuard is now forcing an exit of the process.");
        _exit(EXIT_FAILURE);
    }
}

ShutdownGuard::ShutdownGuard(uint64_t millis) :
    FastOS_Runnable(),
    _pool(STACK_SIZE, 1),
    _dieAtTime(getTimeInMillis() + millis)
{
    _pool.NewThread(this);
}

ShutdownGuard::~ShutdownGuard()
{
    _dieAtTime = 0;
    _pool.Close();
}


}