⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

Module hazard

Module hazard 

Source
Expand description

Hazard Pointer Registry

Hazard pointers provide safe memory reclamation for lock-free data structures. When a thread reads a shared pointer, it publishes the address in a per-CPU hazard pointer slot. Before freeing memory, the reclaimer checks all hazard pointers to ensure no thread is actively referencing the object.

This is simpler than RCU for single-object protection and is used alongside RCU for different access patterns:

  • RCU: read-heavy data structures with infrequent updates
  • Hazard pointers: fine-grained per-object protection in lock-free containers (queues, stacks, hash maps)

Structs§

HazardGuard
A guard that holds a hazard pointer slot. When dropped, the slot is cleared (set to HP_EMPTY).

Functions§

active_count
Get the number of active (non-empty) hazard pointer slots.
clear_cpu_slots
Clear all hazard pointer slots for a given CPU.
collect_protected
Scan all hazard pointer slots and return a list of currently protected addresses. Used for batch reclamation: collect a retire list, then filter out any addresses that appear in the hazard set.
is_protected
Check whether a given address is currently protected by any hazard pointer.
protect
Protect a pointer by publishing it in a hazard pointer slot.