1/*
2 * Copyright (c) 2021 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _KERN_LOCK_ATTR_H_
30#define _KERN_LOCK_ATTR_H_
31
32#include <kern/lock_types.h>
33
34__BEGIN_DECLS
35
36#ifdef XNU_KERNEL_PRIVATE
37typedef struct _lck_attr_ {
38 unsigned int lck_attr_val;
39} lck_attr_t;
40
41extern lck_attr_t lck_attr_default;
42
43#define LCK_ATTR_NONE 0
44#define LCK_ATTR_DEBUG 0x00000001
45#define LCK_ATTR_RW_SHARED_PRIORITY 0x00010000
46#else /* !XNU_KERNEL_PRIVATE */
47typedef struct __lck_attr__ lck_attr_t;
48#endif /* !XNU_KERNEL_PRIVATE */
49
50#define LCK_ATTR_NULL ((lck_attr_t *)NULL)
51
52extern lck_attr_t *lck_attr_alloc_init(void);
53
54extern void lck_attr_setdefault(
55 lck_attr_t *attr);
56
57extern void lck_attr_setdebug(
58 lck_attr_t *attr);
59
60extern void lck_attr_cleardebug(
61 lck_attr_t *attr);
62
63extern void lck_attr_free(
64 lck_attr_t *attr);
65
66#ifdef XNU_KERNEL_PRIVATE
67/*!
68 * @function lck_attr_rw_shared_priority
69 *
70 * @abstract
71 * Changes the rw lock behaviour by setting reader priority over writer.
72 *
73 * @discussion
74 * The attribute needs to be set before calling lck_rw_init().
75 * This attribute changes the locking behaviour by possibly starving the writers.
76 * Readers will always be able to lock the lock as long as a writer is not holding it.
77 * This attribute was added to allow recursive locking in shared mode.
78 *
79 * @param attr attr to modify
80 */
81extern void lck_attr_rw_shared_priority(
82 lck_attr_t *attr);
83#endif /* XNU_KERNEL_PRIVATE */
84
85__END_DECLS
86
87#endif /* _KERN_LOCK_ATTR_H_ */
88