Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
95caa6dc
提交
95caa6dc
authored
9月 07, 2024
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mock all methods on non-linux platforms
上级
f0f993eb
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
29 行增加
和
26 行删除
+29
-26
controller.rs
src/controller.rs
+22
-12
lib.rs
src/lib.rs
+1
-12
supervisor.rs
src/supervisor.rs
+6
-2
thread_rt.rs
src/thread_rt.rs
+0
-0
没有找到文件。
src/controller.rs
浏览文件 @
95caa6dc
...
@@ -7,16 +7,18 @@ use std::{
...
@@ -7,16 +7,18 @@ use std::{
time
::
Duration
,
time
::
Duration
,
};
};
#[cfg(target_os
=
"linux"
)]
use
crate
::
suicide
;
use
crate
::{
use
crate
::{
critical
,
critical
,
hub
::
Hub
,
hub
::
Hub
,
suicide
,
supervisor
::
Supervisor
,
supervisor
::
Supervisor
,
thread_rt
::{
Builder
,
RTParams
,
Scheduling
},
thread_rt
::{
Builder
,
RTParams
,
Scheduling
},
Error
,
Result
,
Error
,
Result
,
};
};
pub
use
roboplc_derive
::
WorkerOpts
;
pub
use
roboplc_derive
::
WorkerOpts
;
use
rtsc
::
data_policy
::
DataDeliveryPolicy
;
use
rtsc
::
data_policy
::
DataDeliveryPolicy
;
#[cfg(target_os
=
"linux"
)]
use
signal_hook
::{
use
signal_hook
::{
consts
::{
SIGINT
,
SIGTERM
},
consts
::{
SIGINT
,
SIGTERM
},
iterator
::
Signals
,
iterator
::
Signals
,
...
@@ -203,7 +205,7 @@ where
...
@@ -203,7 +205,7 @@ where
pub
fn
register_signals_with_shutdown_handler
<
H
>
(
pub
fn
register_signals_with_shutdown_handler
<
H
>
(
&
mut
self
,
&
mut
self
,
handle_fn
:
H
,
handle_fn
:
H
,
shutdown_timeout
:
Duration
,
#[allow(unused_variables)]
shutdown_timeout
:
Duration
,
)
->
Result
<
()
>
)
->
Result
<
()
>
where
where
H
:
Fn
(
&
Context
<
D
,
V
>
)
+
Send
+
Sync
+
'static
,
H
:
Fn
(
&
Context
<
D
,
V
>
)
+
Send
+
Sync
+
'static
,
...
@@ -218,22 +220,30 @@ where
...
@@ -218,22 +220,30 @@ where
builder
.park_on_errors
=
true
;
builder
.park_on_errors
=
true
;
macro_rules!
sig_handler
{
macro_rules!
sig_handler
{
(
$handler
:
expr
)
=>
{{
(
$handler
:
expr
)
=>
{{
let
context
=
self
.context
();
#[cfg(target_os
=
"linux"
)]
let
mut
signals
=
Signals
::
new
([
SIGTERM
,
SIGINT
])
?
;
{
move
||
{
let
context
=
self
.context
();
if
let
Some
(
sig
)
=
signals
.forever
()
.next
()
{
let
mut
signals
=
Signals
::
new
([
SIGTERM
,
SIGINT
])
?
;
match
sig
{
move
||
{
SIGTERM
|
SIGINT
=>
{
if
let
Some
(
sig
)
=
signals
.forever
()
.next
()
{
suicide
(
shutdown_timeout
,
true
);
match
sig
{
$handler
(
&
context
);
SIGTERM
|
SIGINT
=>
{
context
.terminate
();
suicide
(
shutdown_timeout
,
true
);
$handler
(
&
context
);
context
.terminate
();
}
_
=>
unreachable!
(),
}
}
_
=>
unreachable!
(),
}
}
}
}
}
}
#[cfg(not(target_os
=
"linux"
))]
{
move
||
{}
}
}};
}};
}
}
#[allow(unused_variables)]
let
h
=
handler
.clone
();
let
h
=
handler
.clone
();
if
let
Err
(
e
)
=
self
.supervisor
.spawn
(
builder
.clone
(),
sig_handler!
(
h
))
{
if
let
Err
(
e
)
=
self
.supervisor
.spawn
(
builder
.clone
(),
sig_handler!
(
h
))
{
if
!
matches!
(
e
,
Error
::
RTSchedSetSchduler
(
_
))
{
if
!
matches!
(
e
,
Error
::
RTSchedSetSchduler
(
_
))
{
...
...
src/lib.rs
浏览文件 @
95caa6dc
...
@@ -6,7 +6,6 @@ use std::panic::PanicInfo;
...
@@ -6,7 +6,6 @@ use std::panic::PanicInfo;
use
std
::{
env
,
sync
::
Arc
,
time
::
Duration
};
use
std
::{
env
,
sync
::
Arc
,
time
::
Duration
};
use
colored
::
Colorize
as
_
;
use
colored
::
Colorize
as
_
;
#[cfg(target_os
=
"linux"
)]
use
thread_rt
::{
RTParams
,
Scheduling
};
use
thread_rt
::{
RTParams
,
Scheduling
};
pub
use
log
::
LevelFilter
;
pub
use
log
::
LevelFilter
;
...
@@ -90,7 +89,6 @@ pub use rtsc::data_policy::{DataDeliveryPolicy, DeliveryPolicy};
...
@@ -90,7 +89,6 @@ pub use rtsc::data_policy::{DataDeliveryPolicy, DeliveryPolicy};
/// Reliable TCP/Serial communications
/// Reliable TCP/Serial communications
pub
mod
comm
;
pub
mod
comm
;
/// Controller and workers
/// Controller and workers
#[cfg(target_os
=
"linux"
)]
pub
mod
controller
;
pub
mod
controller
;
/// In-process data communication pub/sub hub, synchronous edition
/// In-process data communication pub/sub hub, synchronous edition
pub
mod
hub
;
pub
mod
hub
;
...
@@ -100,10 +98,8 @@ pub mod hub_async;
...
@@ -100,10 +98,8 @@ pub mod hub_async;
/// I/O
/// I/O
pub
mod
io
;
pub
mod
io
;
/// Task supervisor to manage real-time threads
/// Task supervisor to manage real-time threads
#[cfg(target_os
=
"linux"
)]
pub
mod
supervisor
;
pub
mod
supervisor
;
/// Real-time thread functions to work with [`supervisor::Supervisor`] and standalone
/// Real-time thread functions to work with [`supervisor::Supervisor`] and standalone, Linux only
#[cfg(target_os
=
"linux"
)]
pub
mod
thread_rt
;
pub
mod
thread_rt
;
/// The crate result type
/// The crate result type
...
@@ -245,7 +241,6 @@ impl Error {
...
@@ -245,7 +241,6 @@ impl Error {
}
}
/// Immediately kills the current process and all its subprocesses with a message to stderr
/// Immediately kills the current process and all its subprocesses with a message to stderr
#[cfg(target_os
=
"linux"
)]
pub
fn
critical
(
msg
:
&
str
)
->
!
{
pub
fn
critical
(
msg
:
&
str
)
->
!
{
eprintln!
(
"{}"
,
msg
.red
()
.bold
());
eprintln!
(
"{}"
,
msg
.red
()
.bold
());
thread_rt
::
suicide_myself
(
Duration
::
from_secs
(
0
),
false
);
thread_rt
::
suicide_myself
(
Duration
::
from_secs
(
0
),
false
);
...
@@ -257,7 +252,6 @@ pub fn critical(msg: &str) -> ! {
...
@@ -257,7 +252,6 @@ pub fn critical(msg: &str) -> ! {
/// period of time.
/// period of time.
///
///
/// Prints warnings to STDOUT if warn is true
/// Prints warnings to STDOUT if warn is true
#[cfg(target_os
=
"linux"
)]
pub
fn
suicide
(
delay
:
Duration
,
warn
:
bool
)
{
pub
fn
suicide
(
delay
:
Duration
,
warn
:
bool
)
{
let
mut
builder
=
thread_rt
::
Builder
::
new
()
.name
(
"suicide"
)
.rt_params
(
let
mut
builder
=
thread_rt
::
Builder
::
new
()
.name
(
"suicide"
)
.rt_params
(
RTParams
::
new
()
RTParams
::
new
()
...
@@ -336,14 +330,12 @@ pub fn metrics_exporter_install(
...
@@ -336,14 +330,12 @@ pub fn metrics_exporter_install(
/// Sets panic handler to immediately kill the process and its childs with SIGKILL. The process is
/// Sets panic handler to immediately kill the process and its childs with SIGKILL. The process is
/// killed when panic happens in ANY thread
/// killed when panic happens in ANY thread
#[cfg(target_os
=
"linux"
)]
pub
fn
setup_panic
()
{
pub
fn
setup_panic
()
{
std
::
panic
::
set_hook
(
Box
::
new
(
move
|
info
:
&
PanicInfo
|
{
std
::
panic
::
set_hook
(
Box
::
new
(
move
|
info
:
&
PanicInfo
|
{
panic
(
info
);
panic
(
info
);
}));
}));
}
}
#[cfg(target_os
=
"linux"
)]
fn
panic
(
info
:
&
PanicInfo
)
->
!
{
fn
panic
(
info
:
&
PanicInfo
)
->
!
{
eprintln!
(
"{}"
,
info
.to_string
()
.red
()
.bold
());
eprintln!
(
"{}"
,
info
.to_string
()
.red
()
.bold
());
thread_rt
::
suicide_myself
(
Duration
::
from_secs
(
0
),
false
);
thread_rt
::
suicide_myself
(
Duration
::
from_secs
(
0
),
false
);
...
@@ -372,13 +364,10 @@ pub fn configure_logger(filter: LevelFilter) {
...
@@ -372,13 +364,10 @@ pub fn configure_logger(filter: LevelFilter) {
/// Prelude module
/// Prelude module
pub
mod
prelude
{
pub
mod
prelude
{
#[cfg(target_os
=
"linux"
)]
pub
use
super
::
suicide
;
pub
use
super
::
suicide
;
#[cfg(target_os
=
"linux"
)]
pub
use
crate
::
controller
::
*
;
pub
use
crate
::
controller
::
*
;
pub
use
crate
::
hub
::
prelude
::
*
;
pub
use
crate
::
hub
::
prelude
::
*
;
pub
use
crate
::
io
::
prelude
::
*
;
pub
use
crate
::
io
::
prelude
::
*
;
#[cfg(target_os
=
"linux"
)]
pub
use
crate
::
supervisor
::
prelude
::
*
;
pub
use
crate
::
supervisor
::
prelude
::
*
;
pub
use
crate
::
time
::
DurationRT
;
pub
use
crate
::
time
::
DurationRT
;
pub
use
bma_ts
::{
Monotonic
,
Timestamp
};
pub
use
bma_ts
::{
Monotonic
,
Timestamp
};
...
...
src/supervisor.rs
浏览文件 @
95caa6dc
...
@@ -29,8 +29,12 @@ impl<T> Default for Supervisor<T> {
...
@@ -29,8 +29,12 @@ impl<T> Default for Supervisor<T> {
macro_rules!
vacant_entry
{
macro_rules!
vacant_entry
{
(
$self:ident
,
$builder:ident
)
=>
{{
(
$self:ident
,
$builder:ident
)
=>
{{
let
Some
(
name
)
=
$builder
.name
.clone
()
else
{
return
Err
(
Error
::
SupervisorNameNotSpecified
);
};
let
Some
(
name
)
=
$builder
.name
.clone
()
else
{
let
btree_map
::
Entry
::
Vacant
(
entry
)
=
$self
.tasks
.entry
(
name
.clone
())
else
{
return
Err
(
Error
::
SupervisorDuplicateTask
(
name
));
};
return
Err
(
Error
::
SupervisorNameNotSpecified
);
};
let
btree_map
::
Entry
::
Vacant
(
entry
)
=
$self
.tasks
.entry
(
name
.clone
())
else
{
return
Err
(
Error
::
SupervisorDuplicateTask
(
name
));
};
entry
entry
}};
}};
}
}
...
...
src/thread_rt.rs
浏览文件 @
95caa6dc
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论