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    SuperH version.
00003    Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005    Contributed by Niibe Yutaka <gniibe@m17n.org>.
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 __ASSEMBLER__
00026 #ifndef PT_EI
00027 # define PT_EI extern inline __attribute__ ((always_inline))
00028 #endif
00029 
00030 extern long int testandset (int *spinlock);
00031 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
00032 
00033 /* Spinlock implementation; required.  */
00034 PT_EI long int
00035 testandset (int *spinlock)
00036 {
00037   int ret;
00038 
00039   __asm__ __volatile__(
00040        "tas.b @%1\n\t"
00041        "movt  %0"
00042        : "=r" (ret)
00043        : "r" (spinlock)
00044        : "memory", "cc");
00045 
00046   return (ret == 0);
00047 }
00048 
00049 /* We want the OS to assign stack addresses.  */
00050 #define FLOATING_STACKS 1
00051 
00052 /* Maximum size of the stack if the rlimit is unlimited.  */
00053 #define ARCH_STACK_MAX_SIZE     32*1024*1024
00054 
00055 /* Get some notion of the current stack.  Need not be exactly the top
00056    of the stack, just something somewhere in the current frame.  */
00057 #define CURRENT_STACK_FRAME  stack_pointer
00058 register char * stack_pointer __asm__ ("r15");
00059 
00060 /* Return the thread descriptor for the current thread.  */
00061 struct _pthread_descr_struct;
00062 #define THREAD_SELF \
00063   ({ struct _pthread_descr_struct *self; \
00064       __asm__("stc gbr,%0" : "=r" (self)); self;})
00065 
00066 /* Initialize the thread-unique value.  */
00067 #define INIT_THREAD_SELF(descr, nr) \
00068   ({ __asm__ __volatile__("ldc %0,gbr" : : "r" (descr));})
00069 
00070 /* Access to data in the thread descriptor is easy.  */
00071 #define THREAD_GETMEM(descr, member) \
00072   ((void) sizeof (descr), THREAD_SELF->member)
00073 #define THREAD_GETMEM_NC(descr, member) \
00074   ((void) sizeof (descr), THREAD_SELF->member)
00075 #define THREAD_SETMEM(descr, member, value) \
00076   ((void) sizeof (descr), THREAD_SELF->member = (value))
00077 #define THREAD_SETMEM_NC(descr, member, value) \
00078   ((void) sizeof (descr), THREAD_SELF->member = (value))
00079 #endif /* __ASSEMBLER__ */
00080 
00081 #endif /* pt-machine.h */