pt-machine.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. Sparc v9 version.
  3. Copyright (C) 1997-2002, 2003 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Richard Henderson <rth@tamu.edu>.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public License as
  8. published by the Free Software Foundation; either version 2.1 of the
  9. License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; see the file COPYING.LIB. If
  16. not, write to the Free Software Foundation, Inc.,
  17. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  18. #ifndef _PT_MACHINE_H
  19. #define _PT_MACHINE_H 1
  20. #ifndef PT_EI
  21. # define PT_EI extern inline __attribute__ ((always_inline))
  22. #endif
  23. extern long int testandset (int *spinlock);
  24. extern int __compare_and_swap (long int *p, long int oldval, long int newval);
  25. /* Spinlock implementation; required. */
  26. PT_EI long int
  27. testandset (int *spinlock)
  28. {
  29. int ret;
  30. __asm__ __volatile__("ldstub %1,%0"
  31. : "=r" (ret), "=m" (*spinlock) : "m" (*spinlock));
  32. return ret;
  33. }
  34. /* Memory barrier; default is to do nothing */
  35. #define MEMORY_BARRIER() \
  36. __asm__ __volatile__("membar #LoadLoad | #LoadStore | #StoreLoad | #StoreStore" : : : "memory")
  37. /* Read barrier. */
  38. #define READ_MEMORY_BARRIER() \
  39. __asm__ __volatile__("membar #LoadLoad | #LoadStore" : : : "memory")
  40. /* Write barrier. */
  41. #define WRITE_MEMORY_BARRIER() \
  42. __asm__ __volatile__("membar #StoreLoad | #StoreStore" : : : "memory")
  43. /* Get some notion of the current stack. Need not be exactly the top
  44. of the stack, just something somewhere in the current frame. */
  45. #define CURRENT_STACK_FRAME (stack_pointer + (2 * 128))
  46. register char *stack_pointer __asm__ ("%sp");
  47. /* Registers %g6 and %g7 are reserved by the ABI for "system use". The
  48. TLS ABI specifies %g7 as the thread pointer. */
  49. struct _pthread_descr_struct;
  50. register struct _pthread_descr_struct *__thread_self __asm__ ("%g7");
  51. /* Return the thread descriptor for the current thread. */
  52. #define THREAD_SELF __thread_self
  53. /* Initialize the thread-unique value. */
  54. #define INIT_THREAD_SELF(descr, nr) (__thread_self = (descr))
  55. /* Compare-and-swap for semaphores. */
  56. #define HAS_COMPARE_AND_SWAP
  57. PT_EI int
  58. __compare_and_swap (long int *p, long int oldval, long int newval)
  59. {
  60. long int readval;
  61. __asm__ __volatile__ ("casx [%4], %2, %0"
  62. : "=r"(readval), "=m"(*p)
  63. : "r"(oldval), "m"(*p), "r"(p), "0"(newval));
  64. MEMORY_BARRIER();
  65. return readval == oldval;
  66. }
  67. /* Access to data in the thread descriptor is easy. */
  68. #define THREAD_GETMEM(descr, member) \
  69. ((void) sizeof (descr), THREAD_SELF->member)
  70. #define THREAD_GETMEM_NC(descr, member) \
  71. ((void) sizeof (descr), THREAD_SELF->member)
  72. #define THREAD_SETMEM(descr, member, value) \
  73. ((void) sizeof (descr), THREAD_SELF->member = (value))
  74. #define THREAD_SETMEM_NC(descr, member, value) \
  75. ((void) sizeof (descr), THREAD_SELF->member = (value))
  76. /* We want the OS to assign stack addresses. */
  77. #define FLOATING_STACKS 1
  78. /* Maximum size of the stack if the rlimit is unlimited. */
  79. #define ARCH_STACK_MAX_SIZE 32*1024*1024
  80. #endif /* pt-machine.h */