xref: /xnu-8796.101.5/osfmk/kern/smr_types.h (revision aca3beaa3dfbd42498b42c5e5ce20a938e6554e5)
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_SMR_TYPES_H_
30 #define _KERN_SMR_TYPES_H_
31 
32 #include <sys/cdefs.h>
33 #include <stdbool.h>
34 #include <stdint.h>
35 
36 __BEGIN_DECLS
37 
38 /*!
39  * @typedef smr_seq_t
40  *
41  * @brief
42  * Represents an opaque SMR sequence number.
43  */
44 typedef unsigned long           smr_seq_t;
45 
46 /*!
47  * @typedef smr_t
48  *
49  * @brief
50  * Type for an SMR domain.
51  */
52 typedef struct smr             *smr_t;
53 
54 
55 /*!
56  * @macro SMR_POINTER_DECL
57  *
58  * @brief
59  * Macro to declare a pointer type that uses SMR for access.
60  */
61 #define SMR_POINTER_DECL(name, type_t) \
62 	struct name { type_t volatile __smr_ptr; }
63 
64 /*!
65  * @macro SMR_POINTER
66  *
67  * @brief
68  * Macro to declare a pointer that uses SMR for access.
69  */
70 #define SMR_POINTER(type_t) \
71 	SMR_POINTER_DECL(, type_t)
72 
73 
74 /* internal types that clients should not use directly */
75 typedef SMR_POINTER(struct smrq_slink *) __smrq_slink_t;
76 typedef SMR_POINTER(struct smrq_link *)  __smrq_link_t;
77 
78 
79 /*!
80  * @struct smrq_slink
81  *
82  * @brief
83  * Type used to represent a linkage in an SMR queue
84  * (single form, with O(n) deletion).
85  */
86 struct smrq_slink {
87 	__smrq_slink_t          next;
88 };
89 
90 /*!
91  * @struct smrq_link
92  *
93  * @brief
94  * Type used to represent a linkage in an SMR queue
95  * (double form, with O(1) deletion).
96  */
97 struct smrq_link {
98 	__smrq_link_t           next;
99 	__smrq_link_t          *prev;
100 };
101 
102 
103 /*!
104  * @struct smrq_slist_head
105  *
106  * @brief
107  * Type used to represent the head of a singly linked list.
108  *
109  * @discussion
110  * This must be used with @c smrq_slink linkages.
111  *
112  * This type supports:
113  * - insertion at the head,
114  * - O(n) removal / replacement.
115  */
116 struct smrq_slist_head {
117 	__smrq_slink_t          first;
118 };
119 
120 #define SMRQ_SLIST_INITIALIZER(name) \
121 	{ .first = { NULL } }
122 
123 /*!
124  * @struct smrq_list_head
125  *
126  * @brief
127  * Type used to represent the head of a doubly linked list.
128  *
129  * @discussion
130  * This must be used with @c smrq_link linkages.
131  *
132  * This type supports:
133  * - insertion at the head,
134  * - O(1) removal / replacement.
135  */
136 struct smrq_list_head {
137 	__smrq_link_t           first;
138 };
139 
140 #define SMRQ_LIST_INITIALIZER(name) \
141 	{ .first = { NULL } }
142 
143 /*!
144  * @struct smrq_stailq_head
145  *
146  * @brief
147  * Type used to represent the head of a singly linked tail-queue.
148  *
149  * @discussion
150  * This must be used with @c smrq_slink linkages.
151  *
152  * This type supports:
153  * - insertion at the head,
154  * - insertion at the tail,
155  * - O(n) removal / replacement.
156  */
157 struct smrq_stailq_head {
158 	__smrq_slink_t          first;
159 	__smrq_slink_t         *last;
160 };
161 
162 #define SMRQ_STAILQ_INITIALIZER(name) \
163 	{ .first = { NULL }, .last = &(name).first }
164 
165 /*!
166  * @struct smrq_tailq_head
167  *
168  * @brief
169  * Type used to represent the head of a doubly linked tail-queue.
170  *
171  * @discussion
172  * This must be used with @c smrq_link linkages.
173  *
174  * This type supports:
175  * - insertion at the head,
176  * - insertion at the tail,
177  * - O(1) removal / replacement.
178  */
179 struct smrq_tailq_head {
180 	__smrq_link_t           first;
181 	__smrq_link_t          *last;
182 };
183 
184 #define SMRQ_TAILQ_INITIALIZER(name) \
185 	{ .first = { NULL }, .last = &(name).first }
186 
187 __END_DECLS
188 
189 #endif /* _KERN_SMR_TYPES_H_ */
190