diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-08-08 16:03:11 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-08-23 09:38:59 -0400 |
commit | 43a59c487209293ee48b8d1f0215ceb643af8ad3 (patch) | |
tree | c48f27495110df338f52d08e8b3e483cda0056ac /src | |
parent | 15ce658253f13f356d51b746938b19c9ffe1f33d (diff) | |
download | bfs-43a59c487209293ee48b8d1f0215ceb643af8ad3.tar.xz |
ioq: New ioq_slot_monitor() helper
Diffstat (limited to 'src')
-rw-r--r-- | src/ioq.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -146,10 +146,15 @@ static struct ioqq *ioqq_create(size_t size) { return ioqq; } +/** Get the monitor associated with a slot. */ +static struct ioq_monitor *ioq_slot_monitor(struct ioqq *ioqq, ioq_slot *slot) { + size_t i = slot - ioqq->slots; + return &ioqq->monitors[i & ioqq->monitor_mask]; +} + /** Atomically wait for a slot to change. */ static uintptr_t ioq_slot_wait(struct ioqq *ioqq, ioq_slot *slot, uintptr_t value) { - size_t i = slot - ioqq->slots; - struct ioq_monitor *monitor = &ioqq->monitors[i & ioqq->monitor_mask]; + struct ioq_monitor *monitor = ioq_slot_monitor(ioqq, slot); mutex_lock(&monitor->mutex); uintptr_t ret = load(slot, relaxed); @@ -178,8 +183,7 @@ done: /** Wake up any threads waiting on a slot. */ static void ioq_slot_wake(struct ioqq *ioqq, ioq_slot *slot) { - size_t i = slot - ioqq->slots; - struct ioq_monitor *monitor = &ioqq->monitors[i & ioqq->monitor_mask]; + struct ioq_monitor *monitor = ioq_slot_monitor(ioqq, slot); // The following implementation would clearly avoid the missed wakeup // issue mentioned above in ioq_slot_wait(): |