comp.lang.ada
 help / color / mirror / Atom feed
From: "Vinzent Hoefler" <0439279208b62c95f1880bf0f8776eeb@t-domaingrabbing.de>
Subject: Re: Interrupts handling in ADA
Date: Sat, 10 Dec 2011 22:13:28 +0100
Date: 2011-12-10T22:13:28+01:00	[thread overview]
Message-ID: <op.v6ak8qmklzeukk@jellix.jlfencey.com> (raw)
In-Reply-To: 30143086.6.1323549838421.JavaMail.geo-discussion-forums@vbbfq24

Ada @ BRL wrote:

> The environment of ADA applcation is:
> 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 decided to use the sockets instead of dll/lib import because this approach hasn't worked... =( ]
>
> 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.
>
> I've thought to use the interrupts...because I haven't found any references about the use of "events" in ADA.

You probably haven't seen references to protected types, then.
(Although I am not sure, if a task rendezvous wouldn't even be more fit
for your purpose...)

> May you tell me please if this is the right way to face the problem?

Well, not in Ada, no. ;)

A quick and dirty approach (I'm missing the specs about what precisely you
are trying to achieve, but then again, it's /your/ thesis.) But I sure hope,
it gives you an idea at least...

-- 8< --

type Source_Id     is (Task_1, Task_2, Task_3);
type Arrived_Flags is array (Source_Id) of Boolean;

protected type Event is

     procedure Signal_Event (Source : in Source_Id);
     entry Wait (Source : out Source_Id);

private

     Arrived       : Arrived_Flags := (others => False);
     Event_Pending : Boolean       := False;

end Event;

protected body Event is

     procedure Signal_Event (Source : in Source_Id) is
     begin
        --  Set flag for available source.
        Arrived_Flags (Source) := True;

        --  And set the barrier condition.
        Event_Pending := True;
     end Signal_Event;

     entry Wait (Source : out Source_Id) when Event_Pending is
     begin
        Find_Event:
        for S in Arrived'Range loop
           --  If event is marked as arrived, clear it and
           --  return the source id.
           if Arrived (S) then
              Source := S;
              Arrived (S) := False;
              exit Find_Event;
           end if;
        end loop;

        --  Paranoid thoughts: Shall we protect against uninitialized
        --                     values of Source here or can we assume
        --                     that at least one bit in the array was
        --                     set if Event_Pending was actually True?

        --  No more events in Arrived? Lower the barrier again.
        Event_Pending := Arrived /= Arrived_Flags'(others => False);
     end Wait;

end Event;

(Haven't compiled it, so any errors are mine.)

Now your main task could suspend on the wait entry of such a protected
object whilst your communication task indicate their readiness via the
Signal_Event protected procedure.

How to exchange the data between the threads, well ... it could be done
in the Wait entry, too, but that's something I'd like to be "left as an
exercise for the reader". ;)


Vinzent.

-- 
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.



  reply	other threads:[~2011-12-10 21:13 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 [this message]
2011-12-10 22:09 ` Niklas Holsti
2011-12-10 22:27 ` Simon Wright
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