176166Smarkm/*-
276166Smarkm * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
376166Smarkm *
476166Smarkm * Redistribution and use in source and binary forms, with or without
576166Smarkm * modification, are permitted provided that the following conditions
676166Smarkm * are met:
776166Smarkm * 1. Redistributions of source code must retain the above copyright
876166Smarkm *    notice, this list of conditions and the following disclaimer.
976166Smarkm * 2. Redistributions in binary form must reproduce the above copyright
1076166Smarkm *    notice, this list of conditions and the following disclaimer in the
1176166Smarkm *    documentation and/or other materials provided with the distribution.
1276166Smarkm * 3. Berkeley Software Design Inc's name may not be used to endorse or
1376166Smarkm *    promote products derived from this software without specific prior
1476166Smarkm *    written permission.
1576166Smarkm *
1676166Smarkm * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
1776166Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1876166Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1976166Smarkm * ARE DISCLAIMED.  IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
2076166Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2176166Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2276166Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2376166Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2476166Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2576166Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2676166Smarkm * SUCH DAMAGE.
2776166Smarkm *
2876166Smarkm * $FreeBSD$
2976166Smarkm */
3076166Smarkm
3198059Sbde#ifndef _SYS__MUTEX_H_
3298059Sbde#define	_SYS__MUTEX_H_
3376166Smarkm
34242395Sattilio#include <machine/param.h>
35242395Sattilio
3676166Smarkm/*
3798059Sbde * Sleep/spin mutex.
38242395Sattilio *
39242901Sattilio * All mutex implementations must always have a member called mtx_lock.
40242901Sattilio * Other locking primitive structures are not allowed to use this name
41242901Sattilio * for their members.
42242901Sattilio * If this rule needs to change, the bits in the mutex implementation must
43242901Sattilio * be modified appropriately.
4476166Smarkm */
4598059Sbdestruct mtx {
46167787Sjhb	struct lock_object	lock_object;	/* Common lock properties. */
4798059Sbde	volatile uintptr_t	mtx_lock;	/* Owner and flags. */
4876166Smarkm};
4976166Smarkm
50242395Sattilio/*
51242395Sattilio * Members of struct mtx_padalign must mirror members of struct mtx.
52242901Sattilio * mtx_padalign mutexes can use the mtx(9) API transparently without
53242901Sattilio * modification.
54242901Sattilio * Pad-aligned mutexes used within structures should generally be the
55242901Sattilio * first member of the struct.  Otherwise, the compiler can generate
56242901Sattilio * additional padding for the struct to keep a correct alignment for
57242901Sattilio * the mutex.
58242395Sattilio */
59242395Sattiliostruct mtx_padalign {
60242395Sattilio	struct lock_object	lock_object;	/* Common lock properties. */
61242395Sattilio	volatile uintptr_t	mtx_lock;	/* Owner and flags. */
62242395Sattilio} __aligned(CACHE_LINE_SIZE);
63242395Sattilio
6498059Sbde#endif /* !_SYS__MUTEX_H_ */
65