Import into DevLib.
[bertos.git] / kern / msg.h
1 /*!
2  * \file
3  * <!--
4  * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
5  * Copyright 1999,2001 Bernardo Innocenti <bernie@develer.com>
6  * This file is part of DevLib - See devlib/README for information.
7  * -->
8  *
9  * \brief Simple inter-process messaging system
10  *
11  * This module implements a common system for executing
12  * a user defined action calling a hook function.
13  *
14  * \version $Id$
15  *
16  * \author Bernardo Innocenti <bernie@develer.com>
17  */
18
19 /*
20  * $Log$
21  * Revision 1.1  2004/06/06 15:11:08  bernie
22  * Import into DevLib.
23  *
24  */
25 #ifndef KERN_MSG_H
26 #define KERN_MSG_H
27
28 #include "event.h"
29
30
31 typedef struct MsgPort
32 {
33         List  queue; /*!< Messages queued at this port */
34         Event evn;   /*!< Event to trigger when a message arrives */
35 } MsgPort;
36
37
38 typedef struct Msg
39 {
40         Node     link;      /*!< Link into message port queue */
41         MsgPort *replyPort; /*!< Port to which the msg is to be replied */
42         /* User data may follow */
43 } Msg;
44
45
46 /*! Initialize a messge port */
47 #define INITPORT(p)                     INITLIST(&(p)->queue)
48
49 /*! Queue a message to a message port */
50 #define PUTMSG(p,m) (ADDTAIL(&(p)->queue,(Node *)(m)), DOEVENT(&(p)->evn))
51 #define PUTMSG_INTR(p,m) (ADDTAIL(&(p)->queue,(Node *)(m)), DOEVENT_INTR(&(p)->evn))
52
53 /*! Get first message from port's queue (returns NULL when the port is empty) */
54 #define GETMSG(p) ((Msg *)REMHEAD(&(p)->queue))
55
56 /*! Reply a message to its sender */
57 #define REPLYMSG(m) (PUTMSG((m)->replyPort,(m)))
58
59 #endif /* KERN_MSG_H */