Change sendfile() to use the new m_ext callback scheme for cleaning up after
[dragonfly.git] / sys / sys / msgport2.h
CommitLineData
ece04fd0
MD
1/*
2 * SYS/MSGPORT2.H
3 *
4 * Implements Inlines for LWKT messages and ports.
5 *
1fa2b4b4 6 * $DragonFly: src/sys/sys/msgport2.h,v 1.10 2004/06/04 20:35:39 dillon Exp $
ece04fd0
MD
7 */
8
9#ifndef _SYS_MSGPORT2_H_
10#define _SYS_MSGPORT2_H_
11
e7906ee5
MD
12#ifndef _SYS_THREAD2_H_
13#include <sys/thread2.h>
14#endif
15
b44419cb
MD
16#define lwkt_cmd_op_none lwkt_cmd_op(0)
17
18typedef int (*lwkt_cmd_func_t)(lwkt_msg_t);
19
20/*
21 * Initialize a LWKT message structure. Note that if the message supports
22 * an abort MSGF_ABORTABLE must be passed in flags and an abort command
23 * supplied. If abort is not supported then lwkt_cmd_op_none is passed as
24 * the abort command argument by convention.
1fa2b4b4
MD
25 *
26 * Note that other areas of the LWKT msg may already be initialized, so we
27 * do not zero the message here.
b44419cb 28 */
335dda38
MD
29static __inline
30void
b44419cb
MD
31lwkt_initmsg(lwkt_msg_t msg, lwkt_port_t rport, int flags,
32 lwkt_cmd_t cmd, lwkt_cmd_t abort)
3227f1b8 33{
b44419cb
MD
34 msg->ms_cmd = cmd; /* opaque */
35 if (flags & MSGF_ABORTABLE) /* constant optimized conditional */
36 msg->ms_abort = abort; /* opaque */
37 msg->ms_flags = MSGF_DONE | flags;
38 msg->ms_reply_port = rport;
3227f1b8
MD
39 msg->ms_msgsize = 0;
40}
41
b44419cb
MD
42/*
43 * These inlines convert specific types to the lwkt_cmd_t type. The compiler
44 * should be able to optimize this whole mess out.
45 */
46static __inline
47lwkt_cmd_t
48lwkt_cmd_op(int op)
49{
50 lwkt_cmd_t cmd;
51
52 cmd.cm_op = op;
53 return(cmd);
54}
55
56static __inline
57lwkt_cmd_t
58lwkt_cmd_func(int (*func)(lwkt_msg_t))
59{
60 lwkt_cmd_t cmd;
61
62 cmd.cm_func = func;
63 return(cmd);
64}
65
3227f1b8
MD
66static __inline
67void
b44419cb 68lwkt_initmsg_simple(lwkt_msg_t msg, int op)
335dda38 69{
b44419cb
MD
70 lwkt_initmsg(msg, &curthread->td_msgport, 0,
71 lwkt_cmd_op(op), lwkt_cmd_op(0));
245e4f17
MD
72}
73
74static __inline
75void
76lwkt_reinitmsg(lwkt_msg_t msg, lwkt_port_t rport)
77{
b44419cb 78 msg->ms_flags = (msg->ms_flags & (MSGF_ASYNC | MSGF_ABORTABLE)) | MSGF_DONE;
245e4f17 79 msg->ms_reply_port = rport;
335dda38
MD
80}
81
ece04fd0
MD
82static __inline
83int
84lwkt_beginmsg(lwkt_port_t port, lwkt_msg_t msg)
85{
df2244e3 86 return(port->mp_putport(port, msg));
ece04fd0
MD
87}
88
df2244e3
MD
89static __inline
90int
91lwkt_waitmsg(lwkt_msg_t msg)
92{
93 lwkt_port_t port = msg->ms_reply_port;
94 return(((lwkt_msg_t)port->mp_waitport(port, msg))->ms_error);
ece04fd0
MD
95}
96
ece04fd0
MD
97static __inline
98void
99lwkt_replymsg(lwkt_msg_t msg, int error)
e7906ee5 100{
b44419cb 101 lwkt_port_t port;
e7906ee5 102
ece04fd0 103 msg->ms_error = error;
b44419cb 104 port = msg->ms_reply_port;
df2244e3 105 port->mp_replyport(port, msg);
ece04fd0
MD
106}
107
c95cd171
MD
108static __inline
109void *
110lwkt_waitport(lwkt_port_t port, lwkt_msg_t msg)
111{
112 return(port->mp_waitport(port, msg));
113}
114
1fa2b4b4
MD
115static __inline
116int
117lwkt_checkmsg(lwkt_msg_t msg)
118{
119 return(msg->ms_flags & MSGF_DONE);
120}
121
ece04fd0
MD
122#endif
123