Skip to content

Instantly share code, notes, and snippets.

@smirn0v
Created February 2, 2014 17:47
Show Gist options
  • Save smirn0v/8772052 to your computer and use it in GitHub Desktop.
Save smirn0v/8772052 to your computer and use it in GitHub Desktop.
OSSpinLockTry
/*
* void
* OSSpinLockUnlock(p)
* int *p;
*
* Unlock the lock pointed to by p.
*/
LEAF(_OSSpinLockUnlock, 0)
LEAF(_IOSpinUnlock, 0)
LEAF(_ev_unlock, 0)
movl $0, (%rdi)
END(_OSSpinLockUnlock)
/*
* int
* OSSpinLockTry(p)
* int *p;
*
* Try to lock p. Return zero if not successful.
*/
LEAF(_OSSpinLockTry, 0)
LEAF(_IOTrySpinLock, 0)
LEAF(_ev_try_lock, 0)
xorl %eax, %eax
orl $-1, %edx
lock
cmpxchgl %edx, (%rdi)
setz %dl
movzbl %dl, %eax
END(_OSSpinLockTry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment