1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use LabelledArray;
// use core::sync::atomic::Ordering;
/// A reference to an array, whose clone points to the same data.
///
/// Allows for idiomatic cloning of array references:
///
/// ```rust
/// use heaparray::naive_rc::*;
/// let array_ref = FpRcArray::new(10, |_| 0);
/// let another_ref = ArrayRef::clone(&array_ref);
///
/// assert!(array_ref.len() == another_ref.len());
/// for i in 0..another_ref.len() {
/// let r1 = &array_ref[i] as *const i32;
/// let r2 = &another_ref[i] as *const i32;
/// assert!(r1 == r2);
/// }
/// ```
/// Array with optional label struct stored next to the data that can
/// be conditionally mutated.
/*
/// Atomically modified array reference.
///
/// Guarrantees that all operations on the
/// array reference are atomic (i.e. all changes to the internal array pointer).
/// Additionally, guarrantees that all reads of the value of the internal pointer
/// are done with atomic loads.
///
/// For more details on the expected behavior of these methods, see the
/// documentation for `core::sync::atomic::AtomicPtr`.
pub trait AtomicArrayRef: Sized {
fn as_ref(&self) -> usize;
/// Returns the previous value, and also the struct you passed in if the value
/// wasn't updated
fn compare_and_swap(
&self,
current: usize,
new: Self,
order: Ordering,
) -> Result<usize, (Self, usize)>;
/// Returns the previous value, and also the struct you passed in if the value
/// wasn't updated
fn compare_exchange(
&self,
current: usize,
new: Self,
success: Ordering,
failure: Ordering,
) -> Result<usize, (Self, usize)>;
/// Swaps in the passed-in reference if the internal reference matches `current`.
/// Returns the previous value, and also the struct you passed in if the value
/// wasn't updated
fn compare_exchange_weak(
&self,
current: usize,
new: Self,
success: Ordering,
failure: Ordering,
) -> Result<usize, (Self, usize)>;
/// Swaps in the specified array reference and returns the previous value
fn swap(&self, ptr: Self, order: Ordering) -> Self;
}*/