tas.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 2000, 2002, 2003, 2004 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. __BEGIN_DECLS
  21. extern int _test_and_set (int *p, int v) __THROW;
  22. #ifdef __USE_EXTERN_INLINES
  23. # ifndef _EXTERN_INLINE
  24. # define _EXTERN_INLINE extern __inline
  25. # endif
  26. _EXTERN_INLINE int
  27. __NTH (_test_and_set (int *p, int v))
  28. {
  29. int r, t;
  30. __asm__ __volatile__
  31. ("/* Inline test and set */\n"
  32. "1:\n\t"
  33. ".set push\n\t"
  34. #if _MIPS_SIM == _ABIO32
  35. ".set mips2\n\t"
  36. #endif
  37. "ll %0,%3\n\t"
  38. "move %1,%4\n\t"
  39. "beq %0,%4,2f\n\t"
  40. "sc %1,%2\n\t"
  41. ".set pop\n\t"
  42. "beqz %1,1b\n"
  43. "2:\n\t"
  44. "/* End test and set */"
  45. : "=&r" (r), "=&r" (t), "=m" (*p)
  46. : "m" (*p), "r" (v)
  47. : "memory");
  48. return r;
  49. }
  50. #endif /* __USE_EXTERN_INLINES */
  51. __END_DECLS
  52. #endif /* sys/tas.h */