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).
ck_pring
Samy Al Bahra 13 years ago
parent 27ed5f78fe
commit 79e336cfbc

@ -420,7 +420,11 @@ ck_spinlock_ticket_lock(struct ck_spinlock_ticket *ticket)
/* Get our ticket number and set next ticket number. */ /* Get our ticket number and set next ticket number. */
request = ck_pr_faa_uint(&ticket->next, 1); 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) while (ck_pr_load_uint(&ticket->position) != request)
ck_pr_stall(); 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. * it is only an issue if there are 2^32 pending lock requests.
*/ */
update = ck_pr_load_uint(&ticket->position); update = ck_pr_load_uint(&ticket->position);
ck_pr_store_uint(&ticket->position, ++update); ck_pr_store_uint(&ticket->position, update + 1);
return; return;
} }
#endif /* CK_F_SPINLOCK_TICKET */ #endif /* CK_F_SPINLOCK_TICKET */

Loading…
Cancel
Save