OSDN Git Service

- fixup gnu_inline vs. C99 inline
[uclinux-h8/uClibc.git] / libpthread / linuxthreads / sysdeps / avr32 / pt-machine.h
1 /* Machine-dependent pthreads configuration and inline functions.
2  *
3  * Copyright (C) 2005-2007 Atmel Corporation
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser General
6  * Public License.  See the file "COPYING.LIB" in the main directory of this
7  * archive for more details.
8  */
9 #ifndef _PT_MACHINE_H
10 #define _PT_MACHINE_H   1
11
12 #include <features.h>
13
14 #ifndef PT_EI
15 # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
16 #  define PT_EI static inline __attribute__((always_inline))
17 # else
18 #  define PT_EI extern inline __attribute__((always_inline))
19 # endif
20 #endif
21
22 static inline int
23 _test_and_set (int *p, int v) __THROW
24 {
25        int result;
26
27        __asm__ __volatile__(
28                "/* Inline test and set */\n"
29                "       xchg    %[old], %[mem], %[new]"
30                : [old] "=&r"(result)
31                : [mem] "r"(p), [new] "r"(v)
32                : "memory");
33
34        return result;
35 }
36
37 extern long int testandset (int *spinlock);
38 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
39
40 /* Spinlock implementation; required.  */
41 PT_EI long int
42 testandset (int *spinlock)
43 {
44        return _test_and_set(spinlock, 1);
45 }
46
47
48 /* Get some notion of the current stack.  Need not be exactly the top
49    of the stack, just something somewhere in the current frame.  */
50 #define CURRENT_STACK_FRAME  stack_pointer
51 register char * stack_pointer __asm__ ("sp");
52
53 /* Compare-and-swap for semaphores. */
54
55 #define HAS_COMPARE_AND_SWAP
56 PT_EI int
57 __compare_and_swap(long int *p, long int oldval, long int newval)
58 {
59        int result;
60
61        __asm__ __volatile__(
62                "/* Inline compare and swap */\n"
63                "1:     ssrf    5\n"
64                "       ld.w    %[result], %[mem]\n"
65                "       eor     %[result], %[old]\n"
66                "       brne    2f\n"
67                "       stcond  %[mem], %[new]\n"
68                "       brne    1b\n"
69                "2:"
70                : [result] "=&r"(result), [mem] "=m"(*p)
71                : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
72                : "cc", "memory");
73
74        return result == 0;
75 }
76
77 #endif /* pt-machine.h */