mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-30 05:50:29 +00:00
Merge pull request #283 from japaric/rm-scoped_threadpool
use std:🧵:scope instead of scoped_threadpool
This commit is contained in:
commit
1c56672469
@ -27,9 +27,6 @@ mpmc_large = []
|
|||||||
# This flag has no version guarantee, the `defmt` dependency can be updated in a patch release
|
# This flag has no version guarantee, the `defmt` dependency can be updated in a patch release
|
||||||
defmt-impl = ["defmt"]
|
defmt-impl = ["defmt"]
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "none"))'.dev-dependencies]
|
|
||||||
scoped_threadpool = "0.1.8"
|
|
||||||
|
|
||||||
[target.thumbv6m-none-eabi.dependencies]
|
[target.thumbv6m-none-eabi.dependencies]
|
||||||
atomic-polyfill = { version = "0.1.2", optional = true }
|
atomic-polyfill = { version = "0.1.2", optional = true }
|
||||||
|
|
||||||
@ -65,5 +62,8 @@ version = "0.1"
|
|||||||
version = ">=0.2.0,<0.4"
|
version = ">=0.2.0,<0.4"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
rustc_version = "0.4.0"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
|
9
build.rs
9
build.rs
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
use std::{env, error::Error};
|
use std::{env, error::Error};
|
||||||
|
|
||||||
|
use rustc_version::Channel;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let target = env::var("TARGET")?;
|
let target = env::var("TARGET")?;
|
||||||
|
|
||||||
@ -66,5 +68,12 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !matches!(
|
||||||
|
rustc_version::version_meta().unwrap().channel,
|
||||||
|
Channel::Stable | Channel::Beta
|
||||||
|
) {
|
||||||
|
println!("cargo:rustc-cfg=unstable_channel");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# false positives in thread::spawn (?)
|
race:std::panic::catch_unwind
|
||||||
race:*dealloc
|
race:std::thread::scope
|
||||||
race:*drop_slow*
|
|
||||||
race:__call_tls_dtors
|
|
||||||
|
|
||||||
# false positives in scoped_threadpool (?)
|
# std::thread::spawn false positive; seen on Ubuntu 20.04 but not on Arch Linux (2022-04-29)
|
||||||
race:*drop*
|
race:drop_in_place*JoinHandle
|
||||||
|
race:alloc::sync::Arc<*>::drop_slow
|
||||||
|
race:__call_tls_dtors
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
|
#![cfg_attr(unstable_channel, feature(scoped_threads))]
|
||||||
#![deny(rust_2018_compatibility)]
|
#![deny(rust_2018_compatibility)]
|
||||||
#![deny(rust_2018_idioms)]
|
#![deny(rust_2018_idioms)]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
use std::{sync::mpsc, thread};
|
use std::thread;
|
||||||
|
|
||||||
use heapless::{mpmc::Q64, spsc};
|
use heapless::spsc;
|
||||||
use scoped_threadpool::Pool;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn once() {
|
fn once() {
|
||||||
@ -51,6 +51,7 @@ fn twice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(unstable_channel)]
|
||||||
fn scoped() {
|
fn scoped() {
|
||||||
let mut rb: spsc::Queue<i32, 5> = spsc::Queue::new();
|
let mut rb: spsc::Queue<i32, 5> = spsc::Queue::new();
|
||||||
|
|
||||||
@ -59,12 +60,12 @@ fn scoped() {
|
|||||||
{
|
{
|
||||||
let (mut p, mut c) = rb.split();
|
let (mut p, mut c) = rb.split();
|
||||||
|
|
||||||
Pool::new(2).scoped(move |scope| {
|
thread::scope(move |scope| {
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
p.enqueue(1).unwrap();
|
p.enqueue(1).unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
c.dequeue().unwrap();
|
c.dequeue().unwrap();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -75,6 +76,7 @@ fn scoped() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore)] // too slow
|
#[cfg_attr(miri, ignore)] // too slow
|
||||||
|
#[cfg(unstable_channel)]
|
||||||
fn contention() {
|
fn contention() {
|
||||||
const N: usize = 1024;
|
const N: usize = 1024;
|
||||||
|
|
||||||
@ -83,8 +85,8 @@ fn contention() {
|
|||||||
{
|
{
|
||||||
let (mut p, mut c) = rb.split();
|
let (mut p, mut c) = rb.split();
|
||||||
|
|
||||||
Pool::new(2).scoped(move |scope| {
|
thread::scope(move |scope| {
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
let mut sum: u32 = 0;
|
let mut sum: u32 = 0;
|
||||||
|
|
||||||
for i in 0..(2 * N) {
|
for i in 0..(2 * N) {
|
||||||
@ -95,7 +97,7 @@ fn contention() {
|
|||||||
println!("producer: {}", sum);
|
println!("producer: {}", sum);
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
let mut sum: u32 = 0;
|
let mut sum: u32 = 0;
|
||||||
|
|
||||||
for _ in 0..(2 * N) {
|
for _ in 0..(2 * N) {
|
||||||
@ -120,15 +122,20 @@ fn contention() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore)] // too slow
|
#[cfg_attr(miri, ignore)] // too slow
|
||||||
|
#[cfg(unstable_channel)]
|
||||||
fn mpmc_contention() {
|
fn mpmc_contention() {
|
||||||
|
use std::sync::mpsc;
|
||||||
|
|
||||||
|
use heapless::mpmc::Q64;
|
||||||
|
|
||||||
const N: u32 = 64;
|
const N: u32 = 64;
|
||||||
|
|
||||||
static Q: Q64<u32> = Q64::new();
|
static Q: Q64<u32> = Q64::new();
|
||||||
|
|
||||||
let (s, r) = mpsc::channel();
|
let (s, r) = mpsc::channel();
|
||||||
Pool::new(2).scoped(|scope| {
|
thread::scope(|scope| {
|
||||||
let s1 = s.clone();
|
let s1 = s.clone();
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
let mut sum: u32 = 0;
|
let mut sum: u32 = 0;
|
||||||
|
|
||||||
for i in 0..(16 * N) {
|
for i in 0..(16 * N) {
|
||||||
@ -141,7 +148,7 @@ fn mpmc_contention() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let s2 = s.clone();
|
let s2 = s.clone();
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
let mut sum: u32 = 0;
|
let mut sum: u32 = 0;
|
||||||
|
|
||||||
for _ in 0..(16 * N) {
|
for _ in 0..(16 * N) {
|
||||||
@ -166,6 +173,7 @@ fn mpmc_contention() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore)] // too slow
|
#[cfg_attr(miri, ignore)] // too slow
|
||||||
|
#[cfg(unstable_channel)]
|
||||||
fn unchecked() {
|
fn unchecked() {
|
||||||
const N: usize = 1024;
|
const N: usize = 1024;
|
||||||
|
|
||||||
@ -178,14 +186,14 @@ fn unchecked() {
|
|||||||
{
|
{
|
||||||
let (mut p, mut c) = rb.split();
|
let (mut p, mut c) = rb.split();
|
||||||
|
|
||||||
Pool::new(2).scoped(move |scope| {
|
thread::scope(move |scope| {
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
for _ in 0..N / 2 - 1 {
|
for _ in 0..N / 2 - 1 {
|
||||||
p.enqueue(2).unwrap();
|
p.enqueue(2).unwrap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
let mut sum: usize = 0;
|
let mut sum: usize = 0;
|
||||||
|
|
||||||
for _ in 0..N / 2 - 1 {
|
for _ in 0..N / 2 - 1 {
|
||||||
@ -246,8 +254,8 @@ fn pool() {
|
|||||||
|
|
||||||
A::grow(unsafe { &mut M });
|
A::grow(unsafe { &mut M });
|
||||||
|
|
||||||
Pool::new(2).scoped(move |scope| {
|
thread::scope(move |scope| {
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
for _ in 0..N / 4 {
|
for _ in 0..N / 4 {
|
||||||
let a = A::alloc().unwrap();
|
let a = A::alloc().unwrap();
|
||||||
let b = A::alloc().unwrap();
|
let b = A::alloc().unwrap();
|
||||||
@ -257,7 +265,7 @@ fn pool() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.execute(move || {
|
scope.spawn(move || {
|
||||||
for _ in 0..N / 2 {
|
for _ in 0..N / 2 {
|
||||||
let a = A::alloc().unwrap();
|
let a = A::alloc().unwrap();
|
||||||
let a = a.init([2; 8]);
|
let a = a.init([2; 8]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user