pt-machine.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004
  3. Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Ralf Baechle <ralf@gnu.org>.
  6. Based on the Alpha version by Richard Henderson <rth@tamu.edu>.
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public License as
  9. published by the Free Software Foundation; either version 2.1 of the
  10. License, or (at your option) any later version.
  11. The GNU C Library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the GNU C Library; see the file COPYING.LIB. If
  17. not, write to the Free Software Foundation, Inc.,
  18. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  19. #ifndef _PT_MACHINE_H
  20. #define _PT_MACHINE_H 1
  21. #include <sgidefs.h>
  22. #include <sys/tas.h>
  23. #ifndef PT_EI
  24. # define PT_EI extern inline __attribute__ ((always_inline))
  25. #endif
  26. extern long int testandset (int *spinlock);
  27. extern int __compare_and_swap (long int *p, long int oldval, long int newval);
  28. /* Spinlock implementation; required. */
  29. PT_EI long int
  30. testandset (int *spinlock)
  31. {
  32. return _test_and_set (spinlock, 1);
  33. }
  34. /* Get some notion of the current stack. Need not be exactly the top
  35. of the stack, just something somewhere in the current frame. */
  36. #define CURRENT_STACK_FRAME stack_pointer
  37. register char * stack_pointer __asm__ ("$29");
  38. /* Compare-and-swap for semaphores. */
  39. #define HAS_COMPARE_AND_SWAP
  40. PT_EI int
  41. __compare_and_swap (long int *p, long int oldval, long int newval)
  42. {
  43. long int ret, temp;
  44. __asm__ __volatile__
  45. ("/* Inline compare & swap */\n"
  46. "1:\n\t"
  47. ".set push\n\t"
  48. #if _MIPS_SIM == _ABIO32
  49. ".set mips2\n\t"
  50. #endif
  51. #if _MIPS_SIM == _ABI64
  52. "lld %1,%5\n\t"
  53. #else
  54. "ll %1,%5\n\t"
  55. #endif
  56. "move %0,$0\n\t"
  57. "bne %1,%3,2f\n\t"
  58. "move %0,%4\n\t"
  59. #if _MIPS_SIM == _ABI64
  60. "scd %0,%2\n\t"
  61. #else
  62. "sc %0,%2\n\t"
  63. #endif
  64. ".set pop\n\t"
  65. "beqz %0,1b\n"
  66. "2:\n\t"
  67. "/* End compare & swap */"
  68. : "=&r" (ret), "=&r" (temp), "=m" (*p)
  69. : "r" (oldval), "r" (newval), "m" (*p)
  70. : "memory");
  71. return ret;
  72. }
  73. #endif /* pt-machine.h */