Back to index

glibc  2.9
pt-machine.h
Go to the documentation of this file.
00001 /* Machine-dependent pthreads configuration and inline functions.
00002    Sparc v9 version.
00003    Copyright (C) 1997-2002, 2003 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005    Contributed by Richard Henderson <rth@tamu.edu>.
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public License as
00009    published by the Free Software Foundation; either version 2.1 of the
00010    License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; see the file COPYING.LIB.  If
00019    not, write to the Free Software Foundation, Inc.,
00020    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00021 
00022 #ifndef _PT_MACHINE_H
00023 #define _PT_MACHINE_H   1
00024 
00025 #ifndef PT_EI
00026 # define PT_EI extern inline __attribute__ ((always_inline))
00027 #endif
00028 
00029 extern long int testandset (int *spinlock);
00030 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
00031 
00032 /* Spinlock implementation; required.  */
00033 PT_EI long int
00034 testandset (int *spinlock)
00035 {
00036   int ret;
00037 
00038   __asm__ __volatile__("ldstub %1,%0"
00039        : "=r" (ret), "=m" (*spinlock) : "m" (*spinlock));
00040 
00041   return ret;
00042 }
00043 
00044 
00045 /* Memory barrier; default is to do nothing */
00046 #define MEMORY_BARRIER() \
00047      __asm__ __volatile__("membar #LoadLoad | #LoadStore | #StoreLoad | #StoreStore" : : : "memory")
00048 /* Read barrier.  */
00049 #define READ_MEMORY_BARRIER() \
00050      __asm__ __volatile__("membar #LoadLoad | #LoadStore" : : : "memory")
00051 /* Write barrier.  */
00052 #define WRITE_MEMORY_BARRIER() \
00053      __asm__ __volatile__("membar #StoreLoad | #StoreStore" : : : "memory")
00054 
00055 
00056 /* Get some notion of the current stack.  Need not be exactly the top
00057    of the stack, just something somewhere in the current frame.  */
00058 #define CURRENT_STACK_FRAME  (stack_pointer + (2 * 128))
00059 register char *stack_pointer __asm__ ("%sp");
00060 
00061 
00062 /* Registers %g6 and %g7 are reserved by the ABI for "system use".  The
00063    TLS ABI specifies %g7 as the thread pointer.  */
00064 struct _pthread_descr_struct;
00065 register struct _pthread_descr_struct *__thread_self __asm__ ("%g7");
00066 
00067 /* Return the thread descriptor for the current thread.  */
00068 #define THREAD_SELF  __thread_self
00069 
00070 /* Initialize the thread-unique value.  */
00071 #define INIT_THREAD_SELF(descr, nr)  (__thread_self = (descr))
00072 
00073 
00074 /* Compare-and-swap for semaphores. */
00075 
00076 #define HAS_COMPARE_AND_SWAP
00077 PT_EI int
00078 __compare_and_swap (long int *p, long int oldval, long int newval)
00079 {
00080   long int readval;
00081 
00082   __asm__ __volatile__ ("casx      [%4], %2, %0"
00083                      : "=r"(readval), "=m"(*p)
00084                      : "r"(oldval), "m"(*p), "r"(p), "0"(newval));
00085   MEMORY_BARRIER();
00086   return readval == oldval;
00087 }
00088 
00089 /* Access to data in the thread descriptor is easy.  */
00090 #define THREAD_GETMEM(descr, member) \
00091   ((void) sizeof (descr), THREAD_SELF->member)
00092 #define THREAD_GETMEM_NC(descr, member) \
00093   ((void) sizeof (descr), THREAD_SELF->member)
00094 #define THREAD_SETMEM(descr, member, value) \
00095   ((void) sizeof (descr), THREAD_SELF->member = (value))
00096 #define THREAD_SETMEM_NC(descr, member, value) \
00097   ((void) sizeof (descr), THREAD_SELF->member = (value))
00098 
00099 /* We want the OS to assign stack addresses.  */
00100 #define FLOATING_STACKS 1
00101 
00102 /* Maximum size of the stack if the rlimit is unlimited.  */
00103 #define ARCH_STACK_MAX_SIZE     32*1024*1024
00104 
00105 #endif /* pt-machine.h */