4 * Implements Inlines for LWKT messages and ports.
6 * $DragonFly: src/sys/sys/msgport2.h,v 1.11 2006/05/21 03:43:47 dillon Exp $
9 #ifndef _SYS_MSGPORT2_H_
10 #define _SYS_MSGPORT2_H_
14 #error "This file should not be included by userland programs."
18 #ifndef _SYS_THREAD2_H_
19 #include <sys/thread2.h>
22 #define lwkt_cmd_op_none lwkt_cmd_op(0)
24 typedef int (*lwkt_cmd_func_t)(lwkt_msg_t);
27 * Initialize a LWKT message structure. Note that if the message supports
28 * an abort MSGF_ABORTABLE must be passed in flags and an abort command
29 * supplied. If abort is not supported then lwkt_cmd_op_none is passed as
30 * the abort command argument by convention.
32 * Note that other areas of the LWKT msg may already be initialized, so we
33 * do not zero the message here.
37 lwkt_initmsg(lwkt_msg_t msg, lwkt_port_t rport, int flags,
38 lwkt_cmd_t cmd, lwkt_cmd_t abort)
40 msg->ms_cmd = cmd; /* opaque */
41 if (flags & MSGF_ABORTABLE) /* constant optimized conditional */
42 msg->ms_abort = abort; /* opaque */
43 msg->ms_flags = MSGF_DONE | flags;
44 msg->ms_reply_port = rport;
49 * These inlines convert specific types to the lwkt_cmd_t type. The compiler
50 * should be able to optimize this whole mess out.
64 lwkt_cmd_func(int (*func)(lwkt_msg_t))
74 lwkt_initmsg_simple(lwkt_msg_t msg, int op)
76 lwkt_initmsg(msg, &curthread->td_msgport, 0,
77 lwkt_cmd_op(op), lwkt_cmd_op(0));
82 lwkt_reinitmsg(lwkt_msg_t msg, lwkt_port_t rport)
84 msg->ms_flags = (msg->ms_flags & (MSGF_ASYNC | MSGF_ABORTABLE)) | MSGF_DONE;
85 msg->ms_reply_port = rport;
90 lwkt_beginmsg(lwkt_port_t port, lwkt_msg_t msg)
92 return(port->mp_putport(port, msg));
97 lwkt_waitmsg(lwkt_msg_t msg)
99 lwkt_port_t port = msg->ms_reply_port;
100 return(((lwkt_msg_t)port->mp_waitport(port, msg))->ms_error);
105 lwkt_replymsg(lwkt_msg_t msg, int error)
109 msg->ms_error = error;
110 port = msg->ms_reply_port;
111 port->mp_replyport(port, msg);
116 lwkt_waitport(lwkt_port_t port, lwkt_msg_t msg)
118 return(port->mp_waitport(port, msg));
123 lwkt_checkmsg(lwkt_msg_t msg)
125 return(msg->ms_flags & MSGF_DONE);
129 #endif /* _SYS_MSGPORT2_H_ */