Simple spinlock for C using ASM, revision #1
As you have no doubt noticed, given your follow up post, whilst your current lock is thread safe, it isn't reentrant.

If you perform a double call to atomic_open from the same thread, the second call will fail to enter the gate (because it's already locked) and become deadlocked against itself.

lock xchg %%eax, %[gate]\n" // Exhange eax with gate value.
"test %%eax, %%eax\n"        // 1 = closed, 0 = open.


This is because there's no tracking of which thread opened the gate.

Not checking the thread has the potential to cause another issue (which you might not care about, because it's pretty common with spinlocks) whereby if you have a bug in your code, it is possible for a thread that doesn't own the lock to unlock it (anybody can call atomic_close and it will unlock, even if they didn't call atomic_open first).