Struct crossbeam_deque::deque::Buffer
source · struct Buffer<T> {
ptr: *mut T,
cap: usize,
}
Expand description
A buffer that holds tasks in a worker queue.
This is just a pointer to the buffer and its length - dropping an instance of this struct will not deallocate the buffer.
Fields§
§ptr: *mut T
Pointer to the allocated memory.
cap: usize
Capacity of the buffer. Always a power of two.
Implementations§
source§impl<T> Buffer<T>
impl<T> Buffer<T>
sourceunsafe fn at(&self, index: isize) -> *mut T
unsafe fn at(&self, index: isize) -> *mut T
Returns a pointer to the task at the specified index
.
sourceunsafe fn write(&self, index: isize, task: MaybeUninit<T>)
unsafe fn write(&self, index: isize, task: MaybeUninit<T>)
Writes task
into the specified index
.
This method might be concurrently called with another read
at the same index, which is
technically speaking a data race and therefore UB. We should use an atomic store here, but
that would be more expensive and difficult to implement generically for all types T
.
Hence, as a hack, we use a volatile write instead.
sourceunsafe fn read(&self, index: isize) -> MaybeUninit<T>
unsafe fn read(&self, index: isize) -> MaybeUninit<T>
Reads a task from the specified index
.
This method might be concurrently called with another write
at the same index, which is
technically speaking a data race and therefore UB. We should use an atomic load here, but
that would be more expensive and difficult to implement generically for all types T
.
Hence, as a hack, we use a volatile load instead.