tas.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright (C) 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Maciej W. Rozycki <macro@ds2.pg.gda.pl>, 2000.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _SYS_TAS_H
  17. #define _SYS_TAS_H 1
  18. #include <features.h>
  19. #include <sgidefs.h>
  20. #include <sys/sysmips.h>
  21. __BEGIN_DECLS
  22. extern int _test_and_set (int *p, int v) __THROW;
  23. #ifdef __USE_EXTERN_INLINES
  24. # ifndef _EXTERN_INLINE
  25. # define _EXTERN_INLINE extern __inline
  26. # endif
  27. # if (_MIPS_ISA >= _MIPS_ISA_MIPS2)
  28. _EXTERN_INLINE int
  29. _test_and_set (int *p, int v) __THROW
  30. {
  31. int r, t;
  32. __asm__ __volatile__
  33. ("1:\n\t"
  34. "ll %0,%3\n\t"
  35. ".set push\n\t"
  36. ".set noreorder\n\t"
  37. "beq %0,%4,2f\n\t"
  38. " move %1,%4\n\t"
  39. ".set pop\n\t"
  40. "sc %1,%2\n\t"
  41. "beqz %1,1b\n"
  42. "2:\n"
  43. : "=&r" (r), "=&r" (t), "=m" (*p)
  44. : "m" (*p), "r" (v)
  45. : "memory");
  46. return r;
  47. }
  48. # else /* !(_MIPS_ISA >= _MIPS_ISA_MIPS2) */
  49. _EXTERN_INLINE int
  50. _test_and_set (int *p, int v) __THROW
  51. {
  52. return sysmips (MIPS_ATOMIC_SET, (int) p, v, 0);
  53. }
  54. # endif /* !(_MIPS_ISA >= _MIPS_ISA_MIPS2) */
  55. #endif /* __USE_EXTERN_INLINES */
  56. __END_DECLS
  57. #endif /* sys/tas.h */