Kill warnings when !CONFIG_PROC_MONITOR.
[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.4  2004/10/19 08:22:09  bernie
22  *#* msg_peek(): New function.
23  *#*
24  *#* Revision 1.3  2004/08/25 14:12:09  rasky
25  *#* Aggiornato il comment block dei log RCS
26  *#*
27  *#* Revision 1.2  2004/08/14 19:37:57  rasky
28  *#* Merge da SC: macros.h, pool.h, BIT_CHANGE, nome dei processi, etc.
29  *#*
30  *#* Revision 1.1  2004/06/06 15:11:08  bernie
31  *#* Import into DevLib.
32  *#*
33  *#*/
34 #ifndef KERN_MSG_H
35 #define KERN_MSG_H
36
37 #include "event.h"
38 #include <mware/list.h>
39
40
41 typedef struct MsgPort
42 {
43         List  queue; /*!< Messages queued at this port */
44         Event evn;   /*!< Event to trigger when a message arrives */
45 } MsgPort;
46
47
48 typedef struct Msg
49 {
50         Node     link;      /*!< Link into message port queue */
51         MsgPort *replyPort; /*!< Port to which the msg is to be replied */
52         /* User data may follow */
53 } Msg;
54
55
56 /*! Initialize a message port */
57 INLINE void msg_initPort(MsgPort* port, Event event)
58 {
59         INITLIST(&port->queue);
60         port->evn = event;
61 }
62
63 /*! Queue \a msg into \a port, triggering the associated event */
64 INLINE void msg_put(MsgPort* port, Msg* msg)
65 {
66         ADDTAIL(&port->queue, &msg->link);
67         event_do(&port->evn);
68 }
69
70 /* Get the first message from the queue of \a port, or NULL if the port is empty */
71 INLINE Msg* msg_get(MsgPort* port)
72 {
73         return (Msg*)REMHEAD(&port->queue);
74 }
75
76 /* Peek the first message in the queue of \a port, or NULL if the port is empty */
77 INLINE Msg *msg_peek(MsgPort *port)
78 {
79         if (ISLISTEMPTY(&port->queue))
80                 return NULL;
81
82         return (Msg *)port->queue.head;
83 }
84
85 /*! Send back (reply) \a msg to its sender */
86 INLINE void msg_reply(Msg* msg)
87 {
88         msg_put(msg->replyPort, msg);
89 }
90
91 #endif /* KERN_MSG_H */