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