lock.h

Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 2000 The NetBSD Foundation, Inc.
00003  * All rights reserved.
00004  *
00005  * This code is derived from software contributed to The NetBSD Foundation
00006  * by Jason R. Thorpe.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. All advertising materials mentioning features or use of this software
00017  *    must display the following acknowledgement:
00018  *      This product includes software developed by the NetBSD
00019  *      Foundation, Inc. and its contributors.
00020  * 4. Neither the name of The NetBSD Foundation nor the names of its
00021  *    contributors may be used to endorse or promote products derived
00022  *    from this software without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
00025  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00027  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
00028  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  * POSSIBILITY OF SUCH DAMAGE.
00035  */
00036 #ifndef __MACHDEP_LOCK_H__
00037 #define __MACHDEP_LOCK_H__
00038 /*
00039  * Machine-dependent spin lock operations.
00040  */
00041 
00042 typedef __volatile int          __cpu_simple_lock_t;
00043 
00044 #define __SIMPLELOCK_LOCKED     1
00045 #define __SIMPLELOCK_UNLOCKED   0
00046 
00047 static __inline void __cpu_simple_lock_init(__cpu_simple_lock_t *)
00048         __attribute__((__unused__));
00049 static __inline void __cpu_simple_lock(__cpu_simple_lock_t *)
00050         __attribute__((__unused__));
00051 static __inline int __cpu_simple_lock_try(__cpu_simple_lock_t *)
00052         __attribute__((__unused__));
00053 static __inline void __cpu_simple_unlock(__cpu_simple_lock_t *) 
00054         __attribute__((__unused__));
00055 
00056 static __inline void
00057 __cpu_simple_lock_init(__cpu_simple_lock_t *alp)
00058 {
00059 
00060         *alp = __SIMPLELOCK_UNLOCKED;
00061 }
00062 
00063 static __inline void
00064 __cpu_simple_lock(__cpu_simple_lock_t *alp)
00065 {
00066         int __val = __SIMPLELOCK_LOCKED;
00067 
00068         do {
00069                 __asm __volatile("xchgl %0, %2"
00070                         : "=r" (__val)
00071                         : "0" (__val), "m" (*alp));
00072         } while (__val != __SIMPLELOCK_UNLOCKED);
00073 }
00074 
00075 static __inline int
00076 __cpu_simple_lock_try(__cpu_simple_lock_t *alp)
00077 {
00078         int __val = __SIMPLELOCK_LOCKED;
00079 
00080         __asm __volatile("xchgl %0, %2"
00081                 : "=r" (__val)
00082                 : "0" (__val), "m" (*alp));
00083 
00084         return ((__val == __SIMPLELOCK_UNLOCKED) ? 1 : 0);
00085 }
00086 
00087 static __inline void
00088 __cpu_simple_unlock(__cpu_simple_lock_t *alp)
00089 {
00090 
00091         *alp = __SIMPLELOCK_UNLOCKED;
00092 }
00093 
00094 #endif

Generated on Wed May 24 23:04:17 2006 for LSE/OS by  doxygen 1.4.6