The goal of this PR is to add atomic Link types for every data structure that can be shared between threads.
Every link type implements acquire_link and release_link using atomic operations. The rest of the operations on the links are implemented using non-atomic operations, assuming that acquire_link has already been called.
All the AtomicLink types are Send and Sync.
The atomic link types all have the same size as their non-atomic counterpart. This relies on these assumptions:
AtomicUsize and Cell<usize> have the same representation and interior mutability. So &AtomicUsize can be transmuted to &Cell<usize>.
AtomicPtr<AtomicLink> and Cell<Option<NonNull<AtomicLink>>> have the same representation and interior mutability. So &AtomicPtr<AtomicLink> can be transmuted to &Cell<Option<NonNull<AtomicLink>>>.
The goal of this PR is to add atomic Link types for every data structure that can be shared between threads.
Every link type implements
acquire_link
andrelease_link
using atomic operations. The rest of the operations on the links are implemented using non-atomic operations, assuming thatacquire_link
has already been called.All the
AtomicLink
types areSend
andSync
.The atomic link types all have the same size as their non-atomic counterpart. This relies on these assumptions:
AtomicUsize
andCell<usize>
have the same representation and interior mutability. So&AtomicUsize
can be transmuted to&Cell<usize>
.AtomicPtr<AtomicLink>
andCell<Option<NonNull<AtomicLink>>>
have the same representation and interior mutability. So&AtomicPtr<AtomicLink>
can be transmuted to&Cell<Option<NonNull<AtomicLink>>>
.