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    S390 version.
00003    Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
00004    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
00005    This file is part of the GNU C Library.
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 not,
00019    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020    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 /* For multiprocessor systems, we want to ensure all memory accesses
00033    are completed before we reset a lock.  On other systems, we still
00034    need to make sure that the compiler has flushed everything to memory.  */
00035 #define MEMORY_BARRIER() __asm__ __volatile__ ("bcr 15,0" : : : "memory")
00036 
00037 /* Spinlock implementation; required.  */
00038 PT_EI long int
00039 testandset (int *spinlock)
00040 {
00041   int ret;
00042 
00043   __asm__ __volatile__(
00044        "    la    1,%1\n"
00045        "    lhi   0,1\n"
00046        "    l     %0,%1\n"
00047        "0:  cs    %0,0,0(1)\n"
00048        "    jl    0b"
00049        : "=&d" (ret), "+m" (*spinlock)
00050        : : "0", "1", "cc");
00051 
00052   return ret;
00053 }
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
00059 register char * stack_pointer __asm__ ("15");
00060 
00061 #ifdef USE_TLS
00062 /* Return the thread descriptor for the current thread.  */
00063 # define THREAD_SELF ((pthread_descr) __builtin_thread_pointer ())
00064 
00065 /* Initialize the thread-unique value.  */
00066 #define INIT_THREAD_SELF(descr, nr) __builtin_set_thread_pointer (descr)
00067 #else
00068 /* Return the thread descriptor for the current thread.
00069    S/390 registers uses access register 0 as "thread register".  */
00070 #define THREAD_SELF  ({                                                       \
00071   register pthread_descr __self;                                              \
00072   __asm__ ("ear %0,%%a0" : "=d" (__self) );                                   \
00073   __self;                                                                     \
00074 })
00075 
00076 /* Initialize the thread-unique value.  */
00077 #define INIT_THREAD_SELF(descr, nr)  ({                                       \
00078   __asm__ ("sar %%a0,%0" : : "d" (descr) );                                   \
00079 })
00080 #endif
00081 
00082 /* Access to data in the thread descriptor is easy.  */
00083 #define THREAD_GETMEM(descr, member) \
00084   ((void) sizeof (descr), THREAD_SELF->member)
00085 #define THREAD_GETMEM_NC(descr, member) \
00086   ((void) sizeof (descr), THREAD_SELF->member)
00087 #define THREAD_SETMEM(descr, member, value) \
00088   ((void) sizeof (descr), THREAD_SELF->member = (value))
00089 #define THREAD_SETMEM_NC(descr, member, value) \
00090   ((void) sizeof (descr), THREAD_SELF->member = (value))
00091 
00092 /* We want the OS to assign stack addresses.  */
00093 #define FLOATING_STACKS 1
00094 
00095 /* Maximum size of the stack if the rlimit is unlimited.  */
00096 #define ARCH_STACK_MAX_SIZE     8*1024*1024
00097 
00098 /* Compare-and-swap for semaphores. */
00099 
00100 #define HAS_COMPARE_AND_SWAP
00101 
00102 PT_EI int
00103 __compare_and_swap(long int *p, long int oldval, long int newval)
00104 {
00105         int retval;
00106 
00107         __asm__ __volatile__(
00108                 "  la   1,%1\n"
00109                 "  lr   0,%2\n"
00110                 "  cs   0,%3,0(1)\n"
00111                 "  ipm  %0\n"
00112                 "  srl  %0,28\n"
00113                 "0:"
00114                 : "=&d" (retval), "+m" (*p)
00115                 : "d" (oldval) , "d" (newval)
00116                 : "cc", "0", "1" );
00117         return retval == 0;
00118 }
00119 
00120 #endif /* pt-machine.h */