summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-08-08 16:03:11 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-08-23 09:38:59 -0400
commit43a59c487209293ee48b8d1f0215ceb643af8ad3 (patch)
treec48f27495110df338f52d08e8b3e483cda0056ac /src
parent15ce658253f13f356d51b746938b19c9ffe1f33d (diff)
downloadbfs-43a59c487209293ee48b8d1f0215ceb643af8ad3.tar.xz
ioq: New ioq_slot_monitor() helper
Diffstat (limited to 'src')
-rw-r--r--src/ioq.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/ioq.c b/src/ioq.c
index a394e07..f7ca8c6 100644
--- a/src/ioq.c
+++ b/src/ioq.c
@@ -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():