Apollo 10.0
自动驾驶开放平台
sysmo.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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#include "cyber/sysmo/sysmo.h"
18
20
21namespace apollo {
22namespace cyber {
23
25
26SysMo::SysMo() { Start(); }
27
29 auto sysmo_start = GetEnv("sysmo_start");
30 if (sysmo_start != "" && std::stoi(sysmo_start)) {
31 start_ = true;
32 sysmo_ = std::thread(&SysMo::Checker, this);
33 }
34}
35
37 if (!start_ || shut_down_.exchange(true)) {
38 return;
39 }
40
41 cv_.notify_all();
42 if (sysmo_.joinable()) {
43 sysmo_.join();
44 }
45}
46
47void SysMo::Checker() {
48 while (cyber_unlikely(!shut_down_.load())) {
50 std::unique_lock<std::mutex> lk(lk_);
51 cv_.wait_for(lk, std::chrono::milliseconds(sysmo_interval_ms_));
52 }
53}
54
55} // namespace cyber
56} // namespace apollo
#define cyber_unlikely(x)
Definition macros.h:30
std::string GetEnv(const std::string &var_name, const std::string &default_value="")
Definition environment.h:29
class register implement
Definition arena_queue.h:37