pt-machine.h 1.2 KB

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