lock.h revision 1.4
11.4Sthorpej/* $NetBSD: lock.h,v 1.4 2003/01/17 23:18:28 thorpej Exp $ */ 21.1Sthorpej 31.1Sthorpej/*- 41.1Sthorpej * Copyright (c) 2000 The NetBSD Foundation, Inc. 51.1Sthorpej * All rights reserved. 61.1Sthorpej * 71.1Sthorpej * This code is derived from software contributed to The NetBSD Foundation 81.1Sthorpej * by Jason R. Thorpe. 91.1Sthorpej * 101.1Sthorpej * Redistribution and use in source and binary forms, with or without 111.1Sthorpej * modification, are permitted provided that the following conditions 121.1Sthorpej * are met: 131.1Sthorpej * 1. Redistributions of source code must retain the above copyright 141.1Sthorpej * notice, this list of conditions and the following disclaimer. 151.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 161.1Sthorpej * notice, this list of conditions and the following disclaimer in the 171.1Sthorpej * documentation and/or other materials provided with the distribution. 181.1Sthorpej * 3. All advertising materials mentioning features or use of this software 191.1Sthorpej * must display the following acknowledgement: 201.1Sthorpej * This product includes software developed by the NetBSD 211.1Sthorpej * Foundation, Inc. and its contributors. 221.1Sthorpej * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Sthorpej * contributors may be used to endorse or promote products derived 241.1Sthorpej * from this software without specific prior written permission. 251.1Sthorpej * 261.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Sthorpej * POSSIBILITY OF SUCH DAMAGE. 371.1Sthorpej */ 381.1Sthorpej 391.1Sthorpej/* 401.1Sthorpej * Machine-dependent spin lock operations. 411.1Sthorpej */ 421.1Sthorpej 431.1Sthorpej#ifndef _M68K_LOCK_H_ 441.1Sthorpej#define _M68K_LOCK_H_ 451.2Sthorpej 461.3Sthorpejtypedef __volatile unsigned char __cpu_simple_lock_t; 471.1Sthorpej 481.3Sthorpej#define __SIMPLELOCK_LOCKED 0x80 /* result of `tas' insn */ 491.1Sthorpej#define __SIMPLELOCK_UNLOCKED 0 501.3Sthorpej 511.3Sthorpejstatic __inline void __cpu_simple_lock_init __P((__cpu_simple_lock_t *)) 521.3Sthorpej __attribute__((__unused__)); 531.3Sthorpejstatic __inline void __cpu_simple_lock __P((__cpu_simple_lock_t *)) 541.3Sthorpej __attribute__((__unused__)); 551.3Sthorpejstatic __inline int __cpu_simple_lock_try __P((__cpu_simple_lock_t *)) 561.3Sthorpej __attribute__((__unused__)); 571.3Sthorpejstatic __inline void __cpu_simple_unlock __P((__cpu_simple_lock_t *)) 581.3Sthorpej __attribute__((__unused__)); 591.3Sthorpej 601.3Sthorpejstatic __inline void 611.3Sthorpej__cpu_simple_lock_init(__cpu_simple_lock_t *alp) 621.3Sthorpej{ 631.3Sthorpej 641.3Sthorpej *alp = __SIMPLELOCK_UNLOCKED; 651.3Sthorpej} 661.3Sthorpej 671.3Sthorpejstatic __inline void 681.3Sthorpej__cpu_simple_lock(__cpu_simple_lock_t *alp) 691.3Sthorpej{ 701.3Sthorpej 711.3Sthorpej __asm __volatile( 721.3Sthorpej "1: tas %0 \n" 731.3Sthorpej " jne 1b \n" 741.3Sthorpej : "=m" (*alp)); 751.3Sthorpej} 761.3Sthorpej 771.3Sthorpejstatic __inline int 781.3Sthorpej__cpu_simple_lock_try(__cpu_simple_lock_t *alp) 791.3Sthorpej{ 801.4Sthorpej int __rv; 811.3Sthorpej 821.3Sthorpej __asm __volatile( 831.4Sthorpej " moveq #1, %1 \n" 841.3Sthorpej " tas %0 \n" 851.3Sthorpej " jeq 1f \n" 861.3Sthorpej " moveq #0, %1 \n" 871.3Sthorpej "1: \n" 881.3Sthorpej : "=m" (*alp), "=d" (__rv)); 891.3Sthorpej 901.3Sthorpej return (__rv); 911.3Sthorpej} 921.3Sthorpej 931.3Sthorpejstatic __inline void 941.3Sthorpej__cpu_simple_unlock(__cpu_simple_lock_t *alp) 951.3Sthorpej{ 961.3Sthorpej 971.3Sthorpej *alp = __SIMPLELOCK_UNLOCKED; 981.3Sthorpej} 991.1Sthorpej 1001.1Sthorpej#endif /* _M68K_LOCK_H_ */ 101