1154956Sscottl/*-
2154956Sscottl * Copyright (c) 2006 John Baldwin <jhb@FreeBSD.org>
3154956Sscottl *
4154956Sscottl * Redistribution and use in source and binary forms, with or without
5154956Sscottl * modification, are permitted provided that the following conditions
6154956Sscottl * are met:
7154956Sscottl * 1. Redistributions of source code must retain the above copyright
8154956Sscottl *    notice, this list of conditions and the following disclaimer.
9154956Sscottl * 2. Redistributions in binary form must reproduce the above copyright
10154956Sscottl *    notice, this list of conditions and the following disclaimer in the
11154956Sscottl *    documentation and/or other materials provided with the distribution.
12154956Sscottl *
13155121Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14154956Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15154956Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16155121Sjhb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17154956Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18154956Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19154956Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20154956Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21154956Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22154956Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23154956Sscottl * SUCH DAMAGE.
24154956Sscottl *
25154956Sscottl * $FreeBSD: stable/11/sys/sys/_rwlock.h 367457 2020-11-07 18:10:59Z dim $
26154956Sscottl */
27154956Sscottl
28154956Sscottl#ifndef _SYS__RWLOCK_H_
29154956Sscottl#define	_SYS__RWLOCK_H_
30154956Sscottl
31242515Sattilio#include <machine/param.h>
32242515Sattilio
33154956Sscottl/*
34155121Sjhb * Reader/writer lock.
35242515Sattilio *
36242901Sattilio * All reader/writer lock implementations must always have a member
37242901Sattilio * called rw_lock.  Other locking primitive structures are not allowed to
38242901Sattilio * use this name for their members.
39242901Sattilio * If this rule needs to change, the bits in the reader/writer lock
40242901Sattilio * implementation must be modified appropriately.
41154956Sscottl */
42154956Sscottlstruct rwlock {
43167787Sjhb	struct lock_object	lock_object;
44154956Sscottl	volatile uintptr_t	rw_lock;
45154956Sscottl};
46154956Sscottl
47242515Sattilio/*
48242515Sattilio * Members of struct rwlock_padalign must mirror members of struct rwlock.
49242901Sattilio * rwlock_padalign rwlocks can use the rwlock(9) API transparently without
50242901Sattilio * modification.
51242901Sattilio * Pad-aligned rwlocks used within structures should generally be the
52242901Sattilio * first member of the struct.  Otherwise, the compiler can generate
53242901Sattilio * additional padding for the struct to keep a correct alignment for
54242901Sattilio * the rwlock.
55242515Sattilio */
56242515Sattiliostruct rwlock_padalign {
57242515Sattilio	struct lock_object	lock_object;
58242515Sattilio	volatile uintptr_t	rw_lock;
59242515Sattilio} __aligned(CACHE_LINE_SIZE);
60242515Sattilio
61154956Sscottl#endif /* !_SYS__RWLOCK_H_ */
62