1. -- 
  2. -- Uwe R. Zimmer, Australia, 2013 
  3. -- 
  4.  
  5. -- This generic monitor synchronizes the concurrent parts of 
  6. -- an atomic action and distributes a failure signal to all. 
  7. -- This monitor is used in conjunction with Generic_Atomic_Action. 
  8.  
  9. generic 
  10.    type Task_Ids is (<>); 
  11.  
  12. package Atomic_Controller is 
  13.  
  14.    type Atomic_State is (Checking_In, 
  15.                          All_Checked_In, 
  16.                          Checking_Out, 
  17.                          Final); 
  18.  
  19.    type Atomic_Condition is (Succeeded, 
  20.                              Late_Condition, 
  21.                              Time_Out_Condition, 
  22.                              Other_Exception); 
  23.  
  24.    type Check_Out_State is (Normal_Check_Out, Failed_Check_Out); 
  25.  
  26.    type Task_State is (Is_In, Is_Out); 
  27.  
  28.    type Task_List is array (Task_Ids) of Task_State; 
  29.  
  30.    Check_List_All_In      : constant Task_List := (others => Is_In); 
  31.    Check_List_All_Out     : constant Task_List := (others => Is_Out); 
  32.  
  33.    protected Monitor is 
  34.  
  35.       entry Check_In      (Task_Id   :     Task_Ids); 
  36.  
  37.       entry Fail          (Condition :     Atomic_Condition); 
  38.       entry Failed; 
  39.  
  40.       entry Check_Out (Check_Out_State) (Task_Id : Task_Ids); 
  41.  
  42.       entry Action_Result (Condition : out Atomic_Condition); 
  43.  
  44.    private 
  45.       Check_List      : Task_List        := Check_List_All_Out; 
  46.       State           : Atomic_State     := Checking_In; 
  47.       Final_Condition : Atomic_Condition := Succeeded; 
  48.       Id_Counter      : Task_Ids         := Task_Ids'First; 
  49.  
  50.    end Monitor; 
  51.  
  52.    Repeated_Check_In : exception; 
  53.  
  54. end Atomic_Controller;