mutex.h revision 1.5
11.5Sriastrad/*	$NetBSD: mutex.h,v 1.5 2023/07/09 17:03:10 riastradh Exp $	*/
21.1Sjmcneill
31.1Sjmcneill/*-
41.1Sjmcneill * Copyright (c) 2002, 2006 The NetBSD Foundation, Inc.
51.1Sjmcneill * All rights reserved.
61.1Sjmcneill *
71.1Sjmcneill * This code is derived from software contributed to The NetBSD Foundation
81.1Sjmcneill * by Jason R. Thorpe and Andrew Doran.
91.1Sjmcneill *
101.1Sjmcneill * Redistribution and use in source and binary forms, with or without
111.1Sjmcneill * modification, are permitted provided that the following conditions
121.1Sjmcneill * are met:
131.1Sjmcneill * 1. Redistributions of source code must retain the above copyright
141.1Sjmcneill *    notice, this list of conditions and the following disclaimer.
151.1Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright
161.1Sjmcneill *    notice, this list of conditions and the following disclaimer in the
171.1Sjmcneill *    documentation and/or other materials provided with the distribution.
181.1Sjmcneill *
191.1Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Sjmcneill * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Sjmcneill * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Sjmcneill * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Sjmcneill * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Sjmcneill * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Sjmcneill * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Sjmcneill * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Sjmcneill * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Sjmcneill * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Sjmcneill * POSSIBILITY OF SUCH DAMAGE.
301.1Sjmcneill */
311.1Sjmcneill
321.2Sjmcneill#ifndef _ARCH_USERMODE_INCLUDE_MUTEX_H_
331.2Sjmcneill#define	_ARCH_USERMODE_INCLUDE_MUTEX_H_
341.1Sjmcneill
351.5Sriastrad#ifdef __MUTEX_PRIVATE
361.5Sriastrad#include <machine/intr.h>
371.5Sriastrad#include <machine/lock.h>
381.5Sriastrad#endif
391.5Sriastrad
401.1Sjmcneillstruct kmutex {
411.1Sjmcneill	union {
421.1Sjmcneill		volatile uintptr_t	mtxa_owner;
431.1Sjmcneill#ifdef __MUTEX_PRIVATE
441.1Sjmcneill		struct {
451.1Sjmcneill			volatile uint8_t	mtxs_dummy;
461.1Sjmcneill			ipl_cookie_t		mtxs_ipl;
471.1Sjmcneill                        __cpu_simple_lock_t	mtxs_lock;
481.1Sjmcneill			volatile uint8_t	mtxs_unused;
491.1Sjmcneill		} s;
501.1Sjmcneill#endif
511.1Sjmcneill	} u;
521.1Sjmcneill};
531.1Sjmcneill
541.1Sjmcneill#ifdef __MUTEX_PRIVATE
551.1Sjmcneill
561.1Sjmcneill#define	mtx_owner 			u.mtxa_owner
571.1Sjmcneill#define	mtx_ipl 			u.s.mtxs_ipl
581.1Sjmcneill#define	mtx_lock			u.s.mtxs_lock
591.1Sjmcneill
601.1Sjmcneill#define	__HAVE_SIMPLE_MUTEXES		1
611.1Sjmcneill
621.1Sjmcneill#define	MUTEX_CAS(p, o, n)		\
631.1Sjmcneill    (_atomic_cas_ulong((volatile unsigned long *)(p), (o), (n)) == (o))
641.1Sjmcneill
651.1Sjmcneillunsigned long	_atomic_cas_ulong(volatile unsigned long *,
661.1Sjmcneill    unsigned long, unsigned long);
671.1Sjmcneill
681.1Sjmcneill#endif	/* __MUTEX_PRIVATE */
691.1Sjmcneill
701.2Sjmcneill#endif /* _ARCH_USERMODE_INCLUDE_MUTEX_H_ */
71