| 1 | /* |
| 2 | * SYS/MSGPORT.H |
| 3 | * |
| 4 | * Implements LWKT messages and ports. |
| 5 | * |
| 6 | * $DragonFly: src/sys/sys/msgport.h,v 1.1 2003/07/20 01:37:22 dillon Exp $ |
| 7 | */ |
| 8 | |
| 9 | #ifndef _SYS_MSGPORT_H_ |
| 10 | #define _SYS_MSGPORT_H_ |
| 11 | |
| 12 | #ifndef _SYS_QUEUE_H_ |
| 13 | #include <sys/queue.h> /* TAILQ_* macros */ |
| 14 | #endif |
| 15 | |
| 16 | struct lwkt_msg; |
| 17 | struct lwkt_port; |
| 18 | |
| 19 | typedef struct lwkt_msg *lwkt_msg_t; |
| 20 | typedef struct lwkt_port *lwkt_port_t; |
| 21 | |
| 22 | /* |
| 23 | * The standard message and port structure for communications between |
| 24 | * threads. See kern/lwkt_msgport.c for documentation on how messages and |
| 25 | * ports work. |
| 26 | */ |
| 27 | typedef struct lwkt_msg { |
| 28 | TAILQ_ENTRY(lwkt_msg) ms_node; /* link node (not always used) */ |
| 29 | lwkt_port_t ms_target_port; /* only used in certain situations */ |
| 30 | lwkt_port_t ms_reply_port; /* asynch replies returned here */ |
| 31 | int ms_abortreq; /* set asynchronously */ |
| 32 | int ms_cmd; |
| 33 | int ms_flags; |
| 34 | int ms_error; |
| 35 | } lwkt_msg; |
| 36 | |
| 37 | #define MSGF_DONE 0x0001 /* asynch message is complete */ |
| 38 | #define MSGF_REPLY 0x0002 /* asynch message has been returned */ |
| 39 | #define MSGF_QUEUED 0x0004 /* message has been queued sanitychk */ |
| 40 | #define MSGF_ASYNC 0x0008 /* sync/async hint */ |
| 41 | |
| 42 | typedef struct lwkt_port { |
| 43 | lwkt_msg_queue mp_msgq; |
| 44 | int mp_flags; |
| 45 | thread_t mp_td; |
| 46 | int (*mp_beginmsg)(lwkt_port_t port, lwkt_msg_t msg); |
| 47 | void (*mp_abortmsg)(lwkt_port_t port, lwkt_msg_t msg); |
| 48 | void (*mp_returnmsg)(lwkt_port_t port, lwkt_msg_t msg); |
| 49 | } lwkt_port; |
| 50 | |
| 51 | #define MSGPORTF_WAITING 0x0001 |
| 52 | |
| 53 | #ifdef _KERNEL |
| 54 | |
| 55 | extern void lwkt_init_port(lwkt_port_t port, thread_t td); |
| 56 | extern void lwkt_sendmsg(lwkt_port_t port, lwkt_msg_t msg); |
| 57 | extern int lwkt_domsg(lwkt_port_t port, lwkt_msg_t msg); |
| 58 | extern int lwkt_waitmsg(lwkt_msg_t msg); |
| 59 | extern void lwkt_replyport(lwkt_port_t port, lwkt_msg_t msg); |
| 60 | extern void lwkt_abortport(lwkt_port_t port, lwkt_msg_t msg); |
| 61 | extern int lwkt_putport(lwkt_port_t port, lwkt_msg_t msg); |
| 62 | extern void *lwkt_getport(lwkt_port_t port); |
| 63 | extern void *lwkt_waitport(lwkt_port_t port); |
| 64 | |
| 65 | #endif |
| 66 | |
| 67 | #endif |