Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ergonomics of platform_support's Instant #17577

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/bevy_platform_support/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod fallback {
time::Duration,
};

static ELAPSED_GETTER: AtomicPtr<fn() -> Duration> = AtomicPtr::new(unset_getter as *mut _);
static ELAPSED_GETTER: AtomicPtr<()> = AtomicPtr::new(unset_getter as *mut _);

/// Fallback implementation of `Instant` suitable for a `no_std` environment.
///
Expand All @@ -53,7 +53,7 @@ mod fallback {
let getter = ELAPSED_GETTER.load(Ordering::Acquire);

// SAFETY: Function pointer is always valid
let getter = unsafe { *getter };
let getter = unsafe { core::mem::transmute::<_, fn() -> Duration>(getter) };

Self((getter)())
}
Expand All @@ -66,8 +66,8 @@ mod fallback {
/// - The function provided must accurately represent the elapsed time.
/// - The function must preserve all invariants of the [`Instant`] type.
/// - The pointer to the function must be valid whenever [`Instant::now`] is called.
pub unsafe fn set_elapsed(getter: *mut fn() -> Duration) {
ELAPSED_GETTER.store(getter, Ordering::Release);
pub unsafe fn set_elapsed(getter: fn() -> Duration) {
ELAPSED_GETTER.store(getter as *mut _, Ordering::Release);
}

/// Returns the amount of time elapsed from another instant to this one,
Expand Down