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
19
#include "
cyber/common/environment.h
"
20
21
namespace
apollo
{
22
namespace
cyber {
23
24
using
apollo::cyber::common::GetEnv
;
25
26
SysMo::SysMo() {
Start
(); }
27
28
void
SysMo::Start
() {
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
36
void
SysMo::Shutdown
() {
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
47
void
SysMo::Checker() {
48
while
(
cyber_unlikely
(!shut_down_.load())) {
49
scheduler::Instance
()->
CheckSchedStatus
();
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
apollo::cyber::SysMo::Shutdown
void Shutdown()
Definition
sysmo.cc:36
apollo::cyber::SysMo::Start
void Start()
Definition
sysmo.cc:28
apollo::cyber::scheduler::Scheduler::CheckSchedStatus
void CheckSchedStatus()
Definition
scheduler.cc:102
cyber_unlikely
#define cyber_unlikely(x)
Definition
macros.h:30
environment.h
apollo::cyber::common::GetEnv
std::string GetEnv(const std::string &var_name, const std::string &default_value="")
Definition
environment.h:29
apollo::cyber::scheduler::Instance
Scheduler * Instance()
Definition
scheduler_factory.cc:49
apollo
class register implement
Definition
arena_queue.h:37
sysmo.h
cyber
sysmo
sysmo.cc