Define F_DUPFD_CLOEXEC.
[glibc-ports.git] / sysdeps / mach / mips / machine-lock.h
blobeccc720dfaf12eb993247ce84e9c047ae5434da4
1 /* Machine-specific definition for spin locks. MIPS version.
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _MACHINE_LOCK_H
21 #define _MACHINE_LOCK_H
23 /* To get the TAS pseudo-instruction. */
24 #include <mach/mips/mips_instruction.h>
26 /* The type of a spin lock variable. */
28 typedef __volatile int __spin_lock_t;
30 /* Value to initialize `__spin_lock_t' variables to. */
32 #define __SPIN_LOCK_INITIALIZER 0
35 #ifndef _EXTERN_INLINE
36 #define _EXTERN_INLINE extern __inline
37 #endif
39 /* Unlock LOCK. */
41 _EXTERN_INLINE void
42 __spin_unlock (__spin_lock_t *__lock)
44 *__lock = 0;
47 /* Try to lock LOCK; return nonzero if we locked it, zero if another has. */
49 _EXTERN_INLINE int
50 __spin_try_lock (register __spin_lock_t *__lock)
52 #if (__mips >= 2)
53 int __rtn;
55 __asm__ __volatile (".set noreorder");
56 #if (__mips64)
57 __asm__ __volatile ("lld %0,0(%1)" : "=r" (__rtn) : "r" (__lock));
58 #else
59 __asm__ __volatile ("ll %0,0(%1)" : "=r" (__rtn) : "r" (__lock));
60 #endif
61 if (__rtn)
62 return 0;
63 __asm__ __volatile ("move %0,%1" : "=r" (__rtn) : "r" (__lock));
64 #if (__mips64)
65 __asm__ __volatile ("scd %0,0(%1)" : "=r" (__rtn) : "r" (__lock));
66 #else
67 __asm__ __volatile ("sc %0,0(%1)" : "=r" (__rtn) : "r" (__lock));
68 #endif
69 __asm__ __volatile (".set reorder");
70 return __rtn;
71 #else
72 register int __rtn __asm__ ("a0");
74 /* Use the Mach microkernel's emulated TAS pseudo-instruction. */
75 __asm__ __volatile (".set noreorder");
76 __asm__ __volatile (".word %1" : "=r" (__rtn) : "i" (op_tas), "0" (__lock));
77 __asm__ __volatile ("nop");
78 __asm__ __volatile (".set reorder");
79 return __rtn ^ (int) __lock;
80 #endif
83 /* Return nonzero if LOCK is locked. */
85 _EXTERN_INLINE int
86 __spin_lock_locked (__spin_lock_t *__lock)
88 return *__lock != 0;
92 #endif /* machine-lock.h */