pt-machine.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #ifndef _PT_MACHINE_H
  14. #define _PT_MACHINE_H 1
  15. #include <features.h>
  16. #ifndef PT_EI
  17. # define PT_EI __extern_always_inline
  18. #endif
  19. /* Get some notion of the current stack. Need not be exactly the top
  20. of the stack, just something somewhere in the current frame. */
  21. #define CURRENT_STACK_FRAME __stack_pointer
  22. register char *__stack_pointer __asm__ ("sp");
  23. #define HAS_COMPARE_AND_SWAP
  24. /* Atomically: If *PTR == OLD, set *PTR to NEW and return true,
  25. otherwise do nothing and return false. */
  26. PT_EI int
  27. __compare_and_swap (long *ptr, long old, long new)
  28. {
  29. unsigned long psw;
  30. /* disable interrupts */
  31. __asm__ __volatile__ ("stsr psw, %0; di" : "=&r" (psw));
  32. if (likely (*ptr == old))
  33. {
  34. *ptr = new;
  35. __asm__ __volatile__ ("ldsr %0, psw" :: "r" (psw)); /* re-enable */
  36. return 1;
  37. }
  38. else
  39. {
  40. __asm__ __volatile__ ("ldsr %0, psw" :: "r" (psw)); /* re-enable */
  41. return 0;
  42. }
  43. }
  44. #endif /* pt-machine.h */