]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/ipc_mqueue.h
xnu-344.21.74.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_mqueue.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
32 *
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.
38 *
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.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53 /*
54 */
55 /*
56 * File: ipc/ipc_mqueue.h
57 * Author: Rich Draves
58 * Date: 1989
59 *
60 * Definitions for message queues.
61 */
62
63 #ifndef _IPC_IPC_MQUEUE_H_
64 #define _IPC_IPC_MQUEUE_H_
65
66 #include <mach_assert.h>
67
68 #include <mach/message.h>
69
70 #include <kern/assert.h>
71 #include <kern/macro_help.h>
72 #include <kern/wait_queue.h>
73
74 #include <ipc/ipc_kmsg.h>
75 #include <ipc/ipc_object.h>
76 #include <ipc/ipc_types.h>
77
78 typedef struct ipc_mqueue {
79 union {
80 struct {
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;
87 } port;
88 struct wait_queue_set set_queue;
89 } data;
90 } *ipc_mqueue_t;
91
92 #define IMQ_NULL ((ipc_mqueue_t) 0)
93
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
100
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)
104
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)
109
110 #define imq_full(mq) ((mq)->imq_msgcount >= (mq)->imq_qlimit)
111
112 extern int ipc_mqueue_full;
113 extern int ipc_mqueue_rcv;
114
115 #define IPC_MQUEUE_FULL (event64_t)&ipc_mqueue_full
116 #define IPC_MQUEUE_RECEIVE (event64_t)&ipc_mqueue_rcv
117
118 /*
119 * Exported interfaces
120 */
121
122 /* Initialize a newly-allocated message queue */
123 extern void ipc_mqueue_init(
124 ipc_mqueue_t mqueue,
125 boolean_t is_set);
126
127 /* Wake up receivers waiting in a message queue */
128 extern void ipc_mqueue_changed(
129 ipc_mqueue_t mqueue);
130
131 /* Send a message to a port */
132 extern mach_msg_return_t ipc_mqueue_send(
133 ipc_mqueue_t mqueue,
134 ipc_kmsg_t kmsg,
135 mach_msg_option_t option,
136 mach_msg_timeout_t timeout);
137
138 /* Deliver message to message queue or waiting receiver */
139 extern void ipc_mqueue_post(
140 ipc_mqueue_t mqueue,
141 ipc_kmsg_t kmsg);
142
143 /* Receive a message from a message queue */
144 extern void ipc_mqueue_receive(
145 ipc_mqueue_t mqueue,
146 mach_msg_option_t option,
147 mach_msg_size_t max_size,
148 mach_msg_timeout_t timeout,
149 int interruptible);
150
151 /* Continuation routine for message receive */
152 extern void ipc_mqueue_receive_continue(void);
153
154 /* Select a message from a queue and try to post it to ourself */
155 extern void ipc_mqueue_select(
156 ipc_mqueue_t mqueue,
157 mach_msg_option_t option,
158 mach_msg_size_t max_size);
159
160 /* Clear a message count reservation */
161 extern void ipc_mqueue_release_msgcount(
162 ipc_mqueue_t mqueue);
163
164 /* Change a queue limit */
165 extern void ipc_mqueue_set_qlimit(
166 ipc_mqueue_t mqueue,
167 mach_port_msgcount_t qlimit);
168
169 /* Change a queue's sequence number */
170 extern void ipc_mqueue_set_seqno(
171 ipc_mqueue_t mqueue,
172 mach_port_seqno_t seqno);
173
174 /* Convert a name in a space to a message queue */
175 extern mach_msg_return_t ipc_mqueue_copyin(
176 ipc_space_t space,
177 mach_port_name_t name,
178 ipc_mqueue_t *mqueuep,
179 ipc_object_t *objectp);
180
181 #endif /* _IPC_IPC_MQUEUE_H_ */