1 /* Machine-dependent pthreads configuration and inline functions.
3 * Copyright (C) 2005-2007 Atmel Corporation
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.
10 #define _PT_MACHINE_H 1
15 # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
16 # define PT_EI static inline __attribute__((always_inline))
18 # define PT_EI extern inline __attribute__((always_inline))
23 _test_and_set (int *p, int v) __THROW
28 "/* Inline test and set */\n"
29 " xchg %[old], %[mem], %[new]"
31 : [mem] "r"(p), [new] "r"(v)
37 extern long int testandset (int *spinlock);
38 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
40 /* Spinlock implementation; required. */
42 testandset (int *spinlock)
44 return _test_and_set(spinlock, 1);
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");
53 /* Compare-and-swap for semaphores. */
55 #define HAS_COMPARE_AND_SWAP
57 __compare_and_swap(long int *p, long int oldval, long int newval)
62 "/* Inline compare and swap */\n"
64 " ld.w %[result], %[mem]\n"
65 " eor %[result], %[old]\n"
67 " stcond %[mem], %[new]\n"
70 : [result] "=&r"(result), [mem] "=m"(*p)
71 : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
77 #endif /* pt-machine.h */