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    CRIS version.
00003    Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public License as
00008    published by the Free Software Foundation; either version 2.1 of the
00009    License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00018    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.  */
00020 
00021 #ifndef _PT_MACHINE_H
00022 #define _PT_MACHINE_H   1
00023 
00024 #ifndef PT_EI
00025 # define PT_EI extern inline __attribute__ ((always_inline))
00026 #endif
00027 
00028 extern long int testandset (int *spinlock);
00029 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
00030 
00031 PT_EI long int
00032 testandset (int *spinlock)
00033 {
00034   register unsigned long int ret;
00035 
00036   /* Note the use of a dummy output of *spinlock to expose the write.  The
00037      memory barrier is to stop *other* writes being moved past this code.  */
00038   __asm__ __volatile__("clearf\n"
00039                      "0:\n\t"
00040                      "movu.b [%2],%0\n\t"
00041                      "ax\n\t"
00042                      "move.b %3,[%2]\n\t"
00043                      "bwf 0b\n\t"
00044                      "clearf"
00045                      : "=&r" (ret), "=m" (*spinlock)
00046                      : "r" (spinlock), "r" ((int) 1)
00047                      : "memory");
00048   return ret;
00049 }
00050 
00051 
00052 /* Get some notion of the current stack.  Need not be exactly the top
00053    of the stack, just something somewhere in the current frame.
00054    I don't trust register variables, so let's do this the safe way.  */
00055 #define CURRENT_STACK_FRAME \
00056  ({ char *sp; __asm__ ("move.d $sp,%0" : "=rm" (sp)); sp; })
00057 
00058 #endif /* pt-machine.h */