PDA

View Full Version : Interrupt handling in ADA, Attach_Handler(Handler_Func, Interr_ID)


zero_kelvin
07-12-2011, 18:17
Ciao a tutti,

purtroppo mi sono ritrovato a dover utilizzare il linguaggio ADA e più precisamente a programmare un'applicazione multithreading che gestisca dei socket di rete ed anche degli interrupt software.

Sto incontrando molte difficoltà data la mancanza di documentazione / esempi ecc...

Per fortuna ho trovato qualche esempio sulla gestione degli interrupt tramite la direttiva pragma Attach_Handler(Handler_Func, Interrupt_ID).

Il programma è per sommi capi composto da:
il main thread che esegue delle operazioni per conto suo ed altri tre thread che ascoltano le comunicazioni in arrivo tramite socket; vorrei che questi tre thread scatenassero un interrupt (ovviamente diverso a seconda del thread) per notificare al main certi eventi.
Ho quindi pensato di settare tre handler su tre segnali di interrupt diversi, in modo tale da poter eseguire delle operazioni diverse a seconda dell'interrupt e generare quindi un interrupt all'interno del codice dei thread nel caso in cui si verifichi un evento.

Il problema è che se utilizzo al posto di Interrupt_ID un segnale di default dell'OS (esempio SIGINT o SIGTERM) qualcosa funziona, vale a dire compila ed esegue.

Se invece utilizzo un numero che corrisponde ad un segnale non di default (ad esempio l'ID di interrupt numero 3 o 7) ottengo il seguente errore:

raised PROGRAM_ERROR : adjust/finalize raised PROGRAM_ERROR: s-interr.adb:343 explicit raise

Preferirei utilizzare degli interrupt non riservati, per ovvie ragioni di affidabilità.

Riporto lo stralcio del sorgente (libreria standard di ADA) a cui si riferisce l'errore:

### File s-interr.adb ###

--------------------
-- Attach_Handler --
--------------------

procedure Attach_Handler
(New_Handler : Parameterless_Handler;
Interrupt : Interrupt_ID;
Static : Boolean := False) is
begin
Attach_Handler (New_Handler, Interrupt, Static, False);
end Attach_Handler;

procedure Attach_Handler
(New_Handler : Parameterless_Handler;
Interrupt : Interrupt_ID;
Static : Boolean;
Restoration : Boolean)
is
New_Task : Server_Task_Access;

begin
if Is_Reserved (Interrupt) then
linea 343 =====>>>>> raise Program_Error;
end if;

if not Restoration and then not Static

-- Tries to overwrite a static Interrupt Handler with dynamic handle

and then
(Descriptors (Interrupt).Static

-- New handler not specified as an Interrupt Handler by a pragma

or else not Is_Registered (New_Handler))
then
raise Program_Error with
"Trying to overwrite a static Interrupt Handler with a " &
"dynamic Handler";
end if;

if Handlers (Interrupt) = null then
New_Task := new Server_Task (Interrupt);
Handlers (Interrupt) := To_System (New_Task.all'Identity);
end if;

if intr_attach (int (Interrupt),
TISR (Signal_Handler'Access)) = FUNC_ERR
then
raise Program_Error;
end if;

if New_Handler = null then

-- The null handler means we are detaching the handler

Descriptors (Interrupt) :=
(Kind => Unknown, T => null, E => 0, H => null, Static => False);

else
Descriptors (Interrupt).Kind := Protected_Procedure;
Descriptors (Interrupt).H := New_Handler;
Descriptors (Interrupt).Static := Static;
end if;
end Attach_Handler;

eccetera

###

Ho fatto delle prove con la funzione Is_Reserved e restituisce FALSE nel caso di segnali di interrupt riservati, cioè esibisce un comportamento opposto a quello che mi sarei aspettato!!! [esempio: Is_Reserved(SIGINT) -> False]

Può essere che ci sia un problema nell'implementazione della funzione Is_Reserved e/o delle funzioni sottostanti?

Spero di essere stato abbastanza chiaro...

Vi ringrazio molto per l'aiuto!

:help: