Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
heapless
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
heapless
Commits
40994962
Commit
40994962
authored
7 years ago
by
Jorge Aparicio
Browse files
Options
Downloads
Patches
Plain Diff
add contention test
parent
612bf44a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ci/script.sh
+2
-1
2 additions, 1 deletion
ci/script.sh
src/ring_buffer/mod.rs
+5
-0
5 additions, 0 deletions
src/ring_buffer/mod.rs
tests/tsan.rs
+45
-0
45 additions, 0 deletions
tests/tsan.rs
with
52 additions
and
1 deletion
ci/script.sh
+
2
−
1
View file @
40994962
...
@@ -11,8 +11,9 @@ main() {
...
@@ -11,8 +11,9 @@ main() {
cargo
test
--target
$TARGET
cargo
test
--target
$TARGET
cargo
test
--target
$TARGET
--release
cargo
test
--target
$TARGET
--release
export
TSAN_OPTIONS
=
"suppressions=
$(
pwd
)
/blacklist.txt"
export
RUSTFLAGS
=
"-Z sanitizer=thread"
export
RUSTFLAGS
=
"-Z sanitizer=thread"
export
RUST_TEST_THREADS
=
1
export
TSAN_OPTIONS
=
"suppressions=
$(
pwd
)
/blacklist.txt"
cargo
test
--test
tsan
--target
$TARGET
cargo
test
--test
tsan
--target
$TARGET
cargo
test
--test
tsan
--target
$TARGET
--release
cargo
test
--test
tsan
--target
$TARGET
--release
...
...
This diff is collapsed.
Click to expand it.
src/ring_buffer/mod.rs
+
5
−
0
View file @
40994962
...
@@ -129,6 +129,11 @@ where
...
@@ -129,6 +129,11 @@ where
}
}
}
}
/// Returns `true` if the ring buffer has a length of 0
pub
fn
is_empty
(
&
self
)
->
bool
{
self
.len
()
==
0
}
/// Iterates from the front of the queue to the back
/// Iterates from the front of the queue to the back
pub
fn
iter
(
&
self
)
->
Iter
<
T
,
A
>
{
pub
fn
iter
(
&
self
)
->
Iter
<
T
,
A
>
{
Iter
{
Iter
{
...
...
This diff is collapsed.
Click to expand it.
tests/tsan.rs
+
45
−
0
View file @
40994962
...
@@ -73,3 +73,48 @@ fn scoped() {
...
@@ -73,3 +73,48 @@ fn scoped() {
rb
.dequeue
()
.unwrap
();
rb
.dequeue
()
.unwrap
();
}
}
#[test]
fn
contention
()
{
const
N
:
usize
=
1024
;
let
mut
rb
:
RingBuffer
<
u8
,
[
u8
;
N
]
>
=
RingBuffer
::
new
();
{
let
(
mut
p
,
mut
c
)
=
rb
.split
();
Pool
::
new
(
2
)
.scoped
(
move
|
scope
|
{
scope
.execute
(
move
||
{
let
mut
sum
:
u32
=
0
;
for
i
in
0
..
N
{
let
i
=
i
as
u8
;
sum
=
sum
.wrapping_add
(
i
as
u32
);
while
let
Err
(
_
)
=
p
.enqueue
(
i
)
{}
}
println!
(
"producer: {}"
,
sum
);
});
scope
.execute
(
move
||
{
let
mut
sum
:
u32
=
0
;
for
_
in
0
..
N
{
loop
{
match
c
.dequeue
()
{
Some
(
v
)
=>
{
sum
=
sum
.wrapping_add
(
v
as
u32
);
break
;
}
_
=>
{}
}
}
}
println!
(
"consumer: {}"
,
sum
);
});
});
}
assert!
(
rb
.is_empty
());
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment