threadlocal count for join/heatbeat
This commit is contained in:
parent
9b0cc41834
commit
940c681222
|
@ -1013,7 +1013,7 @@ mod job {
|
|||
|
||||
use std::{
|
||||
any::Any,
|
||||
cell::UnsafeCell,
|
||||
cell::{Cell, UnsafeCell},
|
||||
collections::BTreeMap,
|
||||
future::Future,
|
||||
hint::cold_path,
|
||||
|
@ -1084,8 +1084,6 @@ struct WorkerThread {
|
|||
}
|
||||
|
||||
pub struct Scope<'scope> {
|
||||
// counter for join_every_* function
|
||||
join_count: AtomicUsize,
|
||||
// latch to wait on before the scope finishes
|
||||
job_counter: JobCounter,
|
||||
// local threadpool
|
||||
|
@ -1572,9 +1570,20 @@ impl<'scope> Scope<'scope> {
|
|||
A: FnOnce(&Self) -> RA + Send,
|
||||
B: FnOnce(&Self) -> RB + Send,
|
||||
{
|
||||
let count = self.join_count.load(Ordering::Relaxed);
|
||||
self.join_count
|
||||
.store(count.wrapping_add(1) % TIMES, Ordering::Relaxed);
|
||||
thread_local! {
|
||||
static JOIN_COUNT: Cell<usize> = Cell::new(0);
|
||||
}
|
||||
|
||||
// a threadlocal counter is much faster than a sync atomic counter
|
||||
let count = JOIN_COUNT.with(|count| {
|
||||
count.set(count.get().wrapping_add(1) % TIMES);
|
||||
count.get()
|
||||
});
|
||||
|
||||
// let count = self.join_count.load(Ordering::Relaxed);
|
||||
// self.join_count
|
||||
// .store(count.wrapping_add(1) % TIMES, Ordering::Relaxed);
|
||||
|
||||
// let count = self
|
||||
// .join_count
|
||||
// .update(Ordering::Relaxed, Ordering::Relaxed, |n| {
|
||||
|
@ -1645,7 +1654,6 @@ impl<'scope> Scope<'scope> {
|
|||
fn from_context(ctx: Arc<Context>) -> Self {
|
||||
Self {
|
||||
context: ctx,
|
||||
join_count: AtomicUsize::new(0),
|
||||
job_counter: JobCounter::default(),
|
||||
panic: AtomicPtr::new(ptr::null_mut()),
|
||||
_pd: PhantomData,
|
||||
|
|
Loading…
Reference in a new issue