From b8c801136a8856c2c1750eb643b26ddb2ac1671c Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Sat, 18 Jan 2014 16:51:02 -0500 Subject: [PATCH] ck_bytelock: Fix deadlock for unslotted reader workloads. There is an off-by-one for slot ID sizeof(bytelock->readers) + 1. This patch fixes the handling of this slot ID. Based off a patch submitted by Albi Kavo . --- include/ck_bytelock.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/ck_bytelock.h b/include/ck_bytelock.h index 26fa438..cf12d58 100644 --- a/include/ck_bytelock.h +++ b/include/ck_bytelock.h @@ -89,7 +89,7 @@ ck_bytelock_write_lock(struct ck_bytelock *bytelock, unsigned int slot) ck_pr_stall(); /* If we are slotted, we might be upgrading from a read lock. */ - if (slot < sizeof bytelock->readers) + if (slot <= sizeof bytelock->readers) ck_pr_store_8(&bytelock->readers[slot - 1], false); /* Wait for slotted readers to drain out. */ @@ -175,11 +175,10 @@ ck_bytelock_read_unlock(struct ck_bytelock *bytelock, unsigned int slot) ck_pr_fence_release(); - slot -= 1; if (slot > sizeof bytelock->readers) ck_pr_dec_uint(&bytelock->n_readers); else - ck_pr_store_8(&bytelock->readers[slot], false); + ck_pr_store_8(&bytelock->readers[slot - 1], false); return; }