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