From 045d0e1053d65ff8cffccc4694de3305b243edb2 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Mon, 24 Jun 2013 16:51:37 -0400 Subject: [PATCH] ck_spinlock: Apply modulo arithmetic to proportional back-off ticket lock. --- include/ck_spinlock.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/ck_spinlock.h b/include/ck_spinlock.h index b78051b..d0252d7 100644 --- a/include/ck_spinlock.h +++ b/include/ck_spinlock.h @@ -492,7 +492,7 @@ ck_spinlock_ticket_lock_pb(struct ck_spinlock_ticket *ticket, unsigned int c) position = CK_SPINLOCK_TICKET_LOAD(&ticket->value) & CK_SPINLOCK_TICKET_MASK; - backoff = request - position; + backoff = (request - position) & CK_SPINLOCK_TICKET_MASK; backoff <<= c; ck_backoff_eb(&backoff); } @@ -596,8 +596,7 @@ ck_spinlock_ticket_lock_pb(struct ck_spinlock_ticket *ticket, unsigned int c) if (position == request) break; - /* Overflow is handled fine, assuming 2s complement. */ - backoff = (request - position); + backoff = (request - position) & CK_SPINLOCK_TICKET_MASK; backoff <<= c; /*