From 79e336cfbc3f201a4dbc0e987dcf3bc81ebd6e88 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Sun, 19 Aug 2012 16:35:14 -0400 Subject: [PATCH] ck_spinlock: Clarify ticket spinlock code. Some people might be confused as far as lack of fencing in the lock. Add a comment to clarify that old values should not be equal to new values of current position (where acquiring the current position already has a global ordering). --- include/ck_spinlock.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/ck_spinlock.h b/include/ck_spinlock.h index 2d15a20..cac2210 100644 --- a/include/ck_spinlock.h +++ b/include/ck_spinlock.h @@ -420,7 +420,11 @@ ck_spinlock_ticket_lock(struct ck_spinlock_ticket *ticket) /* Get our ticket number and set next ticket number. */ request = ck_pr_faa_uint(&ticket->next, 1); - /* Busy-wait until our ticket number is current. */ + /* + * Busy-wait until our ticket number is current. + * We can get away without a fence here assuming + * our position counter does not overflow. + */ while (ck_pr_load_uint(&ticket->position) != request) ck_pr_stall(); @@ -469,7 +473,7 @@ ck_spinlock_ticket_unlock(struct ck_spinlock_ticket *ticket) * it is only an issue if there are 2^32 pending lock requests. */ update = ck_pr_load_uint(&ticket->position); - ck_pr_store_uint(&ticket->position, ++update); + ck_pr_store_uint(&ticket->position, update + 1); return; } #endif /* CK_F_SPINLOCK_TICKET */