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

Provide a proper new method for RefCount. #2570

Merged
merged 1 commit into from
Apr 1, 2022
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
9 changes: 7 additions & 2 deletions wgpu-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ unsafe impl Sync for RefCount {}
impl RefCount {
const MAX: usize = 1 << 24;

/// Construct a new `RefCount`, with an initial count of 1.
fn new() -> RefCount {
let bx = Box::new(AtomicUsize::new(1));
Self(unsafe { ptr::NonNull::new_unchecked(Box::into_raw(bx)) })
}

fn load(&self) -> usize {
unsafe { self.0.as_ref() }.load(Ordering::Acquire)
}
Expand Down Expand Up @@ -184,9 +190,8 @@ pub struct LifeGuard {
impl LifeGuard {
#[allow(unused_variables)]
fn new(label: &str) -> Self {
let bx = Box::new(AtomicUsize::new(1));
Self {
ref_count: ptr::NonNull::new(Box::into_raw(bx)).map(RefCount),
ref_count: Some(RefCount::new()),
submission_index: AtomicUsize::new(0),
#[cfg(debug_assertions)]
label: label.to_string(),
Expand Down