xref: /illumos-gate/usr/src/boot/sys/sys/_mutex.h (revision 199767f8)
1*199767f8SToomas Soome /*-
2*199767f8SToomas Soome  * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
3*199767f8SToomas Soome  *
4*199767f8SToomas Soome  * Redistribution and use in source and binary forms, with or without
5*199767f8SToomas Soome  * modification, are permitted provided that the following conditions
6*199767f8SToomas Soome  * are met:
7*199767f8SToomas Soome  * 1. Redistributions of source code must retain the above copyright
8*199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer.
9*199767f8SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
10*199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
11*199767f8SToomas Soome  *    documentation and/or other materials provided with the distribution.
12*199767f8SToomas Soome  * 3. Berkeley Software Design Inc's name may not be used to endorse or
13*199767f8SToomas Soome  *    promote products derived from this software without specific prior
14*199767f8SToomas Soome  *    written permission.
15*199767f8SToomas Soome  *
16*199767f8SToomas Soome  * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
17*199767f8SToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*199767f8SToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*199767f8SToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
20*199767f8SToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*199767f8SToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*199767f8SToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*199767f8SToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*199767f8SToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*199767f8SToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*199767f8SToomas Soome  * SUCH DAMAGE.
27*199767f8SToomas Soome  *
28*199767f8SToomas Soome  * $FreeBSD$
29*199767f8SToomas Soome  */
30*199767f8SToomas Soome 
31*199767f8SToomas Soome #ifndef _SYS__MUTEX_H_
32*199767f8SToomas Soome #define	_SYS__MUTEX_H_
33*199767f8SToomas Soome 
34*199767f8SToomas Soome #include <machine/param.h>
35*199767f8SToomas Soome 
36*199767f8SToomas Soome /*
37*199767f8SToomas Soome  * Sleep/spin mutex.
38*199767f8SToomas Soome  *
39*199767f8SToomas Soome  * All mutex implementations must always have a member called mtx_lock.
40*199767f8SToomas Soome  * Other locking primitive structures are not allowed to use this name
41*199767f8SToomas Soome  * for their members.
42*199767f8SToomas Soome  * If this rule needs to change, the bits in the mutex implementation must
43*199767f8SToomas Soome  * be modified appropriately.
44*199767f8SToomas Soome  */
45*199767f8SToomas Soome struct mtx {
46*199767f8SToomas Soome 	struct lock_object	lock_object;	/* Common lock properties. */
47*199767f8SToomas Soome 	volatile uintptr_t	mtx_lock;	/* Owner and flags. */
48*199767f8SToomas Soome };
49*199767f8SToomas Soome 
50*199767f8SToomas Soome /*
51*199767f8SToomas Soome  * Members of struct mtx_padalign must mirror members of struct mtx.
52*199767f8SToomas Soome  * mtx_padalign mutexes can use the mtx(9) API transparently without
53*199767f8SToomas Soome  * modification.
54*199767f8SToomas Soome  * Pad-aligned mutexes used within structures should generally be the
55*199767f8SToomas Soome  * first member of the struct.  Otherwise, the compiler can generate
56*199767f8SToomas Soome  * additional padding for the struct to keep a correct alignment for
57*199767f8SToomas Soome  * the mutex.
58*199767f8SToomas Soome  */
59*199767f8SToomas Soome struct mtx_padalign {
60*199767f8SToomas Soome 	struct lock_object	lock_object;	/* Common lock properties. */
61*199767f8SToomas Soome 	volatile uintptr_t	mtx_lock;	/* Owner and flags. */
62*199767f8SToomas Soome } __aligned(CACHE_LINE_SIZE);
63*199767f8SToomas Soome 
64*199767f8SToomas Soome #endif /* !_SYS__MUTEX_H_ */
65