2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
61 * File: ipc/ipc_mqueue.h
65 * Definitions for message queues.
68 #ifndef _IPC_IPC_MQUEUE_H_
69 #define _IPC_IPC_MQUEUE_H_
71 #include <mach_assert.h>
73 #include <mach/message.h>
75 #include <kern/assert.h>
76 #include <kern/macro_help.h>
77 #include <kern/kern_types.h>
78 #include <kern/wait_queue.h>
80 #include <ipc/ipc_kmsg.h>
81 #include <ipc/ipc_object.h>
82 #include <ipc/ipc_types.h>
84 typedef struct ipc_mqueue
{
87 struct wait_queue wait_queue
;
88 struct ipc_kmsg_queue messages
;
89 mach_port_msgcount_t msgcount
;
90 mach_port_msgcount_t qlimit
;
91 mach_port_seqno_t seqno
;
92 boolean_t fullwaiters
;
94 struct wait_queue_set set_queue
;
98 #define IMQ_NULL ((ipc_mqueue_t) 0)
100 #define imq_wait_queue data.port.wait_queue
101 #define imq_messages data.port.messages
102 #define imq_msgcount data.port.msgcount
103 #define imq_qlimit data.port.qlimit
104 #define imq_seqno data.port.seqno
105 #define imq_fullwaiters data.port.fullwaiters
107 #define imq_set_queue data.set_queue
108 #define imq_setlinks data.set_queue.wqs_setlinks
109 #define imq_is_set(mq) wait_queue_is_set(&(mq)->imq_set_queue)
111 #define imq_lock(mq) wait_queue_lock(&(mq)->imq_wait_queue)
112 #define imq_lock_try(mq) wait_queue_lock_try(&(mq)->imq_wait_queue)
113 #define imq_unlock(mq) wait_queue_unlock(&(mq)->imq_wait_queue)
114 #define imq_held(mq) wait_queue_held(&(mq)->imq_wait_queue)
116 #define imq_full(mq) ((mq)->imq_msgcount >= (mq)->imq_qlimit)
118 extern int ipc_mqueue_full
;
119 extern int ipc_mqueue_rcv
;
121 #define IPC_MQUEUE_FULL (event64_t)&ipc_mqueue_full
122 #define IPC_MQUEUE_RECEIVE (event64_t)&ipc_mqueue_rcv
125 * Exported interfaces
128 /* Initialize a newly-allocated message queue */
129 extern void ipc_mqueue_init(
133 /* destroy an mqueue */
134 extern void ipc_mqueue_destroy(
135 ipc_mqueue_t mqueue
);
137 /* Wake up receivers waiting in a message queue */
138 extern void ipc_mqueue_changed(
139 ipc_mqueue_t mqueue
);
141 /* Add the specific mqueue as a member of the set */
142 extern kern_return_t
ipc_mqueue_add(
144 ipc_mqueue_t set_mqueue
);
146 /* Check to see if mqueue is member of set_mqueue */
147 extern boolean_t
ipc_mqueue_member(
149 ipc_mqueue_t set_mqueue
);
151 /* Remove an mqueue from a specific set */
152 extern kern_return_t
ipc_mqueue_remove(
154 ipc_mqueue_t set_mqueue
);
156 /* Remove an mqueue from all sets */
157 extern void ipc_mqueue_remove_from_all(
158 ipc_mqueue_t mqueue
);
160 /* Remove all the members of the specifiied set */
161 extern void ipc_mqueue_remove_all(
162 ipc_mqueue_t mqueue
);
164 /* Send a message to a port */
165 extern mach_msg_return_t
ipc_mqueue_send(
168 mach_msg_option_t option
,
169 mach_msg_timeout_t timeout_val
);
171 /* Deliver message to message queue or waiting receiver */
172 extern void ipc_mqueue_post(
176 /* Receive a message from a message queue */
177 extern void ipc_mqueue_receive(
179 mach_msg_option_t option
,
180 mach_msg_size_t max_size
,
181 mach_msg_timeout_t timeout_val
,
184 /* Continuation routine for message receive */
185 extern void ipc_mqueue_receive_continue(
187 wait_result_t wresult
);
189 /* Select a message from a queue and try to post it to ourself */
190 extern void ipc_mqueue_select(
192 mach_msg_option_t option
,
193 mach_msg_size_t max_size
);
195 /* Clear a message count reservation */
196 extern void ipc_mqueue_release_msgcount(
197 ipc_mqueue_t mqueue
);
199 /* Change a queue limit */
200 extern void ipc_mqueue_set_qlimit(
202 mach_port_msgcount_t qlimit
);
204 /* Change a queue's sequence number */
205 extern void ipc_mqueue_set_seqno(
207 mach_port_seqno_t seqno
);
209 /* Convert a name in a space to a message queue */
210 extern mach_msg_return_t
ipc_mqueue_copyin(
212 mach_port_name_t name
,
213 ipc_mqueue_t
*mqueuep
,
214 ipc_object_t
*objectp
);
216 #endif /* _IPC_IPC_MQUEUE_H_ */