_mutex.h revision 242395
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: head/sys/sys/_mutex.h 242395 2012-10-31 13:38:56Z attilio $ 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 * 39242395Sattilio * The layout of the first 2 members of struct mtx* is considered fixed. 40242395Sattilio * More specifically, it is assumed that there is a member called mtx_lock 41242395Sattilio * for every struct mtx* and that other locking primitive structures are 42242395Sattilio * not allowed to use such name for their members. 43242395Sattilio * If this needs to change, the bits in the mutex implementation might be 44242395Sattilio * modified appropriately. 4576166Smarkm */ 4698059Sbdestruct mtx { 47167787Sjhb struct lock_object lock_object; /* Common lock properties. */ 4898059Sbde volatile uintptr_t mtx_lock; /* Owner and flags. */ 4976166Smarkm}; 5076166Smarkm 51242395Sattilio/* 52242395Sattilio * Members of struct mtx_padalign must mirror members of struct mtx. 53242395Sattilio * mtx_padalign mutexes can use mtx(9) KPI transparently, without modifies. 54242395Sattilio * When using pad-aligned mutexes within structures, they should generally 55242395Sattilio * stay as the first member of the struct. This is because otherwise the 56242395Sattilio * compiler can generate ever more padding for the struct to keep a correct 57242395Sattilio * alignment for 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