spinlock.h revision 92905
134365Sjb/* 234365Sjb * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>. 334365Sjb * All rights reserved. 434365Sjb * 534365Sjb * Redistribution and use in source and binary forms, with or without 634365Sjb * modification, are permitted provided that the following conditions 734365Sjb * are met: 834365Sjb * 1. Redistributions of source code must retain the above copyright 934365Sjb * notice, this list of conditions and the following disclaimer. 1034365Sjb * 2. Redistributions in binary form must reproduce the above copyright 1134365Sjb * notice, this list of conditions and the following disclaimer in the 1234365Sjb * documentation and/or other materials provided with the distribution. 1334365Sjb * 3. All advertising materials mentioning features or use of this software 1434365Sjb * must display the following acknowledgement: 1534365Sjb * This product includes software developed by John Birrell. 1634365Sjb * 4. Neither the name of the author nor the names of any co-contributors 1734365Sjb * may be used to endorse or promote products derived from this software 1834365Sjb * without specific prior written permission. 1934365Sjb * 2034365Sjb * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 2134365Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2234365Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2334365Sjb * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2434365Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2534365Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2634365Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2734365Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2834365Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2934365Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3034365Sjb * SUCH DAMAGE. 3134365Sjb * 3250476Speter * $FreeBSD: head/lib/libc/include/spinlock.h 92905 2002-03-21 22:49:10Z obrien $ 3334365Sjb * 3434365Sjb * Lock definitions used in both libc and libpthread. 3534365Sjb * 3634365Sjb */ 3734365Sjb 3834365Sjb#ifndef _SPINLOCK_H_ 3934365Sjb#define _SPINLOCK_H_ 4034365Sjb#include <sys/cdefs.h> 4136803Sjb#include <sys/types.h> 4234365Sjb 4334365Sjb/* 4436803Sjb * Lock structure with room for debugging information. 4536803Sjb */ 4636803Sjbtypedef struct { 4736803Sjb volatile long access_lock; 4836803Sjb volatile long lock_owner; 4936803Sjb volatile char *fname; 5036803Sjb volatile int lineno; 5136803Sjb} spinlock_t; 5236803Sjb 5336803Sjb#define _SPINLOCK_INITIALIZER { 0, 0, 0, 0 } 5436803Sjb 5536803Sjb#define _SPINUNLOCK(_lck) (_lck)->access_lock = 0 5636803Sjb#ifdef _LOCK_DEBUG 5736803Sjb#define _SPINLOCK(_lck) _spinlock_debug(_lck, __FILE__, __LINE__) 5836803Sjb#else 5936803Sjb#define _SPINLOCK(_lck) _spinlock(_lck) 6036803Sjb#endif 6136803Sjb 6236803Sjb/* 6334365Sjb * Thread function prototype definitions: 6434365Sjb */ 6534365Sjb__BEGIN_DECLS 6692905Sobrienlong _atomic_lock(volatile long *); 6792905Sobrienvoid _spinlock(spinlock_t *); 6892905Sobrienvoid _spinlock_debug(spinlock_t *, char *, int); 6934365Sjb__END_DECLS 7034365Sjb 7134365Sjb#endif /* _SPINLOCK_H_ */ 72