1 /* 2 * Copyright 1991-1998 by Open Software Foundation, Inc. 3 * All Rights Reserved 4 * 5 * Permission to use, copy, modify, and distribute this software and 6 * its documentation for any purpose and without fee is hereby granted, 7 * provided that the above copyright notice appears in all copies and 8 * that both the copyright notice and this permission notice appear in 9 * supporting documentation. 10 * 11 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 12 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 * FOR A PARTICULAR PURPOSE. 14 * 15 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 16 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 17 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 18 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 19 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 */ 21 /* 22 * MkLinux 23 */ 24 /* CMU_HIST */ 25 /* 26 * Revision 2.6 91/08/28 11:13:37 jsb 27 * Added seqno argument to ipc_mqueue_receive. 28 * [91/08/10 rpd] 29 * 30 * Revision 2.5 91/05/14 16:34:12 mrt 31 * Correcting copyright 32 * 33 * Revision 2.4 91/02/05 17:22:29 mrt 34 * Changed to new Mach copyright 35 * [91/02/01 15:46:46 mrt] 36 * 37 * Revision 2.3 91/01/08 15:14:42 rpd 38 * Changed continuation argument and IMQ_NULL_CONTINUE to (void (*)()). 39 * [90/12/18 rpd] 40 * Reorganized ipc_mqueue_receive. 41 * [90/11/22 rpd] 42 * 43 * Revision 2.2 90/06/02 14:50:44 rpd 44 * Created for new IPC. 45 * [90/03/26 20:57:40 rpd] 46 * 47 */ 48 /* CMU_ENDHIST */ 49 /* 50 * Mach Operating System 51 * Copyright (c) 1991,1990,1989 Carnegie Mellon University 52 * All Rights Reserved. 53 * 54 * Permission to use, copy, modify and distribute this software and its 55 * documentation is hereby granted, provided that both the copyright 56 * notice and this permission notice appear in all copies of the 57 * software, derivative works or modified versions, and any portions 58 * thereof, and that both notices appear in supporting documentation. 59 * 60 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 61 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 62 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 63 * 64 * Carnegie Mellon requests users of this software to return to 65 * 66 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 67 * School of Computer Science 68 * Carnegie Mellon University 69 * Pittsburgh PA 15213-3890 70 * 71 * any improvements or extensions that they make and grant Carnegie Mellon 72 * the rights to redistribute these changes. 73 */ 74 /* 75 */ 76 /* 77 * File: ipc/ipc_mqueue.h 78 * Author: Rich Draves 79 * Date: 1989 80 * 81 * Definitions for message queues. 82 */ 83 84 #ifndef _IPC_IPC_MQUEUE_H_ 85 #define _IPC_IPC_MQUEUE_H_ 86 87 #include <sys/cdefs.h> 88 #include <sys/types.h> 89 #include <sys/event.h> 90 91 #include <sys/mach/mach_types.h> 92 #include <sys/mach/message.h> 93 94 #include <sys/mach/ipc/ipc_kmsg.h> 95 #include <sys/mach/ipc/ipc_thread.h> 96 #include <sys/mach/ipc/ipc_object.h> 97 #include <sys/mach/ipc/ipc_types.h> 98 #define TRACE_BUFFER 0 99 #define TR_DECL(x) 100 101 typedef struct ipc_mqueue { 102 struct ipc_kmsg_queue imq_messages; 103 } *ipc_mqueue_t; 104 105 struct ipc_pset; 106 107 #define IMQ_NULL ((ipc_mqueue_t) 0) 108 #if 0 109 #define imq_lock_init(mq) mach_mutex_init(&(mq)->imq_lock_data, \ 110 "ETAP_IPC_MQUEUE") 111 #define imq_lock(mq) mtx_lock(&(mq)->imq_lock_data) 112 #define imq_lock_try(mq) mtx_trylock(&(mq)->imq_lock_data) 113 #define imq_unlock(mq) mtx_unlock(&(mq)->imq_lock_data) 114 #define imq_lock_addr(mq) mtx_lock((mq)->imq_lock_data) 115 #endif 116 #define IMQ_NULL_CONTINUE ((void (*)(void)) 0) 117 118 /* 119 * Exported interfaces 120 */ 121 /* Initialize a newly-allocated message queue */ 122 extern void ipc_mqueue_init( 123 ipc_mqueue_t mqueue); 124 125 /* Move messages from one queue to another */ 126 extern void ipc_mqueue_move( 127 ipc_mqueue_t dest, 128 ipc_mqueue_t source, 129 ipc_port_t port); 130 131 /* Wake up receivers waiting in a message queue */ 132 extern void ipc_mqueue_changed( 133 ipc_mqueue_t mqueue, 134 mach_msg_return_t mr); 135 136 /* Send a message to a port */ 137 extern mach_msg_return_t ipc_mqueue_send( 138 ipc_kmsg_t kmsg, 139 mach_msg_option_t option, 140 mach_msg_timeout_t timeout); 141 142 /* Deliver message to message queue or waiting receiver */ 143 extern mach_msg_return_t ipc_mqueue_deliver( 144 ipc_port_t port, 145 ipc_kmsg_t kmsg, 146 boolean_t thread_context); 147 148 /* Convert a name in a space to a message queue */ 149 extern mach_msg_return_t ipc_mqueue_copyin( 150 ipc_space_t space, 151 mach_port_name_t name, 152 natural_t *bitsp, 153 ipc_object_t *objectp); 154 155 /* Receive a message from a message queue */ 156 extern mach_msg_return_t ipc_mqueue_receive( 157 natural_t bits, 158 mach_msg_option_t option, 159 mach_msg_size_t max_size, 160 mach_msg_timeout_t timeout, 161 ipc_kmsg_t *kmsgp, 162 mach_port_seqno_t *seqnop, 163 thread_t thread); 164 165 /* Receive a message from a message queue */ 166 extern mach_msg_return_t ipc_mqueue_pset_receive( 167 natural_t bits, 168 mach_msg_option_t option, 169 mach_msg_size_t max_size, 170 mach_msg_timeout_t timeout, 171 thread_t thread); 172 173 /* Second half of ipc_mqueue_receive */ 174 extern mach_msg_return_t ipc_mqueue_finish_receive( 175 ipc_kmsg_t *kmsgp, 176 ipc_port_t port, 177 mach_msg_option_t option, 178 mach_msg_size_t max_size); 179 180 /* 181 * extern void 182 * ipc_mqueue_send_always(ipc_kmsg_t); 183 * 184 * Unfortunately, to avoid warnings/lint about unused variables 185 * when assertions are turned off, we need two versions of this. 186 */ 187 188 #if MACH_ASSERT 189 190 #define ipc_mqueue_send_always(kmsg) \ 191 MACRO_BEGIN \ 192 mach_msg_return_t mr; \ 193 \ 194 mr = ipc_mqueue_send((kmsg), MACH_SEND_ALWAYS, \ 195 MACH_MSG_TIMEOUT_NONE); \ 196 assert(mr == MACH_MSG_SUCCESS); \ 197 MACRO_END 198 199 #else /* MACH_ASSERT */ 200 201 #define ipc_mqueue_send_always(kmsg) \ 202 MACRO_BEGIN \ 203 (void) ipc_mqueue_send((kmsg), MACH_SEND_ALWAYS, \ 204 MACH_MSG_TIMEOUT_NONE); \ 205 MACRO_END 206 207 #endif /* MACH_ASSERT */ 208 209 #endif /* _IPC_IPC_MQUEUE_H_ */ 210