kcas/err.rs
1use crate::types::{Stage, ThreadId, WordNum};
2use displaydoc::Display;
3
4/// Any error which can occur during a k-CAS operation.
5#[derive(Debug, Display, Eq, PartialEq)]
6pub enum Error {
7 /// An unrecoverable error occurred and in-flight changes may not have been cleaned up: {0}
8 Fatal(FatalError),
9 /// The value at one of the target addresses was not equal to the expected value.
10 ValueWasNotExpectedValue,
11}
12
13impl From<FatalError> for Error {
14 fn from(fatal_error: FatalError) -> Self {
15 Error::Fatal(fatal_error)
16 }
17}
18
19/// An unrecoverable error.
20#[derive(Debug, Display, Eq, PartialEq)]
21pub enum FatalError {
22 /// Tried to deserialize a number as a stage, but it does not correlate to a valid stage: {0}
23 StageOutOfBounds(usize),
24
25 /// Stage changed from {original_stage} to {actual_stage}, which should not be possible.
26 IllegalStageChange {
27 original_stage: Stage,
28 actual_stage: Stage,
29 },
30
31 /// While helping a thread, that thread's stage changed to {0}, which should not be possible.
32 IllegalHelpeeStage(Stage),
33
34 /// The target address {target_address} at word number {word_num} was not a valid pointer
35 TargetAddressWasNotValidPointer {
36 word_num: WordNum,
37 target_address: usize,
38 },
39
40 /** The sequence number of the current KCAS operation was changed by a thread other than
41 the originating thread {originating_thread_id}, which should not be possible.
42 */
43 SequenceNumChangedByNonOriginatingThread { originating_thread_id: ThreadId },
44
45 /** While setting the target address {target_address} at word number {word_num} to the desired
46 value, a CAS failure indicated the current value at the address was not a claim marker, but
47 instead {actual_value}, which should not be possible.
48 */
49 TriedToSetValueWhichWasNotClaimMarker {
50 word_num: WordNum,
51 target_address: usize,
52 actual_value: usize,
53 },
54 /** The top {num_reserved_bits} bits of value {value} at target address {target_address} with
55 word number {word_num} were not expected. These bits are reserved for kcas internal thread
56 identifiers and should not be used for real information: the only allowed values are either
57 all 0s or all 1s.
58 */
59 TopBitsOfValueWereIllegal {
60 word_num: WordNum,
61 target_address: usize,
62 value: usize,
63 /// the most significant bits
64 num_reserved_bits: usize,
65 },
66 ///
67 SharedStateWasNotValidPointer,
68}
69
70impl From<StageOutOfBoundsError> for FatalError {
71 fn from(stage_out_of_bounds_error: StageOutOfBoundsError) -> Self {
72 FatalError::StageOutOfBounds(stage_out_of_bounds_error.0)
73 }
74}
75
76/// Attempted to convert a usize into a Stage but it was out of bounds: {0}
77#[derive(Debug, Display, Eq, PartialEq)]
78pub struct StageOutOfBoundsError(pub(crate) usize);