Mercurial > hg > CbC > CbC_llvm
comparison clang-tools-extra/clangd/support/Shutdown.cpp @ 173:0572611fdcc8 llvm10 llvm12
reorgnization done
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 11:55:54 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
172:9fbae9c8bf63 | 173:0572611fdcc8 |
---|---|
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 "support/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() { return ShutdownRequested; } | |
35 | |
36 } // namespace clangd | |
37 } // namespace clang |