Simple spinlock for C using ASM
Op's code has a possible race condition between the lock and compare.

"lock xadd %[lock], %[gate]\n" 
"cmp %[lock], %[open]\n"       

OP identified: lock is not certainly made a shared variable.