tas.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _SYS_TAS_H
  16. #define _SYS_TAS_H 1
  17. #include <features.h>
  18. #include <sgidefs.h>
  19. __BEGIN_DECLS
  20. extern int _test_and_set (int *p, int v) __THROW;
  21. #ifdef __USE_EXTERN_INLINES
  22. # ifndef _EXTERN_INLINE
  23. # define _EXTERN_INLINE __extern_inline
  24. # endif
  25. _EXTERN_INLINE int
  26. __NTH (_test_and_set (int *p, int v))
  27. {
  28. int r, t;
  29. __asm__ __volatile__
  30. ("/* Inline test and set */\n"
  31. "1:\n\t"
  32. ".set push\n\t"
  33. #if _MIPS_SIM == _ABIO32
  34. ".set mips2\n\t"
  35. #endif
  36. "ll %0,%3\n\t"
  37. "move %1,%4\n\t"
  38. "beq %0,%4,2f\n\t"
  39. "sc %1,%2\n\t"
  40. ".set pop\n\t"
  41. "beqz %1,1b\n"
  42. "2:\n\t"
  43. "/* End test and set */"
  44. : "=&r" (r), "=&r" (t), "=m" (*p)
  45. : "m" (*p), "r" (v)
  46. : "memory");
  47. return r;
  48. }
  49. #endif /* __USE_EXTERN_INLINES */
  50. __END_DECLS
  51. #endif /* sys/tas.h */