Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
fb9453f1
提交
fb9453f1
authored
4月 15, 2024
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
prealloc_heap
上级
7d4593e2
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
43 行增加
和
1 行删除
+43
-1
lib.rs
src/lib.rs
+7
-1
thread_rt.rs
src/thread_rt.rs
+36
-0
没有找到文件。
src/lib.rs
浏览文件 @
fb9453f1
...
@@ -66,7 +66,7 @@ pub enum Error {
...
@@ -66,7 +66,7 @@ pub enum Error {
#[error(
"timed out"
)]
#[error(
"timed out"
)]
Timeout
,
Timeout
,
/// I/O and threading errors
/// I/O and threading errors
#[error(
"I/O error {0}"
)]
#[error(
"I/O error
:
{0}"
)]
IO
(
String
),
IO
(
String
),
/// 3rd party API errors
/// 3rd party API errors
#[error(
"API error {0}: {1}"
)]
#[error(
"API error {0}: {1}"
)]
...
@@ -101,6 +101,9 @@ pub enum Error {
...
@@ -101,6 +101,9 @@ pub enum Error {
/// This error never happens and is used as a compiler hint only
/// This error never happens and is used as a compiler hint only
#[error(
"never happens"
)]
#[error(
"never happens"
)]
Infallible
(
#
[
from
]
std
::
convert
::
Infallible
),
Infallible
(
#
[
from
]
std
::
convert
::
Infallible
),
/// All other errors
#[error(
"operation failed: {0}"
)]
Failed
(
String
),
}
}
macro_rules!
impl_error
{
macro_rules!
impl_error
{
...
@@ -131,6 +134,9 @@ impl Error {
...
@@ -131,6 +134,9 @@ impl Error {
pub
fn
io
<
S
:
fmt
::
Display
>
(
msg
:
S
)
->
Self
{
pub
fn
io
<
S
:
fmt
::
Display
>
(
msg
:
S
)
->
Self
{
Error
::
IO
(
msg
.to_string
())
Error
::
IO
(
msg
.to_string
())
}
}
pub
fn
failed
<
S
:
fmt
::
Display
>
(
msg
:
S
)
->
Self
{
Error
::
Failed
(
msg
.to_string
())
}
}
}
/// Data delivery policies, used by [`hub::Hub`], [`pchannel::Receiver`] and [`pdeque::Deque`]
/// Data delivery policies, used by [`hub::Hub`], [`pchannel::Receiver`] and [`pdeque::Deque`]
...
...
src/thread_rt.rs
浏览文件 @
fb9453f1
...
@@ -27,6 +27,42 @@ fn is_realtime() -> bool {
...
@@ -27,6 +27,42 @@ fn is_realtime() -> bool {
REALTIME_MODE
.load
(
Ordering
::
Relaxed
)
REALTIME_MODE
.load
(
Ordering
::
Relaxed
)
}
}
/// The method preallocates a heap memory region with the given size. The method is useful to
/// prevent memory fragmentation and speed up memory allocation. It is highly recommended to call
/// the method at the beginning of the program.
///
/// Does nothing in simulated mode.
///
/// # Panics
///
/// Will panic if the page size is too large (more than usize)
pub
fn
prealloc_heap
(
size
:
usize
)
->
Result
<
()
>
{
if
!
is_realtime
()
{
return
Ok
(());
}
let
page_size
=
unsafe
{
if
libc
::
mallopt
(
libc
::
M_MMAP_MAX
,
0
)
!=
1
{
return
Err
(
Error
::
failed
(
"unable to disable mmap for allocation of large mem regions"
,
));
}
if
libc
::
mallopt
(
libc
::
M_TRIM_THRESHOLD
,
-
1
)
!=
1
{
return
Err
(
Error
::
failed
(
"unable to disable trimming"
));
}
if
libc
::
mlockall
(
libc
::
MCL_FUTURE
)
==
-
1
{
return
Err
(
Error
::
failed
(
"unable to lock memory pages"
));
};
usize
::
try_from
(
libc
::
sysconf
(
libc
::
_SC_PAGESIZE
))
.expect
(
"Page size too large"
)
};
let
mut
heap_mem
=
vec!
[
0
_u8
;
size
];
std
::
hint
::
black_box
(
move
||
{
for
i
in
(
0
..
size
)
.step_by
(
page_size
)
{
heap_mem
[
i
]
=
0xff
;
}
})();
Ok
(())
}
/// A thread builder object, similar to [`thread::Builder`] but with real-time capabilities
/// A thread builder object, similar to [`thread::Builder`] but with real-time capabilities
///
///
/// Warning: works on Linux systems only
/// Warning: works on Linux systems only
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论