Add src/test and throw in some of the ad-hoc timing and testing programs
[dragonfly.git] / sys / sys / msgport.h
1 /*
2  * SYS/MSGPORT.H
3  *
4  *      Implements LWKT messages and ports.
5  * 
6  * $DragonFly: src/sys/sys/msgport.h,v 1.6 2003/07/30 00:19:16 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 struct thread;
19
20 typedef struct lwkt_msg         *lwkt_msg_t;
21 typedef struct lwkt_port        *lwkt_port_t;
22
23 typedef TAILQ_HEAD(lwkt_msg_queue, lwkt_msg) lwkt_msg_queue;
24
25 /*
26  * The standard message and port structure for communications between
27  * threads.  See kern/lwkt_msgport.c for documentation on how messages and
28  * ports work.
29  *
30  * NOTE! 64-bit-align this structure.
31  */
32 typedef struct lwkt_msg {
33     TAILQ_ENTRY(lwkt_msg) ms_node;      /* link node (not always used) */
34     union {
35         struct lwkt_msg *ms_next;       /* chaining / cache */
36         union sysmsg    *ms_sysnext;    /* chaining / cache */
37         struct lwkt_msg *ms_umsg;       /* user message (UVA address) */
38     } opaque;
39     lwkt_port_t ms_target_port;         /* only used in certain situations */
40     lwkt_port_t ms_reply_port;          /* asynch replies returned here */
41     int         ms_abortreq;            /* set asynchronously */
42     int         ms_cmd;
43     int         ms_flags;
44     int         ms_error;
45     union {
46         void    *ms_resultp;            /* misc pointer result */
47         int     ms_result;              /* standard 'int'eger result */
48         long    ms_lresult;             /* long result */
49         int     ms_fds[2];              /* two int bit results */
50         int32_t ms_result32;            /* 32 bit result */
51         int64_t ms_result64;            /* 64 bit result */
52         off_t   ms_offset;              /* off_t result */
53     } u;
54     int         ms_pad[2];              /* future use */
55 } lwkt_msg;
56
57 #define MSGF_DONE       0x0001          /* asynch message is complete */
58 #define MSGF_REPLY      0x0002          /* asynch message has been returned */
59 #define MSGF_QUEUED     0x0004          /* message has been queued sanitychk */
60 #define MSGF_ASYNC      0x0008          /* sync/async hint */
61
62 #define MSG_CMD_CDEV    0x00010000
63 #define MSG_CMD_VFS     0x00020000
64 #define MSG_CMD_SYSCALL 0x00030000
65 #define MSG_SUBCMD_MASK 0x0000FFFF
66
67 typedef struct lwkt_port {
68     lwkt_msg_queue      mp_msgq;
69     int                 mp_flags;
70     struct thread       *mp_td;
71     int                 (*mp_beginmsg)(lwkt_port_t port, lwkt_msg_t msg);
72     void                (*mp_abortmsg)(lwkt_port_t port, lwkt_msg_t msg);
73     void                (*mp_returnmsg)(lwkt_port_t port, lwkt_msg_t msg);
74 } lwkt_port;
75
76 #define MSGPORTF_WAITING        0x0001
77
78 #ifdef _KERNEL
79
80 extern void lwkt_init_port(lwkt_port_t port, struct thread *td);
81 extern void lwkt_initmsg_td(lwkt_msg_t msg, struct thread *td);
82 extern void lwkt_sendmsg(lwkt_port_t port, lwkt_msg_t msg);
83 extern int lwkt_domsg(lwkt_port_t port, lwkt_msg_t msg);
84 extern int lwkt_waitmsg(lwkt_msg_t msg);
85 extern void lwkt_replyport(lwkt_port_t port, lwkt_msg_t msg);
86 extern void lwkt_abortport(lwkt_port_t port, lwkt_msg_t msg);
87 extern int lwkt_putport(lwkt_port_t port, lwkt_msg_t msg);
88 extern void *lwkt_getport(lwkt_port_t port);
89 extern void *lwkt_waitport(lwkt_port_t port);
90
91 #endif
92
93 #endif