
1: /* Copyright (C) 1994, 1996, 2007 Free Software Foundation, Inc. 2: This file is part of the GNU C Library. 3: 4: The GNU C Library is free software; you can redistribute it and/or 5: modify it under the terms of the GNU Lesser General Public 6: License as published by the Free Software Foundation; either 7: version 2.1 of the License, or (at your option) any later version. 8: 9: The GNU C Library is distributed in the hope that it will be useful, 10: but WITHOUT ANY WARRANTY; without even the implied warranty of 11: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12: Lesser General Public License for more details. 13: 14: You should have received a copy of the GNU Lesser General Public 15: License along with the GNU C Library; if not, write to the Free 16: Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 17: 02111-1307 USA. */ 18: 19: #ifndef _LOCK_INTERN_H 20: #define _LOCK_INTERN_H 21: 22: #include <sys/cdefs.h> 23: #include <machine-lock.h> 24: 25: #ifndef _EXTERN_INLINE 26: #define _EXTERN_INLINE __extern_inline 27: #endif 28: 29: 30: /* Initialize LOCK. */ 31: 32: _EXTERN_INLINE void 33: __spin_lock_init (__spin_lock_t *__lock) 34: { 35: *__lock = __SPIN_LOCK_INITIALIZER; 36: } 37: 38: 39: /* Lock LOCK, blocking if we can't get it. */ 40: extern void __spin_lock_solid (__spin_lock_t *__lock); 41: 42: /* Lock the spin lock LOCK. */ 43: 44: _EXTERN_INLINE void 45: __spin_lock (__spin_lock_t *__lock) 46: { 47: if (! __spin_try_lock (__lock)) 48: __spin_lock_solid (__lock); 49: } 50: ^L 51: /* Name space-clean internal interface to mutex locks. 52: 53: Code internal to the C library uses these functions to lock and unlock 54: mutex locks. These locks are of type `struct mutex', defined in 55: <cthreads.h>. The functions here are name space-clean. If the program 56: is linked with the cthreads library, `__mutex_lock_solid' and 57: `__mutex_unlock_solid' will invoke the corresponding cthreads functions 58: to implement real mutex locks. If not, simple stub versions just use 59: spin locks. */ 60: 61: 62: /* Initialize the newly allocated mutex lock LOCK for further use. */ 63: extern void __mutex_init (void *__lock); 64: 65: /* Lock LOCK, blocking if we can't get it. */ 66: extern void __mutex_lock_solid (void *__lock); 67: 68: /* Finish unlocking LOCK, after the spin lock LOCK->held has already been 69: unlocked. This function will wake up any thread waiting on LOCK. */ 70: extern void __mutex_unlock_solid (void *__lock); 71: 72: /* Lock the mutex lock LOCK. */ 73: 74: _EXTERN_INLINE void 75: __mutex_lock (void *__lock) 76: { 77: if (! __spin_try_lock ((__spin_lock_t *) __lock)) 78: __mutex_lock_solid (__lock); 79: } 80: 81: /* Unlock the mutex lock LOCK. */ 82: 83: _EXTERN_INLINE void 84: __mutex_unlock (void *__lock) 85: { 86: __spin_unlock ((__spin_lock_t *) __lock); 87: __mutex_unlock_solid (__lock); 88: } 89: 90: 91: _EXTERN_INLINE int 92: __mutex_trylock (void *__lock) 93: { 94: return __spin_try_lock ((__spin_lock_t *) __lock); 95: } 96: 97: #endif /* lock-intern.h */