#ifndef TICKET_H #define TICKET_H /* Simple ticket lock. Ought to be modified to incorporate proportional backoff. NB: ticket locks grant requests in strictly FIFO order. They don't mix well with preemptive scheduling. */ #include "atomic_ops.h" typedef struct ticket_lock { volatile unsigned long next_ticket; volatile unsigned long now_serving; } ticket_lock; static __inline__ void ticket_acquire(ticket_lock *L) { unsigned long my_ticket = fai(&L->next_ticket); while (L->now_serving != my_ticket); } static __inline__ void ticket_release(ticket_lock *L) { L->now_serving += 1; } #endif