|
rlib
Convenience library for useful things
|
Safe reclamation for lock-free data structures: readers publish "I'm using @c p" hazard records so writers know not to free p until every reader has moved on.
More...
Files | |
| file | rhzrptr.h |
| Hazard pointers — safe reclamation for lock-free reads. | |
Data Structures | |
| struct | rhzrptr |
| Pointer slot that participates in hazard-pointer reclamation. More... | |
Macros | |
| #define | R_HZR_PTR_INIT(notify) { 0, (RDestroyNotify)notify } |
Static initialiser for an rhzrptr with destroy notifier notify. | |
Typedefs | |
| typedef struct RHzrPtrRec | RHzrPtrRec |
| Opaque per-thread hazard record. | |
Functions | |
| rpointer | r_hzr_ptr_acquire (rhzrptr *hzrptr, RHzrPtrRec *rec) |
Publish a hazard for the current value of hzrptr and return it. | |
| void | r_hzr_ptr_release (rhzrptr *hzrptr, RHzrPtrRec *rec) |
| Drop the hazard published by a previous r_hzr_ptr_acquire. | |
| void | r_hzr_ptr_replace (rhzrptr *hzrptr, rpointer ptr) |
Atomically replace hzrptr's value with ptr and schedule the displaced value for delayed reclamation. | |
| RHzrPtrRec * | r_hzr_ptr_rec_new (void) |
| Allocate a per-thread hazard record. | |
| void | r_hzr_ptr_rec_free (RHzrPtrRec *rec) |
| Free a per-thread hazard record at thread exit. | |
Safe reclamation for lock-free data structures: readers publish "I'm using @c p" hazard records so writers know not to free p until every reader has moved on.
The shape mirrors the canonical Michael 2004 design:
| rpointer r_hzr_ptr_acquire | ( | rhzrptr * | hzrptr, |
| RHzrPtrRec * | rec | ||
| ) |
Publish a hazard for the current value of hzrptr and return it.
Pair with r_hzr_ptr_release once the caller is done with the returned pointer; while a hazard is active on the value, writers will defer freeing it.
Atomically replace hzrptr's value with ptr and schedule the displaced value for delayed reclamation.
The previous value is freed via hzrptr->notify once no RHzrPtrRec still holds a hazard on it.