
I've noticed two different approaches to implementing spinlock primitives that disable interrupts while the lock is held.
NT and Linux return the old interrupt state to the caller on acquire (KeAcquireSpinlock and spin_lock_irqsave, respectively), and the caller must pass that state back in on release. In NT, the state is the IRQL and in Linux x86 the state is the old EFLAGS contents, but they basically achieve the same thing.
QNX, on the other hand, doesn't return anything from InterruptLock and doesn't require that anything be passed to InterruptUnlock, except for the spinlock itself of course.
I'm designing my Lock right now and I'm curious about the advantages/disadvantages of the two approaches. I don't see why I wouldn't just store the old EFLAGS in the lock structure itself while the lock is being held, rather than return it to the caller and rely on the caller to pass it back in properly later. The only reasons I can think of for doing this are performance-related (trying to avoid unnecessary bus traffic if the lock exists in several CPU caches, maybe?), unless I'm missing something.
Thoughts/opinions?