Skip to content

Instantly share code, notes, and snippets.

@Visic
Visic / rwlock.rs
Created November 14, 2019 17:11
Example implementation of a greedy read lock
use core::cell::UnsafeCell;
use core::marker::PhantomData;
use core::ops::{Deref, DerefMut};
use core::ptr::NonNull;
use core::sync::atomic::{spin_loop_hint as cpu_relax, AtomicUsize, Ordering};
pub struct RwLock<T: ?Sized> {
lock: AtomicUsize,
data: UnsafeCell<T>,
}