| 1 | /* @title: General Locking */ |
| 2 | #pragma once |
| 3 | #include <compiler/name.h> |
| 4 | #include <stdint.h> |
| 5 | |
| 6 | /* The reason we have this is because code around the kernel uses a function |
| 7 | * parameter to indicate the held state of a lock. Using this enum rather than |
| 8 | * booleans avoids ad-hoc annotations at callsites, assigns explicit names, and |
| 9 | * improves readability and searchability. */ |
| 10 | enum lock_held_state { |
| 11 | /* We're intentionally using truthy and falsy compatible values here: |
| 12 | * much code assumes true == locked, and this will remain stable so |
| 13 | * only the signatures and types change, and code can still go |
| 14 | * |
| 15 | * `if (held) do_thing();` */ |
| 16 | LOCK_NOT_HELD = 0, |
| 17 | LOCK_HELD = 1, |
| 18 | }; |
| 19 | |
| 20 | /* for breaking ordering cycles between locks of the same class |
| 21 | * max is LOCK_CHK_MAX_SUBCLASSES (8) */ |
| 22 | enum lock_subclass : uint8_t { |
| 23 | LOCK_SUBCLASS_PRIMARY = 0, |
| 24 | LOCK_SUBCLASS_SECONDARY = 1, |
| 25 | LOCK_SUBCLASS_TERTIARY = 2, |
| 26 | |
| 27 | /* aliases */ |
| 28 | LOCK_SUBCLASS_PARENT = 0, |
| 29 | LOCK_SUBCLASS_CHILD = 1, |
| 30 | |
| 31 | LOCK_SUBCLASS_SRC_CPU = 0, |
| 32 | LOCK_SUBCLASS_DST_CPU = 1, |
| 33 | |
| 34 | LOCK_SUBCLASS_LOWER = 0, |
| 35 | LOCK_SUBCLASS_HIGHER = 1, |
| 36 | }; |
| 37 | |
| 38 | enum lock_acquire_policy { |
| 39 | LOCK_ACQUIRE_BLOCKING = 0, |
| 40 | LOCK_ACQUIRE_NONBLOCKING = 1, |
| 41 | }; |
| 42 | |