1 /* 2 * SYS/MSGPORT2.H 3 * 4 * Implements Inlines for LWKT messages and ports. 5 * 6 * $DragonFly: src/sys/sys/msgport2.h,v 1.9 2004/04/20 01:52:24 dillon Exp $ 7 */ 8 9 #ifndef _SYS_MSGPORT2_H_ 10 #define _SYS_MSGPORT2_H_ 11 12 #ifndef _SYS_THREAD2_H_ 13 #include <sys/thread2.h> 14 #endif 15 16 #define lwkt_cmd_op_none lwkt_cmd_op(0) 17 18 typedef 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. 25 */ 26 static __inline 27 void 28 lwkt_initmsg(lwkt_msg_t msg, lwkt_port_t rport, int flags, 29 lwkt_cmd_t cmd, lwkt_cmd_t abort) 30 { 31 msg->ms_cmd = cmd; /* opaque */ 32 if (flags & MSGF_ABORTABLE) /* constant optimized conditional */ 33 msg->ms_abort = abort; /* opaque */ 34 msg->ms_flags = MSGF_DONE | flags; 35 msg->ms_reply_port = rport; 36 msg->ms_msgsize = 0; 37 } 38 39 /* 40 * These inlines convert specific types to the lwkt_cmd_t type. The compiler 41 * should be able to optimize this whole mess out. 42 */ 43 static __inline 44 lwkt_cmd_t 45 lwkt_cmd_op(int op) 46 { 47 lwkt_cmd_t cmd; 48 49 cmd.cm_op = op; 50 return(cmd); 51 } 52 53 static __inline 54 lwkt_cmd_t 55 lwkt_cmd_func(int (*func)(lwkt_msg_t)) 56 { 57 lwkt_cmd_t cmd; 58 59 cmd.cm_func = func; 60 return(cmd); 61 } 62 63 static __inline 64 void 65 lwkt_initmsg_simple(lwkt_msg_t msg, int op) 66 { 67 lwkt_initmsg(msg, &curthread->td_msgport, 0, 68 lwkt_cmd_op(op), lwkt_cmd_op(0)); 69 } 70 71 static __inline 72 void 73 lwkt_reinitmsg(lwkt_msg_t msg, lwkt_port_t rport) 74 { 75 msg->ms_flags = (msg->ms_flags & (MSGF_ASYNC | MSGF_ABORTABLE)) | MSGF_DONE; 76 msg->ms_reply_port = rport; 77 } 78 79 static __inline 80 int 81 lwkt_beginmsg(lwkt_port_t port, lwkt_msg_t msg) 82 { 83 return(port->mp_putport(port, msg)); 84 } 85 86 static __inline 87 int 88 lwkt_waitmsg(lwkt_msg_t msg) 89 { 90 lwkt_port_t port = msg->ms_reply_port; 91 return(((lwkt_msg_t)port->mp_waitport(port, msg))->ms_error); 92 } 93 94 static __inline 95 void 96 lwkt_replymsg(lwkt_msg_t msg, int error) 97 { 98 lwkt_port_t port; 99 100 msg->ms_error = error; 101 port = msg->ms_reply_port; 102 port->mp_replyport(port, msg); 103 } 104 105 static __inline 106 void * 107 lwkt_waitport(lwkt_port_t port, lwkt_msg_t msg) 108 { 109 return(port->mp_waitport(port, msg)); 110 } 111 112 #endif 113 114