Apollo 10.0
自动驾驶开放平台
state.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#ifndef CYBER_STATE_H_
18#define CYBER_STATE_H_
19
20#include <sys/types.h>
21#include <unistd.h>
22
23#include <cerrno>
24#include <csignal>
25#include <cstdint>
26#include <cstring>
27#include <thread>
28
29#include "cyber/common/log.h"
30
31namespace apollo {
32namespace cyber {
33
40
42void SetState(const State& state);
43
44inline bool OK() { return GetState() == STATE_INITIALIZED; }
45
46inline bool IsShutdown() {
48}
49
50inline void WaitForShutdown() {
51 while (!IsShutdown()) {
52 std::this_thread::sleep_for(std::chrono::milliseconds(200));
53 }
54}
55
56inline void AsyncShutdown() {
57 pid_t pid = getpid();
58 if (kill(pid, SIGINT) != 0) {
59 AERROR << strerror(errno);
60 }
61}
62
63} // namespace cyber
64} // namespace apollo
65
66#endif // CYBER_STATE_H_
#define AERROR
Definition log.h:44
bool IsShutdown()
Definition state.h:46
void SetState(const State &state)
Definition state.cc:30
void WaitForShutdown()
Definition state.h:50
@ STATE_INITIALIZED
Definition state.h:36
@ STATE_SHUTDOWN
Definition state.h:38
@ STATE_SHUTTING_DOWN
Definition state.h:37
@ STATE_UNINITIALIZED
Definition state.h:35
bool OK()
Definition state.h:44
State GetState()
Definition state.cc:28
void AsyncShutdown()
Definition state.h:56
class register implement
Definition arena_queue.h:37