Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LARN
X-Lap
Commits
e58df2b8
Commit
e58df2b8
authored
Feb 08, 2021
by
Sven Liefgen
Browse files
Add 'Placeholder', i.e. make it possible to save timestamps to a
variable
parent
f8cd9601
Changes
2
Hide whitespace changes
Inline
Side-by-side
build.rs
View file @
e58df2b8
...
...
@@ -19,7 +19,10 @@ fn main() {
// Create XLAP array containing a table for each kind
let
packet_types
=
&
yaml
[
"packet_types"
];
let
packet_types_count
=
packet_types
.as_hash
()
.expect
(
"Expected `packet_types to be a `Hash`"
)
.len
();
let
packet_types_count
=
packet_types
.as_hash
()
.expect
(
"Expected `packet_types to be a `Hash`"
)
.len
();
let
mut
static_xlap
=
format!
(
"static XLAP: [AtomicPtr<TimestampTable>; {}] = [
\n
"
,
...
...
@@ -46,9 +49,14 @@ fn main() {
let
timestamps
=
&
yaml
[
"stamps"
];
let
mut
timestamp_id_enum
=
String
::
from
(
"#[derive(EnumCount, EnumIter, AsRefStr)]
\n
"
);
let
mut
timestamp_id_enum
=
String
::
from
(
"#[derive(EnumCount, EnumIter, AsRefStr, Copy, Clone)]
\n
"
);
timestamp_id_enum
.push_str
(
"pub enum TimestampId {
\n
"
);
for
timestamp_id
in
timestamps
.as_hash
()
.expect
(
"Expected `stamps` to be a `Hash`"
)
.keys
()
{
for
timestamp_id
in
timestamps
.as_hash
()
.expect
(
"Expected `stamps` to be a `Hash`"
)
.keys
()
{
timestamp_id_enum
.push_str
(
" "
);
timestamp_id_enum
.push_str
(
timestamp_id
.as_str
()
.unwrap
());
timestamp_id_enum
.push_str
(
",
\n
"
);
...
...
src/lib.rs
View file @
e58df2b8
...
...
@@ -57,16 +57,25 @@ pub struct TimestampTable {
static
mut
ZERO
:
Option
<
Instant
>
=
None
;
/// Update the clock and cycle value of a timestamp by setting them to en explicit value
#[inline(always)]
pub
unsafe
fn
set_timestamp
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
,
(
t
,
c
):
(
Instant
,
u64
))
{
set_timestamp_clock
(
kind
,
row
,
id
,
t
);
set_timestamp_cycle
(
kind
,
row
,
id
,
c
);
}
/// Update the clock value of a timestamp by setting it to an explicit value
#[inline(always)]
pub
unsafe
fn
timestamp_value
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
,
value
:
Instant
)
{
(
*
XLAP
[
kind
as
usize
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.t
=
value
;
pub
unsafe
fn
set_timestamp_clock
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
,
value
:
Instant
)
{
(
*
XLAP
[
kind
as
usize
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.t
=
value
;
}
/// Update the clock value of a cyclestamp by setting it to an explicit value
#[inline(always)]
pub
unsafe
fn
cyclestamp_value
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
,
value
:
u64
)
{
(
*
XLAP
[
kind
as
usize
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.c
=
value
;
pub
unsafe
fn
set_timestamp_cycle
(
kind
:
Kind
,
row
:
usize
,
id
:
TimestampId
,
value
:
u64
)
{
(
*
XLAP
[
kind
as
usize
]
.load
(
Ordering
::
Acquire
))
.rows
[
row
%
TS_ROWS
]
.timestamp
[
id
as
usize
]
.c
=
value
;
}
/// Update the clock value of a timestamp
...
...
@@ -83,6 +92,18 @@ pub unsafe fn timestamp_cycle(kind: Kind, row: usize, id: TimestampId) {
current_cycle
();
}
/// Create a clock value without saving it to a table
#[inline(always)]
pub
unsafe
fn
get_timestamp_clock
()
->
Instant
{
Instant
::
now
()
}
/// Create a cycle value without saving it to a table
#[inline(always)]
pub
unsafe
fn
get_timestamp_cycle
()
->
u64
{
current_cycle
()
}
impl
TimestampTable
{
/// Install a timestamp table
///
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment