Clean up more #include files. Create an internal __boolean_t so two or
[dragonfly.git] / sys / sys / msgport2.h
CommitLineData
ece04fd0
MD
1/*
2 * SYS/MSGPORT2.H
3 *
4 * Implements Inlines for LWKT messages and ports.
5 *
03d6a592 6 * $DragonFly: src/sys/sys/msgport2.h,v 1.11 2006/05/21 03:43:47 dillon Exp $
ece04fd0
MD
7 */
8
9#ifndef _SYS_MSGPORT2_H_
10#define _SYS_MSGPORT2_H_
11
03d6a592
MD
12#ifndef _KERNEL
13
14#error "This file should not be included by userland programs."
15
16#else
17
e7906ee5
MD
18#ifndef _SYS_THREAD2_H_
19#include <sys/thread2.h>
20#endif
21
b44419cb
MD
22#define lwkt_cmd_op_none lwkt_cmd_op(0)
23
24typedef int (*lwkt_cmd_func_t)(lwkt_msg_t);
25
26/*
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.
1fa2b4b4
MD
31 *
32 * Note that other areas of the LWKT msg may already be initialized, so we
33 * do not zero the message here.
b44419cb 34 */
335dda38
MD
35static __inline
36void
b44419cb
MD
37lwkt_initmsg(lwkt_msg_t msg, lwkt_port_t rport, int flags,
38 lwkt_cmd_t cmd, lwkt_cmd_t abort)
3227f1b8 39{
b44419cb
MD
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;
3227f1b8
MD
45 msg->ms_msgsize = 0;
46}
47
b44419cb
MD
48/*
49 * These inlines convert specific types to the lwkt_cmd_t type. The compiler
50 * should be able to optimize this whole mess out.
51 */
52static __inline
53lwkt_cmd_t
54lwkt_cmd_op(int op)
55{
56 lwkt_cmd_t cmd;
57
58 cmd.cm_op = op;
59 return(cmd);
60}
61
62static __inline
63lwkt_cmd_t
64lwkt_cmd_func(int (*func)(lwkt_msg_t))
65{
66 lwkt_cmd_t cmd;
67
68 cmd.cm_func = func;
69 return(cmd);
70}
71
3227f1b8
MD
72static __inline
73void
b44419cb 74lwkt_initmsg_simple(lwkt_msg_t msg, int op)
335dda38 75{
b44419cb
MD
76 lwkt_initmsg(msg, &curthread->td_msgport, 0,
77 lwkt_cmd_op(op), lwkt_cmd_op(0));
245e4f17
MD
78}
79
80static __inline
81void
82lwkt_reinitmsg(lwkt_msg_t msg, lwkt_port_t rport)
83{
b44419cb 84 msg->ms_flags = (msg->ms_flags & (MSGF_ASYNC | MSGF_ABORTABLE)) | MSGF_DONE;
245e4f17 85 msg->ms_reply_port = rport;
335dda38
MD
86}
87
ece04fd0
MD
88static __inline
89int
90lwkt_beginmsg(lwkt_port_t port, lwkt_msg_t msg)
91{
df2244e3 92 return(port->mp_putport(port, msg));
ece04fd0
MD
93}
94
df2244e3
MD
95static __inline
96int
97lwkt_waitmsg(lwkt_msg_t msg)
98{
99 lwkt_port_t port = msg->ms_reply_port;
100 return(((lwkt_msg_t)port->mp_waitport(port, msg))->ms_error);
ece04fd0
MD
101}
102
ece04fd0
MD
103static __inline
104void
105lwkt_replymsg(lwkt_msg_t msg, int error)
e7906ee5 106{
b44419cb 107 lwkt_port_t port;
e7906ee5 108
ece04fd0 109 msg->ms_error = error;
b44419cb 110 port = msg->ms_reply_port;
df2244e3 111 port->mp_replyport(port, msg);
ece04fd0
MD
112}
113
c95cd171
MD
114static __inline
115void *
116lwkt_waitport(lwkt_port_t port, lwkt_msg_t msg)
117{
118 return(port->mp_waitport(port, msg));
119}
120
1fa2b4b4
MD
121static __inline
122int
123lwkt_checkmsg(lwkt_msg_t msg)
124{
125 return(msg->ms_flags & MSGF_DONE);
126}
127
03d6a592
MD
128#endif /* _KERNEL */
129#endif /* _SYS_MSGPORT2_H_ */