yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sysdeps/v850/pt-machine.h -- v850-specific pthread definitions |
| 3 | * |
| 4 | * Copyright (C) 2002 NEC Electronics Corporation |
| 5 | * Copyright (C) 2002 Miles Bader <miles@gnu.org> |
| 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU Lesser |
| 8 | * General Public License. See the file COPYING.LIB in the main |
| 9 | * directory of this archive for more details. |
| 10 | * |
| 11 | * Written by Miles Bader <miles@gnu.org> |
| 12 | */ |
| 13 | |
| 14 | #ifndef _PT_MACHINE_H |
| 15 | #define _PT_MACHINE_H 1 |
| 16 | |
| 17 | #include <features.h> |
| 18 | |
| 19 | #ifndef PT_EI |
| 20 | # define PT_EI __extern_always_inline |
| 21 | #endif |
| 22 | |
| 23 | /* Get some notion of the current stack. Need not be exactly the top |
| 24 | of the stack, just something somewhere in the current frame. */ |
| 25 | #define CURRENT_STACK_FRAME __stack_pointer |
| 26 | register char *__stack_pointer __asm__ ("sp"); |
| 27 | |
| 28 | #define HAS_COMPARE_AND_SWAP |
| 29 | |
| 30 | /* Atomically: If *PTR == OLD, set *PTR to NEW and return true, |
| 31 | otherwise do nothing and return false. */ |
| 32 | PT_EI int |
| 33 | __compare_and_swap (long *ptr, long old, long new) |
| 34 | { |
| 35 | unsigned long psw; |
| 36 | |
| 37 | /* disable interrupts */ |
| 38 | __asm__ __volatile__ ("stsr psw, %0; di" : "=&r" (psw)); |
| 39 | |
| 40 | if (likely (*ptr == old)) |
| 41 | { |
| 42 | *ptr = new; |
| 43 | __asm__ __volatile__ ("ldsr %0, psw" :: "r" (psw)); /* re-enable */ |
| 44 | return 1; |
| 45 | } |
| 46 | else |
| 47 | { |
| 48 | __asm__ __volatile__ ("ldsr %0, psw" :: "r" (psw)); /* re-enable */ |
| 49 | return 0; |
| 50 | } |
| 51 | } |
| 52 | #endif /* pt-machine.h */ |