summaryrefslogtreecommitdiff
path: root/lib/librthread/arch/vax/_atomic_lock.c
blob: 8f0a0fd510b958c38276fa81f3c686985132a96f (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*	$OpenBSD: _atomic_lock.c,v 1.1 2005/12/23 19:52:04 miod Exp $	*/

/*
 * Atomic lock for vax
 * Written by Miodrag Vallat <miod@openbsd.org> - placed in the public domain.
 */

#include "spinlock.h"

int
_atomic_lock(volatile _spinlock_lock_t *lock)
{
	_spinlock_lock_t old;

	/*
	 * The Branch on Bit Set and Set Interlocked instruction
	 * sets a given bit in a register or a memory location, as an
	 * atomic, interlocked operation.
	 * If the bit was set, execution continues at the branch
	 * location.
	 *
	 * For more details, please refer to the Vax Architecture
	 * Reference Manual, chapter 3 (Instructions), section
	 * ``Control instructions''.
	 */
	__asm__ (
		"movl	$1, %1\n"	/* _SPINLOCK_LOCKED */
		"bbssi	$0, %0, 1f\n"
		"movl	$0, %1\n"	/* _SPINLOCK_UNLOCKED */
		"1:	\n"
		: "=m" (*lock), "=r" (old) : "0" (*lock)
	);

	return (old != _SPINLOCK_UNLOCKED);
}

int
_atomic_is_locked(volatile _spinlock_lock_t *lock)
{

	return (*lock != _SPINLOCK_UNLOCKED);
}