General Locking
include/sync/lock_general.h View source View on GitHublock_held_state
Section titled “lock_held_state” enum lock_held_state (2 variants) source
The reason we have this is because code around the kernel uses a function parameter to indicate the held state of a lock. Using this enum rather than booleans avoids ad-hoc annotations at callsites, assigns explicit names, and improves readability and searchability.
§
LOCK_NOT_HELD = 0 We’re intentionally using truthy and falsy compatible values here: much code assumes true == locked, and this will remain stable so only the signatures and types change, and code can still go
if (held) do_thing();
§
LOCK_HELD = 1 lock_subclass
Section titled “lock_subclass” enum lock_subclass : uint8_t (9 variants) source
for breaking ordering cycles between locks of the same class max is LOCK_CHK_MAX_SUBCLASSES (8)
§
LOCK_SUBCLASS_PRIMARY = 0 §
LOCK_SUBCLASS_SECONDARY = 1 §
LOCK_SUBCLASS_TERTIARY = 2 §
LOCK_SUBCLASS_PARENT = 0 aliases
§
LOCK_SUBCLASS_CHILD = 1 §
LOCK_SUBCLASS_SRC_CPU = 0 §
LOCK_SUBCLASS_DST_CPU = 1 §
LOCK_SUBCLASS_LOWER = 0 §
LOCK_SUBCLASS_HIGHER = 1