Skip to content

Commit

Permalink
Change tracking value type,from u32 to u64. (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
80ROkWOC4j authored Jan 22, 2025
1 parent d37f8f9 commit c978548
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/all_storages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use alloc::sync::Arc;
use core::any::type_name;
use core::hash::BuildHasherDefault;
use core::marker::PhantomData;
use core::sync::atomic::AtomicU32;
use core::sync::atomic::AtomicU64;
use hashbrown::hash_map::Entry;

#[allow(missing_docs)]
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<Lock, ThreadId> AllStoragesBuilder<Lock, ThreadId> {
}

impl AllStoragesBuilder<LockPresent, ThreadIdPresent> {
pub(crate) fn build(self, counter: Arc<AtomicU32>) -> AtomicRefCell<AllStorages> {
pub(crate) fn build(self, counter: Arc<AtomicU64>) -> AtomicRefCell<AllStorages> {
let mut storages = ShipHashMap::with_hasher(BuildHasherDefault::default());

storages.insert(StorageId::of::<Entities>(), SBox::new(Entities::new()));
Expand Down Expand Up @@ -159,7 +159,7 @@ pub struct AllStorages {
main_thread_id: u64,
#[cfg(feature = "thread_local")]
thread_id_generator: Arc<dyn Fn() -> u64 + Send + Sync>,
counter: Arc<AtomicU32>,
counter: Arc<AtomicU64>,
}

#[cfg(not(feature = "thread_local"))]
Expand All @@ -169,7 +169,7 @@ unsafe impl Sync for AllStorages {}

impl AllStorages {
#[cfg(feature = "std")]
pub(crate) fn new(counter: Arc<AtomicU32>) -> Self {
pub(crate) fn new(counter: Arc<AtomicU64>) -> Self {
let mut storages = ShipHashMap::with_hasher(BuildHasherDefault::default());

storages.insert(StorageId::of::<Entities>(), SBox::new(Entities::new()));
Expand Down
6 changes: 3 additions & 3 deletions src/scheduler/into_workload_run_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::World;
use alloc::boxed::Box;
use alloc::sync::Arc;
use alloc::vec::Vec;
use core::sync::atomic::{AtomicU32, Ordering};
use core::sync::atomic::{AtomicU64, Ordering};

pub trait IntoRunIf<B> {
fn into_workload_run_if(self) -> Result<RunIf, error::InvalidSystem>;
Expand Down Expand Up @@ -80,7 +80,7 @@ macro_rules! impl_into_workload_run_if {
}
}

let last_run = AtomicU32::new(0);
let last_run = AtomicU64::new(0);
Ok(RunIf {
system_fn: Box::new(move |world: &World| {
let current = world.get_current();
Expand Down Expand Up @@ -165,7 +165,7 @@ macro_rules! impl_into_workload_run_if {
}
}

let last_run = Arc::new(AtomicU32::new(0));
let last_run = Arc::new(AtomicU64::new(0));
Ok(Box::new(move |world: &World| {
let current = world.get_current();
let last_run = TrackingTimestamp::new(last_run.swap(current.get(), Ordering::Acquire));
Expand Down
4 changes: 2 additions & 2 deletions src/scheduler/into_workload_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use alloc::boxed::Box;
use alloc::vec;
use alloc::vec::Vec;
use core::any::type_name;
use core::sync::atomic::{AtomicU32, Ordering};
use core::sync::atomic::{AtomicU64, Ordering};

/// Trait used to add systems to a workload.
///
Expand Down Expand Up @@ -145,7 +145,7 @@ macro_rules! impl_into_workload_system {
$type::enable_tracking(&mut tracking_to_enable);
)+

let last_run = AtomicU32::new(0);
let last_run = AtomicU64::new(0);
Ok(WorkloadSystem {
borrow_constraints: borrows,
tracking_to_enable,
Expand Down
6 changes: 3 additions & 3 deletions src/scheduler/into_workload_try_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use alloc::vec::Vec;
use core::any::type_name;
#[cfg(not(feature = "std"))]
use core::any::Any;
use core::sync::atomic::{AtomicU32, Ordering};
use core::sync::atomic::{AtomicU64, Ordering};
#[cfg(feature = "std")]
use std::error::Error;

Expand Down Expand Up @@ -179,7 +179,7 @@ macro_rules! impl_into_workload_try_system {
$type::enable_tracking(&mut tracking_to_enable);
)+

let last_run = AtomicU32::new(0);
let last_run = AtomicU64::new(0);
Ok(WorkloadSystem {
borrow_constraints: borrows,
tracking_to_enable,
Expand Down Expand Up @@ -250,7 +250,7 @@ macro_rules! impl_into_workload_try_system {
$type::enable_tracking(&mut tracking_to_enable);
)+

let last_run = AtomicU32::new(0);
let last_run = AtomicU64::new(0);
Ok(WorkloadSystem {
borrow_constraints: borrows,
tracking_to_enable,
Expand Down
22 changes: 11 additions & 11 deletions src/tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,17 @@ pub(crate) fn map_deletion_data<T>(

/// Timestamp used to clear tracking information.
#[derive(Clone, Copy, Debug)]
pub struct TrackingTimestamp(u32);
pub struct TrackingTimestamp(u64);

impl TrackingTimestamp {
/// Returns a new [`TrackingTimestamp`] at the given tracking cycle.
#[inline]
pub fn new(now: u32) -> TrackingTimestamp {
pub fn new(now: u64) -> TrackingTimestamp {
TrackingTimestamp(now)
}

#[inline]
pub(crate) fn get(self) -> u32 {
pub(crate) fn get(self) -> u64 {
self.0
}

Expand All @@ -212,13 +212,13 @@ impl TrackingTimestamp {
/// This method should only be necessary for custom storages that want to implement tracking.
#[inline]
pub fn is_older_than(self, other: TrackingTimestamp) -> bool {
other.0.wrapping_sub(1).wrapping_sub(self.0) < u32::MAX / 2
other.0.wrapping_sub(1).wrapping_sub(self.0) < u64::MAX / 2
}

/// Returns the timesptamp the furthest from the given one.
#[inline]
pub fn furthest_from(self) -> TrackingTimestamp {
TrackingTimestamp(self.0.wrapping_add(u32::MAX / 2))
TrackingTimestamp(self.0.wrapping_add(u64::MAX / 2))
}
}

Expand All @@ -233,9 +233,9 @@ mod tests {
(5, 0, 10, true),
(11, 0, 10, false),
// check wrapping true
(u32::MAX, u32::MAX - 1, 0, true),
(u64::MAX, u64::MAX - 1, 0, true),
// check wrapping false
(u32::MAX - 1, u32::MAX, 0, false),
(u64::MAX - 1, u64::MAX, 0, false),
(1, 2, 0, false),
// timestamp is equal to last
(1, 1, 0, false),
Expand All @@ -262,13 +262,13 @@ mod tests {
(5, 10, true),
(11, 10, false),
// check wrapping true
(u32::MAX, 0, true),
(u64::MAX, 0, true),
// check wrapping false
(0, u32::MAX, false),
(0, u64::MAX, false),
// barely within limit
(0, u32::MAX / 2, true),
(0, u64::MAX / 2, true),
// barely outside limit
(0, u32::MAX / 2 + 1, false),
(0, u64::MAX / 2 + 1, false),
// timestamp is equal to other
(1, 1, false),
];
Expand Down
6 changes: 3 additions & 3 deletions src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ use crate::views::EntitiesViewMut;
use alloc::boxed::Box;
use alloc::format;
use alloc::sync::Arc;
use core::sync::atomic::AtomicU32;
use core::sync::atomic::AtomicU64;

/// `World` contains all data this library will manipulate.
pub struct World {
pub(crate) all_storages: AtomicRefCell<AllStorages>,
pub(crate) scheduler: AtomicRefCell<Scheduler>,
counter: Arc<AtomicU32>,
counter: Arc<AtomicU64>,
#[cfg(feature = "parallel")]
thread_pool: Option<rayon::ThreadPool>,
}
Expand All @@ -42,7 +42,7 @@ pub struct World {
impl Default for World {
/// Creates an empty `World`.
fn default() -> Self {
let counter = Arc::new(AtomicU32::new(1));
let counter = Arc::new(AtomicU64::new(1));
World {
#[cfg(not(feature = "thread_local"))]
all_storages: AtomicRefCell::new(AllStorages::new(counter.clone())),
Expand Down
4 changes: 2 additions & 2 deletions src/world/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::atomic_refcell::AtomicRefCell;
use crate::public_transport::ShipyardRwLock;
use crate::world::World;
use alloc::sync::Arc;
use core::sync::atomic::AtomicU32;
use core::sync::atomic::AtomicU64;

/// Builder for [`World`] when one wants custom lock, custom thread pool
/// or custom thread id provider function.
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<Lock, ThreadId> WorldBuilder<Lock, ThreadId> {
impl WorldBuilder<LockPresent, ThreadIdPresent> {
/// Creates a new [`World`] based on the [`WorldBuilder`] config.
pub fn build(self) -> World {
let counter = Arc::new(AtomicU32::new(1));
let counter = Arc::new(AtomicU64::new(1));

let all_storages = self.all_storages_builder.build(counter.clone());

Expand Down

0 comments on commit c978548

Please sign in to comment.