with text_io; use text_io; with ada.strings.unbounded; use ada.strings.unbounded; package body schedulers is procedure Select_task_by_fixed_Priority( Current_Time : in Natural; Elected : in out Tasks_Range; No_Task : in out Boolean) is Lowest_Period : Natural := Natural'Last; I : Tasks_Range := 0; begin -- We can compute scheduling since priorities are ok -- I := 0; loop if (Tcbs(I).Wake_Up_Time <= Current_Time) and (Tcbs(I).Period < Lowest_Period) and (Tcbs(I).Rest_Of_Capacity /= 0) then Lowest_Period:=Tcbs(I).Period; Elected :=I; end if; I := I + 1; exit when i>number_of_tasks; end loop; if Lowest_Period = Natural'Last then No_Task := True; else No_Task := False; end if; end Select_task_by_fixed_Priority; procedure schedule(Last_Time : in natural) is -- Variables for the main loop of the simulation -- Last_Current_Time : Natural :=0; Current_Time : Natural :=0; Elected : Tasks_Range :=Tasks_Range'First; No_Task : Boolean :=True; begin for i in 0 .. number_of_tasks-1 loop Tcbs(i).Rest_Of_Capacity:=Tcbs (i).capacity; Tcbs(i).Wake_Up_Time:=Tcbs(i).start_time; Put_line("Time " & Tcbs (i).Wake_Up_Time'img & " : Task " & to_string(tcbs(i).name) & " is activated "); end loop; while (current_Time < last_time) loop Select_task_by_fixed_Priority( Current_Time, Elected, No_Task); -- There is a task to schedule -- if not No_Task then -- -- Produce schedule on the screen -- And update task properties -- Put_line("Time " & current_time'img & " : Task " & to_string(tcbs(elected).name) & " is running "); Tcbs (Elected).Rest_Of_Capacity := Tcbs (Elected).Rest_Of_Capacity - 1; -- -- Compute the next task activations -- if (Tcbs (Elected).Rest_Of_Capacity = 0) then case Tcbs (Elected).task_type is when Periodic_Type => Tcbs (Elected).Rest_Of_Capacity := Tcbs (Elected).capacity; Tcbs (Elected).Wake_Up_Time := Tcbs (Elected).Wake_Up_Time + Tcbs (Elected).period; when Aperiodic_Type => null; end case; if Tcbs (Elected).task_type = periodic_Type and Tcbs (Elected).Wake_Up_Time <= Last_Time then Put_line("Time " & Tcbs (Elected).Wake_Up_Time'img & " : Task " & to_string(tcbs(elected).name) & " is activated "); end if; end if; end if; Current_Time := Current_Time + 1; end loop; end schedule; end schedulers;