blob: be874ad2892dffa1d163f84b5f69e51a20035bd4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
/* $OpenBSD: _atomic_lock.c,v 1.1 1998/11/20 11:15:36 d Exp $ */
/*
* Atomic lock for m68k
*/
#include "spinlock.h"
register_t
_atomic_lock(volatile register_t *lock)
{
register_t old;
/*
* The Compare And Swap instruction (mc68020 and above)
* compares its first operand with the memory addressed by
* the third. If they are the same value, the second operand
* is stored at the address. Otherwise the 1st operand (register)
* is loaded with the contents of the 3rd operand.
*
* old = 0;
* CAS(old, 1, *lock);
* return old;
*/
old = 0;
__asm__("casl %0, %2, %1" : "=d"(old), "=m"(*lock)
: "d"(1), "0"(old));
return old;
}
|