Skip to content

Commit

Permalink
Provide a proper new method for RefCount. (#2570)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblandy authored Apr 1, 2022
1 parent 58f3185 commit 1e42208
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit 1e42208

Please sign in to comment.