Back to index

glibc  2.9
machine-lock.h
Go to the documentation of this file.
00001 /* Machine-specific definition for spin locks.  MIPS version.
00002    Copyright (C) 1996, 1997 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
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 _MACHINE_LOCK_H
00021 #define       _MACHINE_LOCK_H
00022 
00023 /* To get the TAS pseudo-instruction. */
00024 #include <mach/mips/mips_instruction.h>
00025 
00026 /* The type of a spin lock variable.  */
00027 
00028 typedef __volatile int __spin_lock_t;
00029 
00030 /* Value to initialize `__spin_lock_t' variables to.  */
00031 
00032 #define       __SPIN_LOCK_INITIALIZER     0
00033 
00034 
00035 #ifndef _EXTERN_INLINE
00036 #define _EXTERN_INLINE extern __inline
00037 #endif
00038 
00039 /* Unlock LOCK.  */
00040 
00041 _EXTERN_INLINE void
00042 __spin_unlock (__spin_lock_t *__lock)
00043 {
00044   *__lock = 0;
00045 }
00046 
00047 /* Try to lock LOCK; return nonzero if we locked it, zero if another has.  */
00048 
00049 _EXTERN_INLINE int
00050 __spin_try_lock (register __spin_lock_t *__lock)
00051 {
00052 #if (__mips >= 2)
00053   int __rtn;
00054 
00055   __asm__ __volatile (".set noreorder");
00056 #if (__mips64)
00057   __asm__ __volatile ("lld %0,0(%1)" : "=r" (__rtn) : "r" (__lock));
00058 #else
00059   __asm__ __volatile ("ll %0,0(%1)" : "=r" (__rtn) : "r" (__lock));
00060 #endif
00061   if (__rtn)
00062     return 0;
00063   __asm__ __volatile ("move %0,%1" : "=r" (__rtn) : "r" (__lock));
00064 #if (__mips64)
00065   __asm__ __volatile ("scd %0,0(%1)" : "=r" (__rtn) : "r" (__lock));
00066 #else
00067   __asm__ __volatile ("sc %0,0(%1)" : "=r" (__rtn) : "r" (__lock));
00068 #endif
00069   __asm__ __volatile (".set reorder");
00070   return __rtn;
00071 #else
00072   register int __rtn __asm__ ("a0");
00073 
00074   /* Use the Mach microkernel's emulated TAS pseudo-instruction.  */
00075   __asm__ __volatile (".set noreorder");
00076   __asm__ __volatile (".word %1" : "=r" (__rtn) : "i" (op_tas), "0" (__lock));
00077   __asm__ __volatile ("nop");
00078   __asm__ __volatile (".set reorder");
00079   return __rtn ^ (int) __lock;
00080 #endif
00081 }
00082 
00083 /* Return nonzero if LOCK is locked.  */
00084 
00085 _EXTERN_INLINE int
00086 __spin_lock_locked (__spin_lock_t *__lock)
00087 {
00088   return *__lock != 0;
00089 }
00090 
00091 
00092 #endif /* machine-lock.h */