File: pt-machine.h

package info (click to toggle)
uclibc 1.0.31-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 28,252 kB
  • sloc: ansic: 215,237; asm: 33,111; cpp: 4,643; makefile: 2,861; sh: 716; yacc: 610; perl: 535; lex: 364; awk: 40
file content (73 lines) | stat: -rw-r--r-- 1,692 bytes parent folder | download | duplicates (8)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Machine-dependent pthreads configuration and inline functions.
 *
 * Copyright (C) 2005-2007 Atmel Corporation
 *
 * This file is subject to the terms and conditions of the GNU Lesser General
 * Public License.  See the file "COPYING.LIB" in the main directory of this
 * archive for more details.
 */
#ifndef _PT_MACHINE_H
#define _PT_MACHINE_H   1

#include <features.h>

#ifndef PT_EI
# define PT_EI __extern_always_inline
#endif

static __inline__ int
_test_and_set (int *p, int v)
{
	int result;

	__asm__ __volatile__(
		"/* Inline test and set */\n"
		"	xchg	%[old], %[mem], %[new]"
		: [old] "=&r"(result)
		: [mem] "r"(p), [new] "r"(v)
		: "memory");

	return result;
}

extern long int testandset (int *spinlock);
extern int __compare_and_swap (long int *p, long int oldval, long int newval);

/* Spinlock implementation; required.  */
PT_EI long int
testandset (int *spinlock)
{
	return _test_and_set(spinlock, 1);
}


/* Get some notion of the current stack.  Need not be exactly the top
   of the stack, just something somewhere in the current frame.  */
#define CURRENT_STACK_FRAME  stack_pointer
register char * stack_pointer __asm__ ("sp");

/* Compare-and-swap for semaphores. */

#define HAS_COMPARE_AND_SWAP
PT_EI int
__compare_and_swap(long int *p, long int oldval, long int newval)
{
	long int result;

	__asm__ __volatile__(
		"/* Inline compare and swap */\n"
		"1:	ssrf	5\n"
		"	ld.w	%[result], %[mem]\n"
		"	eor	%[result], %[old]\n"
		"	brne	2f\n"
		"	stcond	%[mem], %[new]\n"
		"	brne	1b\n"
		"2:"
		: [result] "=&r"(result), [mem] "=m"(*p)
		: "m"(*p), [new] "r"(newval), [old] "r"(oldval)
		: "cc", "memory");

	return result == 0;
}

#endif /* pt-machine.h */