1 /* 2 * SYS/MSGPORT2.H 3 * 4 * Implements Inlines for LWKT messages and ports. 5 * 6 * $DragonFly: src/sys/sys/msgport2.h,v 1.10 2004/06/04 20:35:39 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 * Note that other areas of the LWKT msg may already be initialized, so we 27 * do not zero the message here. 28 */ 29 static __inline 30 void 31 lwkt_initmsg(lwkt_msg_t msg, lwkt_port_t rport, int flags, 32 lwkt_cmd_t cmd, lwkt_cmd_t abort) 33 { 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; 39 msg->ms_msgsize = 0; 40 } 41 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 */ 46 static __inline 47 lwkt_cmd_t 48 lwkt_cmd_op(int op) 49 { 50 lwkt_cmd_t cmd; 51 52 cmd.cm_op = op; 53 return(cmd); 54 } 55 56 static __inline 57 lwkt_cmd_t 58 lwkt_cmd_func(int (*func)(lwkt_msg_t)) 59 { 60 lwkt_cmd_t cmd; 61 62 cmd.cm_func = func; 63 return(cmd); 64 } 65 66 static __inline 67 void 68 lwkt_initmsg_simple(lwkt_msg_t msg, int op) 69 { 70 lwkt_initmsg(msg, &curthread->td_msgport, 0, 71 lwkt_cmd_op(op), lwkt_cmd_op(0)); 72 } 73 74 static __inline 75 void 76 lwkt_reinitmsg(lwkt_msg_t msg, lwkt_port_t rport) 77 { 78 msg->ms_flags = (msg->ms_flags & (MSGF_ASYNC | MSGF_ABORTABLE)) | MSGF_DONE; 79 msg->ms_reply_port = rport; 80 } 81 82 static __inline 83 int 84 lwkt_beginmsg(lwkt_port_t port, lwkt_msg_t msg) 85 { 86 return(port->mp_putport(port, msg)); 87 } 88 89 static __inline 90 int 91 lwkt_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); 95 } 96 97 static __inline 98 void 99 lwkt_replymsg(lwkt_msg_t msg, int error) 100 { 101 lwkt_port_t port; 102 103 msg->ms_error = error; 104 port = msg->ms_reply_port; 105 port->mp_replyport(port, msg); 106 } 107 108 static __inline 109 void * 110 lwkt_waitport(lwkt_port_t port, lwkt_msg_t msg) 111 { 112 return(port->mp_waitport(port, msg)); 113 } 114 115 static __inline 116 int 117 lwkt_checkmsg(lwkt_msg_t msg) 118 { 119 return(msg->ms_flags & MSGF_DONE); 120 } 121 122 #endif 123 124