Back to index

glibc  2.9
tas.h
Go to the documentation of this file.
00001 /* Copyright (C) 2000, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Maciej W. Rozycki <macro@ds2.pg.gda.pl>, 2000.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _SYS_TAS_H
00021 #define _SYS_TAS_H 1
00022 
00023 #include <features.h>
00024 #include <sgidefs.h>
00025 
00026 __BEGIN_DECLS
00027 
00028 extern int _test_and_set (int *p, int v) __THROW;
00029 
00030 #ifdef __USE_EXTERN_INLINES
00031 
00032 # ifndef _EXTERN_INLINE
00033 #  define _EXTERN_INLINE __extern_inline
00034 # endif
00035 
00036 _EXTERN_INLINE int
00037 __NTH (_test_and_set (int *p, int v))
00038 {
00039   int r, t;
00040 
00041   __asm__ __volatile__
00042     ("/* Inline test and set */\n"
00043      ".set    push\n\t"
00044 #if _MIPS_SIM == _ABIO32
00045      ".set    mips2\n\t"
00046 #endif
00047      "sync\n\t"
00048      "1:\n\t"
00049      "ll      %0,%3\n\t"
00050      "move    %1,%4\n\t"
00051      "beq     %0,%4,2f\n\t"
00052      "sc      %1,%2\n\t"
00053      "beqz    %1,1b\n"
00054      "sync\n\t"
00055      ".set    pop\n\t"
00056      "2:\n\t"
00057      "/* End test and set */"
00058      : "=&r" (r), "=&r" (t), "=m" (*p)
00059      : "m" (*p), "r" (v)
00060      : "memory");
00061 
00062   return r;
00063 }
00064 
00065 #endif /* __USE_EXTERN_INLINES */
00066 
00067 __END_DECLS
00068 
00069 #endif /* sys/tas.h */