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. package body Atomic_Controller is 
  10.  
  11.    protected body Monitor is 
  12.  
  13.       entry Check_In (Task_Id : Task_Ids) when State = Checking_In is 
  14.  
  15.       begin 
  16.          if Check_List (Task_Id) = Is_In then 
  17.             raise Repeated_Check_In; 
  18.          else 
  19.             Check_List (Task_Id) := Is_In; 
  20.             if Check_List = Check_List_All_In then 
  21.                State := All_Checked_In; 
  22.             end if; 
  23.          end if; 
  24.       end Check_In; 
  25.  
  26.       entry Fail (Condition : Atomic_Condition) when State = All_Checked_In is 
  27.  
  28.       begin 
  29.          Final_Condition := Condition; 
  30.       end Fail; 
  31.  
  32.       entry Failed when Final_Condition /= Succeeded is 
  33.  
  34.       begin 
  35.          null; 
  36.       end Failed; 
  37.  
  38.       entry Check_Out (for Check_Out_Queue in Check_Out_State) (Task_Id : Task_Ids) 
  39.       when State = Checking_Out 
  40.         or else Check_Out (Check_Out_Queue)'Count = Task_List'Length is 
  41.  
  42.       begin 
  43.          State := Checking_Out; 
  44.          Check_List (Task_Id) := Is_Out; 
  45.          if Check_List = Check_List_All_Out then 
  46.             State := Final; 
  47.          end if; 
  48.       end Check_Out; 
  49.  
  50.       entry Action_Result (Condition : out Atomic_Condition) when State = Final is 
  51.  
  52.       begin 
  53.          Condition       := Final_Condition; 
  54.          State           := Checking_In; 
  55.          Final_Condition := Succeeded; 
  56.       end Action_Result; 
  57.  
  58.    end Monitor; 
  59.  
  60. end Atomic_Controller;