2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
56 * File: ipc/ipc_mqueue.h
60 * Definitions for message queues.
63 #ifndef _IPC_IPC_MQUEUE_H_
64 #define _IPC_IPC_MQUEUE_H_
66 #include <mach_assert.h>
68 #include <mach/message.h>
70 #include <kern/assert.h>
71 #include <kern/macro_help.h>
72 #include <kern/wait_queue.h>
74 #include <ipc/ipc_kmsg.h>
75 #include <ipc/ipc_object.h>
76 #include <ipc/ipc_types.h>
78 typedef struct ipc_mqueue
{
81 struct wait_queue wait_queue
;
82 struct ipc_kmsg_queue messages
;
83 mach_port_msgcount_t msgcount
;
84 mach_port_msgcount_t qlimit
;
85 mach_port_seqno_t seqno
;
86 boolean_t fullwaiters
;
88 struct wait_queue_set set_queue
;
92 #define IMQ_NULL ((ipc_mqueue_t) 0)
94 #define imq_wait_queue data.port.wait_queue
95 #define imq_messages data.port.messages
96 #define imq_msgcount data.port.msgcount
97 #define imq_qlimit data.port.qlimit
98 #define imq_seqno data.port.seqno
99 #define imq_fullwaiters data.port.fullwaiters
101 #define imq_set_queue data.set_queue
102 #define imq_setlinks data.set_queue.wqs_setlinks
103 #define imq_is_set(mq) wait_queue_is_set(&(mq)->imq_set_queue)
105 #define imq_lock(mq) wait_queue_lock(&(mq)->imq_wait_queue)
106 #define imq_lock_try(mq) wait_queue_lock_try(&(mq)->imq_wait_queue)
107 #define imq_unlock(mq) wait_queue_unlock(&(mq)->imq_wait_queue)
108 #define imq_held(mq) wait_queue_held(&(mq)->imq_wait_queue)
110 #define imq_full(mq) ((mq)->imq_msgcount >= (mq)->imq_qlimit)
112 extern int ipc_mqueue_full
;
113 extern int ipc_mqueue_rcv
;
115 #define IPC_MQUEUE_FULL (event64_t)&ipc_mqueue_full
116 #define IPC_MQUEUE_RECEIVE (event64_t)&ipc_mqueue_rcv
119 * Exported interfaces
122 /* Initialize a newly-allocated message queue */
123 extern void ipc_mqueue_init(
127 /* Wake up receivers waiting in a message queue */
128 extern void ipc_mqueue_changed(
129 ipc_mqueue_t mqueue
);
131 /* Send a message to a port */
132 extern mach_msg_return_t
ipc_mqueue_send(
135 mach_msg_option_t option
,
136 mach_msg_timeout_t timeout
);
138 /* Deliver message to message queue or waiting receiver */
139 extern void ipc_mqueue_post(
143 /* Receive a message from a message queue */
144 extern void ipc_mqueue_receive(
146 mach_msg_option_t option
,
147 mach_msg_size_t max_size
,
148 mach_msg_timeout_t timeout
,
151 /* Continuation routine for message receive */
152 extern void ipc_mqueue_receive_continue(void);
154 /* Select a message from a queue and try to post it to ourself */
155 extern void ipc_mqueue_select(
157 mach_msg_option_t option
,
158 mach_msg_size_t max_size
);
160 /* Clear a message count reservation */
161 extern void ipc_mqueue_release_msgcount(
162 ipc_mqueue_t mqueue
);
164 /* Change a queue limit */
165 extern void ipc_mqueue_set_qlimit(
167 mach_port_msgcount_t qlimit
);
169 /* Change a queue's sequence number */
170 extern void ipc_mqueue_set_seqno(
172 mach_port_seqno_t seqno
);
174 /* Convert a name in a space to a message queue */
175 extern mach_msg_return_t
ipc_mqueue_copyin(
177 mach_port_name_t name
,
178 ipc_mqueue_t
*mqueuep
,
179 ipc_object_t
*objectp
);
181 #endif /* _IPC_IPC_MQUEUE_H_ */