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. 13165968Simp * 3. Neither the name of the author nor the names of any co-contributors 1434365Sjb * may be used to endorse or promote products derived from this software 1534365Sjb * without specific prior written permission. 1634365Sjb * 1734365Sjb * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 1834365Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1934365Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2034365Sjb * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2134365Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2234365Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2334365Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2434365Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2534365Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2634365Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2734365Sjb * SUCH DAMAGE. 2834365Sjb * 2950476Speter * $FreeBSD$ 3034365Sjb * 3134365Sjb * Lock definitions used in both libc and libpthread. 3234365Sjb * 3334365Sjb */ 3434365Sjb 3534365Sjb#ifndef _SPINLOCK_H_ 3634365Sjb#define _SPINLOCK_H_ 3734365Sjb#include <sys/cdefs.h> 3836803Sjb#include <sys/types.h> 3934365Sjb 4034365Sjb/* 4136803Sjb * Lock structure with room for debugging information. 4236803Sjb */ 43122129Sdeischenstruct _spinlock { 4436803Sjb volatile long access_lock; 4536803Sjb volatile long lock_owner; 4636803Sjb volatile char *fname; 4736803Sjb volatile int lineno; 48122129Sdeischen}; 49122129Sdeischentypedef struct _spinlock spinlock_t; 5036803Sjb 5136803Sjb#define _SPINLOCK_INITIALIZER { 0, 0, 0, 0 } 5236803Sjb 53112665Sjeff#define _SPINUNLOCK(_lck) _spinunlock(_lck); 5436803Sjb#ifdef _LOCK_DEBUG 5536803Sjb#define _SPINLOCK(_lck) _spinlock_debug(_lck, __FILE__, __LINE__) 5636803Sjb#else 5736803Sjb#define _SPINLOCK(_lck) _spinlock(_lck) 5836803Sjb#endif 5936803Sjb 6036803Sjb/* 6134365Sjb * Thread function prototype definitions: 6234365Sjb */ 6334365Sjb__BEGIN_DECLS 6492905Sobrienlong _atomic_lock(volatile long *); 6592905Sobrienvoid _spinlock(spinlock_t *); 66112665Sjeffvoid _spinunlock(spinlock_t *); 6792905Sobrienvoid _spinlock_debug(spinlock_t *, char *, int); 6834365Sjb__END_DECLS 6934365Sjb 7034365Sjb#endif /* _SPINLOCK_H_ */ 71