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 
00003    Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004
00004    Free Software Foundation, Inc.
00005    This file is part of the GNU C Library.
00006    Contributed by Ralf Baechle <ralf@gnu.org>.
00007    Based on the Alpha version by Richard Henderson <rth@tamu.edu>.
00008 
00009    The GNU C Library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Lesser General Public License as
00011    published by the Free Software Foundation; either version 2.1 of the
00012    License, or (at your option) any later version.
00013 
00014    The GNU C Library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Lesser General Public License for more details.
00018 
00019    You should have received a copy of the GNU Lesser General Public
00020    License along with the GNU C Library; see the file COPYING.LIB.  If
00021    not, write to the Free Software Foundation, Inc.,
00022    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00023 
00024 #ifndef _PT_MACHINE_H
00025 #define _PT_MACHINE_H   1
00026 
00027 #include <sgidefs.h>
00028 #include <sys/tas.h>
00029 
00030 #ifndef PT_EI
00031 # define PT_EI extern inline __attribute__ ((always_inline))
00032 #endif
00033 
00034 extern long int testandset (int *spinlock);
00035 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
00036 
00037 
00038 /* Spinlock implementation; required.  */
00039 
00040 PT_EI long int
00041 testandset (int *spinlock)
00042 {
00043   return _test_and_set (spinlock, 1);
00044 }
00045 
00046 
00047 /* Get some notion of the current stack.  Need not be exactly the top
00048    of the stack, just something somewhere in the current frame.  */
00049 #define CURRENT_STACK_FRAME  stack_pointer
00050 register char * stack_pointer __asm__ ("$29");
00051 
00052 
00053 /* Compare-and-swap for semaphores. */
00054 
00055 #define HAS_COMPARE_AND_SWAP
00056 PT_EI int
00057 __compare_and_swap (long int *p, long int oldval, long int newval)
00058 {
00059   long int ret, temp;
00060 
00061   __asm__ __volatile__
00062     ("/* Inline compare & swap */\n"
00063      "1:\n\t"
00064      ".set    push\n\t"
00065 #if _MIPS_SIM == _ABIO32
00066      ".set    mips2\n\t"
00067 #endif
00068 #if _MIPS_SIM == _ABI64
00069      "lld     %1,%5\n\t"
00070 #else
00071      "ll      %1,%5\n\t"
00072 #endif
00073      "move    %0,$0\n\t"
00074      "bne     %1,%3,2f\n\t"
00075      "move    %0,%4\n\t"
00076 #if _MIPS_SIM == _ABI64
00077      "scd     %0,%2\n\t"
00078 #else
00079      "sc      %0,%2\n\t"
00080 #endif
00081      ".set    pop\n\t"
00082      "beqz    %0,1b\n"
00083      "2:\n\t"
00084      "/* End compare & swap */"
00085      : "=&r" (ret), "=&r" (temp), "=m" (*p)
00086      : "r" (oldval), "r" (newval), "m" (*p)
00087      : "memory");
00088 
00089   return ret;
00090 }
00091 
00092 #endif /* pt-machine.h */