Import into DevLib.
authorbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Sun, 6 Jun 2004 15:11:08 +0000 (15:11 +0000)
committerbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Sun, 6 Jun 2004 15:11:08 +0000 (15:11 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@17 38d2e660-2303-0410-9eaa-f027e97ec537

kern/msg.h [new file with mode: 0755]

diff --git a/kern/msg.h b/kern/msg.h
new file mode 100755 (executable)
index 0000000..0fcfffa
--- /dev/null
@@ -0,0 +1,59 @@
+/*!
+ * \file
+ * <!--
+ * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 1999,2001 Bernardo Innocenti <bernie@develer.com>
+ * This file is part of DevLib - See devlib/README for information.
+ * -->
+ *
+ * \brief Simple inter-process messaging system
+ *
+ * This module implements a common system for executing
+ * a user defined action calling a hook function.
+ *
+ * \version $Id$
+ *
+ * \author Bernardo Innocenti <bernie@develer.com>
+ */
+
+/*
+ * $Log$
+ * Revision 1.1  2004/06/06 15:11:08  bernie
+ * Import into DevLib.
+ *
+ */
+#ifndef KERN_MSG_H
+#define KERN_MSG_H
+
+#include "event.h"
+
+
+typedef struct MsgPort
+{
+       List  queue; /*!< Messages queued at this port */
+       Event evn;   /*!< Event to trigger when a message arrives */
+} MsgPort;
+
+
+typedef struct Msg
+{
+       Node     link;      /*!< Link into message port queue */
+       MsgPort *replyPort; /*!< Port to which the msg is to be replied */
+       /* User data may follow */
+} Msg;
+
+
+/*! Initialize a messge port */
+#define INITPORT(p)                    INITLIST(&(p)->queue)
+
+/*! Queue a message to a message port */
+#define PUTMSG(p,m) (ADDTAIL(&(p)->queue,(Node *)(m)), DOEVENT(&(p)->evn))
+#define PUTMSG_INTR(p,m) (ADDTAIL(&(p)->queue,(Node *)(m)), DOEVENT_INTR(&(p)->evn))
+
+/*! Get first message from port's queue (returns NULL when the port is empty) */
+#define GETMSG(p) ((Msg *)REMHEAD(&(p)->queue))
+
+/*! Reply a message to its sender */
+#define REPLYMSG(m) (PUTMSG((m)->replyPort,(m)))
+
+#endif /* KERN_MSG_H */