clang-tools 10.0.0

Shutdown.cpp
Go to the documentation of this file.
1 //===--- Shutdown.cpp - Unclean exit scenarios ----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "Shutdown.h"
10
11 #include <atomic>
12 #include <cstdlib>
13 #include <thread>
14
15 namespace clang {
16 namespace clangd {
17
18 void abortAfterTimeout(std::chrono::seconds Timeout) {
19 // This is more portable than sys::WatchDog, and yields a stack trace.
20 std::thread([Timeout] {
21 std::this_thread::sleep_for(Timeout);
22 std::abort();
23 }).detach();
24 }
25
26 static std::atomic<bool> ShutdownRequested = {false};
27
28 void requestShutdown() {
29 if (ShutdownRequested.exchange(true))
30 // This is the second shutdown request. Exit hard.
31 std::abort();
32 }
33
34 bool shutdownRequested() {
35 return ShutdownRequested;
36 }
37
38 } // namespace clangd
39 } // namespace clang
40
clang::clangd::requestShutdown
void requestShutdown()
Sets a flag to indicate that clangd was sent a shutdown signal, and the transport loop should exit at...
Definition: Shutdown.cpp:28
clang::clangd::abortAfterTimeout
void abortAfterTimeout(std::chrono::seconds Timeout)
Causes this process to crash if still running after Timeout.
Definition: Shutdown.cpp:18
Shutdown.h
clang::clangd::ShutdownRequested
static std::atomic< bool > ShutdownRequested
Definition: Shutdown.cpp:26
clang::clangd::shutdownRequested
bool shutdownRequested()
Checks whether requestShutdown() was called.
Definition: Shutdown.cpp:34
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27