pt-machine.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. Copyright (C) 1996, 1998, 2000, 2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Richard Henderson <rth@tamu.edu>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License as
  7. published by the Free Software Foundation; either version 2.1 of the
  8. License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If
  15. not, see <http://www.gnu.org/licenses/>. */
  16. #ifndef _PT_MACHINE_H
  17. #define _PT_MACHINE_H 1
  18. #include <features.h>
  19. #ifndef PT_EI
  20. # define PT_EI __extern_always_inline
  21. #endif
  22. #include <asm/fixed_code.h>
  23. /* Spinlock implementation; required. */
  24. /* The semantics of the TESTSET instruction cannot be guaranteed. We cannot
  25. easily move all locks used by linux kernel to non-cacheable memory.
  26. EXCPT 0x4 is used to trap into kernel to do the atomic testandset.
  27. It's ugly. But it's the only thing we can do now.
  28. The handler of EXCPT 0x4 expects the address of the lock is passed through
  29. R0. And the result is returned by R0. */
  30. PT_EI long int
  31. testandset (int *spinlock)
  32. {
  33. long int res;
  34. __asm__ __volatile__ (
  35. "CALL (%4);"
  36. : "=q0" (res), "=m" (*spinlock)
  37. : "qA" (spinlock), "m" (*spinlock), "a" (ATOMIC_XCHG32), "q1" (1)
  38. : "RETS", "cc", "memory");
  39. return res;
  40. }
  41. #define HAS_COMPARE_AND_SWAP
  42. PT_EI int
  43. __compare_and_swap (long int *p, long int oldval, long int newval)
  44. {
  45. long int readval;
  46. __asm__ __volatile__ (
  47. "CALL (%5);"
  48. : "=q0" (readval), "=m" (*p)
  49. : "qA" (p),
  50. "q1" (oldval),
  51. "q2" (newval),
  52. "a" (ATOMIC_CAS32),
  53. "m" (*p)
  54. : "RETS", "memory", "cc");
  55. return readval == oldval;
  56. }
  57. #ifdef SHARED
  58. # define PTHREAD_STATIC_FN_REQUIRE(name)
  59. #else
  60. # define PTHREAD_STATIC_FN_REQUIRE(name) __asm__ (".globl " "_"#name);
  61. #endif
  62. #endif /* pt-machine.h */