comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Interrupts handling in ADA
Date: Sat, 10 Dec 2011 22:27:39 +0000
Date: 2011-12-10T22:27:39+00:00	[thread overview]
Message-ID: <m2ty589i5g.fsf@pushface.org> (raw)
In-Reply-To: 30143086.6.1323549838421.JavaMail.geo-discussion-forums@vbbfq24

"Ada @ BRL" <ada.brl.2011@gmail.com> writes:

> The environment of ADA applcation is:

Ada, please!

> I have 4 tasks that execute at the same time:
> one is the main task,
> the other three execute a "read" from network (socket) function inside
> their bodies (on the other side there's the C/C++ application with 3
> network sockets).
[...]
> I want that when new data is available on one or more socket threads,
> this / these threads somehow notify the main thread that data is
> arrived and then safely send the data to it.

First off, I'd use a Queue.

The new Ada2012 standard includes a synchronised Queue, which would be
just what you want out of the box, but you won't find that in the
current compilers, so you'll need to roll your own.

Starting from Ada.Containers.Vectors[1], the Queue abstraction would
come from using Append to put new mesages on the queue, Is_Empty to
check whether there's something to get from the queue, and First_Element
followed by Delete_First to fetch the front element.

You then need to wrap this container in a protected object[2], so that
the updates from the different input tasks don't corrupt each other, and
so that the main task can block until there's something to read. Use a
Put procedure to post messages onto the queue, and a Get entry to read
the next message or block if there isn't one.

The spec might look like

   with Ada.Containers.Vectors;
   package Queueing is
      type Message is new Integer;
      package Queue_Data
      is new Ada.Containers.Vectors (Index_Type => Natural,
                                     Element_Type => Message);
      protected Queue is
         procedure Put (M : Message);
         entry Get (M : out Message);
      private
         Buffer : Queue_Data.Vector;
      end Queue;
   end Queueing;

and (as a hint) the body of the Get entry might start like

      entry Get (M : out Message) when not Buffer.Is_Empty is
      begin

If your input messages are not all the same type (in Ada-speak, type
Message is indefinite), things get more complicated; but let's cross
that bridge only if we need to.

[1]http://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-18-2.html
[2]http://en.wikibooks.org/wiki/Ada_Programming/Tasking#Protected_types



  parent reply	other threads:[~2011-12-10 22:27 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-10 20:43 Interrupts handling in ADA Ada @ BRL
2011-12-10 21:13 ` Vinzent Hoefler
2011-12-10 22:09 ` Niklas Holsti
2011-12-10 22:27 ` Simon Wright [this message]
2011-12-11 20:21   ` Martin Dowie
2011-12-13 13:51     ` Ada BRL
2011-12-13 23:18       ` Martin Dowie
2011-12-13 14:11     ` Niklas Holsti
2011-12-13 14:54       ` Simon Wright
2011-12-13 15:06         ` Ada BRL
2011-12-13 21:49           ` Niklas Holsti
2011-12-13 23:18       ` Martin Dowie
2011-12-13 12:47   ` Ada BRL
2011-12-13 15:07     ` Simon Wright
2011-12-13 15:23       ` Ada BRL
2011-12-13 18:14         ` Simon Wright
2011-12-13 18:56           ` Ada BRL
2011-12-13 19:56           ` Bill Findlay
2011-12-13 22:15         ` Niklas Holsti
2011-12-13 15:34       ` Simon Wright
2011-12-13 17:55         ` Ada BRL
2011-12-13 18:18           ` Dmitry A. Kazakov
2011-12-13 19:01             ` Ada BRL
2011-12-13 19:58               ` Dmitry A. Kazakov
2011-12-13 18:24           ` Simon Wright
2011-12-11  0:15 ` Jeffrey Carter
2011-12-13 12:53   ` Ada BRL
2011-12-11  9:23 ` Dmitry A. Kazakov
2011-12-13 13:11   ` Ada BRL
2011-12-13 14:04     ` Dmitry A. Kazakov
2011-12-13 14:51       ` Ada BRL
2011-12-13 15:02         ` Ada BRL
2011-12-13 15:39         ` Dmitry A. Kazakov
2011-12-13 18:51           ` Ada BRL
2011-12-13 19:51             ` Dmitry A. Kazakov
2011-12-13 23:32             ` georg bauhaus
2011-12-11 12:04 ` Georg Bauhaus
2011-12-13 14:08   ` Ada BRL
2011-12-12  3:19 ` anon
2011-12-12  9:12   ` Niklas Holsti
2011-12-13 13:36     ` Ada BRL
2011-12-12 15:23   ` björn lundin
2011-12-13 13:38     ` Ada BRL
2011-12-13 13:56       ` Ludovic Brenta
2011-12-13 14:10         ` Ada BRL
2011-12-13 13:31   ` Ada BRL
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox