[gtkada] GtkAda and tasking

Robin, Stephe, or Nora leakstan at erols.com
Fri Apr 21 14:14:15 CEST 2000


Last night, I wrote:

> I think what you'd like is a main loop something like this:
> 
> loop
>    select
>       accept Gtk.Main.Main_Event_Entry do
>           ...
>       end;
>    or
>       accept My_Stuff.Main_Event_Entry do
>           ...
>       end;
>   end select;
> end loop;

Which just goes to show that I should never try to write multi-tasking
Ada code at 10 PM after a four day vacation :).

Let me try again; I think what you want is to process events from two
queues. If each queue is a protected type:

protected type Event_Queue_Type is
    entry Enqueue (..);
    entyr Dequeue (..);
end;

Gtk_Queue : Event_Queue_Type;
App_Queue : Event_Queue_Type;

You would like the main loop to consist of a selective entry call on
either queue:

loop
    select 
        Gtk_Queue.Dequeue (...);
        ...
    or
        Gtk_Queue.App_Queue (...);
        ...
    end select;
end loop;

But that's not legal Ada! One solution is polling, as you have
mentioned. Another solution is to modify the Enqueue operation to
notify a common Event_Notification object:

protected type Event_Notification_Type is
    procedure Notify;
    entry Event_Occurred;
end Event_Notification_Type;

Common_Event : Event_Notification_Type;

now the main loop is:

loop
    Common_Event.Event_Occured;
    
    -- find out which queue has an event
    select
        Gtk_Queue.Dequeue (...);
        ...
    else
        null;
    end select;

    select
        App_Queue.Dequeue (...);
    else    
        null;
    end select;
end loop;

Note that we don't actually need the protected type Event_Queue_Type;
any type that can call Common_Event.Notify when an event occurs will
do. So now the question is, can the Gtk event queue be made to call
Common_Event.Notify? If there is a hook that is called for every
event, that would work.

I found the Gtk main loop code, in gmain.c in the glib library (I
forgot to look there last night). It's quite complicated, but it
appears there may be a hook that can be used to call
Common_Event.Notify.

-- Stephe






More information about the gtkada mailing list