]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
36 | * Permission to use, copy, modify and distribute this software and its | |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
41 | * | |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | /* | |
57 | */ | |
58 | /* | |
59 | * File: ipc/ipc_mqueue.h | |
60 | * Author: Rich Draves | |
61 | * Date: 1989 | |
62 | * | |
63 | * Definitions for message queues. | |
64 | */ | |
65 | ||
66 | #ifndef _IPC_IPC_MQUEUE_H_ | |
67 | #define _IPC_IPC_MQUEUE_H_ | |
68 | ||
69 | #include <mach_assert.h> | |
70 | ||
71 | #include <mach/message.h> | |
72 | ||
73 | #include <kern/assert.h> | |
74 | #include <kern/macro_help.h> | |
91447636 | 75 | #include <kern/kern_types.h> |
b0d623f7 | 76 | #include <kern/spl.h> |
1c79356b A |
77 | #include <kern/wait_queue.h> |
78 | ||
79 | #include <ipc/ipc_kmsg.h> | |
80 | #include <ipc/ipc_object.h> | |
81 | #include <ipc/ipc_types.h> | |
82 | ||
b0d623f7 A |
83 | #include <sys/event.h> |
84 | ||
1c79356b A |
85 | typedef struct ipc_mqueue { |
86 | union { | |
87 | struct { | |
88 | struct wait_queue wait_queue; | |
89 | struct ipc_kmsg_queue messages; | |
90 | mach_port_msgcount_t msgcount; | |
91 | mach_port_msgcount_t qlimit; | |
b0d623f7 A |
92 | mach_port_seqno_t seqno; |
93 | mach_port_name_t receiver_name; | |
1c79356b | 94 | boolean_t fullwaiters; |
39236c6e | 95 | natural_t pset_count; |
1c79356b | 96 | } port; |
b0d623f7 A |
97 | struct { |
98 | struct wait_queue_set set_queue; | |
99 | mach_port_name_t local_name; | |
100 | } pset; | |
1c79356b A |
101 | } data; |
102 | } *ipc_mqueue_t; | |
103 | ||
104 | #define IMQ_NULL ((ipc_mqueue_t) 0) | |
105 | ||
106 | #define imq_wait_queue data.port.wait_queue | |
107 | #define imq_messages data.port.messages | |
108 | #define imq_msgcount data.port.msgcount | |
109 | #define imq_qlimit data.port.qlimit | |
110 | #define imq_seqno data.port.seqno | |
b0d623f7 | 111 | #define imq_receiver_name data.port.receiver_name |
1c79356b | 112 | #define imq_fullwaiters data.port.fullwaiters |
39236c6e | 113 | #define imq_pset_count data.port.pset_count |
1c79356b | 114 | |
b0d623f7 A |
115 | #define imq_set_queue data.pset.set_queue |
116 | #define imq_setlinks data.pset.set_queue.wqs_setlinks | |
117 | #define imq_preposts data.pset.set_queue.wqs_preposts | |
118 | #define imq_local_name data.pset.local_name | |
9bccf70c | 119 | #define imq_is_set(mq) wait_queue_is_set(&(mq)->imq_set_queue) |
1c79356b A |
120 | |
121 | #define imq_lock(mq) wait_queue_lock(&(mq)->imq_wait_queue) | |
122 | #define imq_lock_try(mq) wait_queue_lock_try(&(mq)->imq_wait_queue) | |
123 | #define imq_unlock(mq) wait_queue_unlock(&(mq)->imq_wait_queue) | |
124 | #define imq_held(mq) wait_queue_held(&(mq)->imq_wait_queue) | |
125 | ||
126 | #define imq_full(mq) ((mq)->imq_msgcount >= (mq)->imq_qlimit) | |
c910b4d9 | 127 | #define imq_full_kernel(mq) ((mq)->imq_msgcount >= MACH_PORT_QLIMIT_KERNEL) |
1c79356b A |
128 | |
129 | extern int ipc_mqueue_full; | |
b0d623f7 | 130 | // extern int ipc_mqueue_rcv; |
1c79356b | 131 | |
cf7d32b8 | 132 | #define IPC_MQUEUE_FULL CAST_EVENT64_T(&ipc_mqueue_full) |
b0d623f7 | 133 | #define IPC_MQUEUE_RECEIVE NO_EVENT64 |
1c79356b A |
134 | |
135 | /* | |
136 | * Exported interfaces | |
137 | */ | |
138 | ||
139 | /* Initialize a newly-allocated message queue */ | |
140 | extern void ipc_mqueue_init( | |
91447636 A |
141 | ipc_mqueue_t mqueue, |
142 | boolean_t is_set); | |
143 | ||
144 | /* destroy an mqueue */ | |
145 | extern void ipc_mqueue_destroy( | |
146 | ipc_mqueue_t mqueue); | |
1c79356b | 147 | |
1c79356b A |
148 | /* Wake up receivers waiting in a message queue */ |
149 | extern void ipc_mqueue_changed( | |
150 | ipc_mqueue_t mqueue); | |
151 | ||
91447636 A |
152 | /* Add the specific mqueue as a member of the set */ |
153 | extern kern_return_t ipc_mqueue_add( | |
154 | ipc_mqueue_t mqueue, | |
316670eb A |
155 | ipc_mqueue_t set_mqueue, |
156 | wait_queue_link_t wql); | |
91447636 A |
157 | |
158 | /* Check to see if mqueue is member of set_mqueue */ | |
159 | extern boolean_t ipc_mqueue_member( | |
160 | ipc_mqueue_t mqueue, | |
161 | ipc_mqueue_t set_mqueue); | |
162 | ||
163 | /* Remove an mqueue from a specific set */ | |
164 | extern kern_return_t ipc_mqueue_remove( | |
165 | ipc_mqueue_t mqueue, | |
316670eb A |
166 | ipc_mqueue_t set_mqueue, |
167 | wait_queue_link_t *wqlp); | |
91447636 A |
168 | |
169 | /* Remove an mqueue from all sets */ | |
170 | extern void ipc_mqueue_remove_from_all( | |
316670eb A |
171 | ipc_mqueue_t mqueue, |
172 | queue_t links); | |
91447636 A |
173 | |
174 | /* Remove all the members of the specifiied set */ | |
175 | extern void ipc_mqueue_remove_all( | |
316670eb A |
176 | ipc_mqueue_t mqueue, |
177 | queue_t links); | |
91447636 | 178 | |
1c79356b A |
179 | /* Send a message to a port */ |
180 | extern mach_msg_return_t ipc_mqueue_send( | |
181 | ipc_mqueue_t mqueue, | |
182 | ipc_kmsg_t kmsg, | |
183 | mach_msg_option_t option, | |
b0d623f7 A |
184 | mach_msg_timeout_t timeout_val, |
185 | spl_t s); | |
1c79356b | 186 | |
39236c6e A |
187 | /* check for queue send queue full of a port */ |
188 | extern mach_msg_return_t ipc_mqueue_preflight_send( | |
189 | ipc_mqueue_t mqueue, | |
190 | ipc_kmsg_t kmsg, | |
191 | mach_msg_option_t option, | |
192 | mach_msg_timeout_t timeout_val); | |
193 | ||
1c79356b A |
194 | /* Deliver message to message queue or waiting receiver */ |
195 | extern void ipc_mqueue_post( | |
196 | ipc_mqueue_t mqueue, | |
197 | ipc_kmsg_t kmsg); | |
198 | ||
199 | /* Receive a message from a message queue */ | |
200 | extern void ipc_mqueue_receive( | |
201 | ipc_mqueue_t mqueue, | |
202 | mach_msg_option_t option, | |
203 | mach_msg_size_t max_size, | |
91447636 | 204 | mach_msg_timeout_t timeout_val, |
1c79356b A |
205 | int interruptible); |
206 | ||
b0d623f7 A |
207 | /* Receive a message from a message queue using a specified thread */ |
208 | extern wait_result_t ipc_mqueue_receive_on_thread( | |
209 | ipc_mqueue_t mqueue, | |
210 | mach_msg_option_t option, | |
211 | mach_msg_size_t max_size, | |
212 | mach_msg_timeout_t rcv_timeout, | |
213 | int interruptible, | |
214 | thread_t thread); | |
215 | ||
1c79356b | 216 | /* Continuation routine for message receive */ |
91447636 A |
217 | extern void ipc_mqueue_receive_continue( |
218 | void *param, | |
219 | wait_result_t wresult); | |
1c79356b A |
220 | |
221 | /* Select a message from a queue and try to post it to ourself */ | |
b0d623f7 | 222 | extern void ipc_mqueue_select_on_thread( |
1c79356b A |
223 | ipc_mqueue_t mqueue, |
224 | mach_msg_option_t option, | |
b0d623f7 A |
225 | mach_msg_size_t max_size, |
226 | thread_t thread); | |
227 | ||
228 | /* Peek into a messaqe queue to see if there are messages */ | |
6d2010ae | 229 | extern unsigned ipc_mqueue_peek( |
39236c6e A |
230 | ipc_mqueue_t mqueue, |
231 | mach_port_seqno_t *msg_seqnop, | |
232 | mach_msg_size_t *msg_sizep, | |
233 | mach_msg_id_t *msg_idp, | |
234 | mach_msg_max_trailer_t *msg_trailerp); | |
235 | ||
236 | /* Peek into a messaqe queue set to see if there are queues with messages */ | |
237 | extern unsigned ipc_mqueue_set_peek( | |
b0d623f7 | 238 | ipc_mqueue_t mqueue); |
1c79356b | 239 | |
39236c6e A |
240 | /* Gather the names of member port for a given set */ |
241 | extern void ipc_mqueue_set_gather_member_names( | |
242 | ipc_mqueue_t mqueue, | |
243 | ipc_entry_num_t maxnames, | |
244 | mach_port_name_t *names, | |
245 | ipc_entry_num_t *actualp); | |
246 | ||
1c79356b A |
247 | /* Clear a message count reservation */ |
248 | extern void ipc_mqueue_release_msgcount( | |
249 | ipc_mqueue_t mqueue); | |
250 | ||
251 | /* Change a queue limit */ | |
252 | extern void ipc_mqueue_set_qlimit( | |
253 | ipc_mqueue_t mqueue, | |
254 | mach_port_msgcount_t qlimit); | |
255 | ||
256 | /* Change a queue's sequence number */ | |
257 | extern void ipc_mqueue_set_seqno( | |
258 | ipc_mqueue_t mqueue, | |
259 | mach_port_seqno_t seqno); | |
260 | ||
261 | /* Convert a name in a space to a message queue */ | |
262 | extern mach_msg_return_t ipc_mqueue_copyin( | |
263 | ipc_space_t space, | |
264 | mach_port_name_t name, | |
265 | ipc_mqueue_t *mqueuep, | |
266 | ipc_object_t *objectp); | |
267 | ||
268 | #endif /* _IPC_IPC_MQUEUE_H_ */ |