--  Verada predefined library: the run-time's tasking operations (Ada's Jorvik profile), which
--  tasks, protected objects and `delay` statements are made of before analysis.
--  Programs call `Stop` only; the rest is what Verada writes for them.
with Ada.Real_Time;

package Verada.Tasking is
   --  a task's body, started by the elaboration of the package body that holds it, and run
   --  once library elaboration is over
   type Task_Body is access procedure;

   procedure Start (Body_Of : Task_Body)
     with Import, Convention => Ada, External_Name => "verada_rt_task_start", Global => null;

   --  every task ends, the calling one too: the program ends once its main subprogram returns
   --  (a task ends at its next delay, wait or loop iteration outside a protected action)
   procedure Stop
     with Import, Convention => Ada, External_Name => "verada_rt_tasks_stop", Global => null;

   --  a protected object's lock, held by each of its actions
   type Lock_Id is new Integer;

   function New_Lock return Lock_Id
     with Import, Convention => Ada, External_Name => "verada_rt_lock_new", Global => null;

   procedure Lock (L : Lock_Id)
     with Import, Convention => Ada, External_Name => "verada_rt_lock", Global => null;

   procedure Unlock (L : Lock_Id)
     with Import, Convention => Ada, External_Name => "verada_rt_unlock", Global => null;

   --  an entry whose barrier is closed waits until another action changes the object
   procedure Wait (L : Lock_Id)
     with Import, Convention => Ada, External_Name => "verada_rt_lock_wait", Global => null;

   --  after an action that may open a barrier
   procedure Notify (L : Lock_Id)
     with Import, Convention => Ada, External_Name => "verada_rt_lock_notify", Global => null;

   procedure Delay_Until (T : Ada.Real_Time.Time)
     with Global => null;

   --  for at least D (to the nanosecond above it), however long
   procedure Delay_For (D : Duration)
     with Global => null;

   --  an interrupt's handler, a protected procedure, attached as its package is elaborated
   --  (`Attach_Handler`); True
   function Attach (Interrupt : Integer; Handler : Task_Body) return Boolean
     with Import, Convention => Ada, External_Name => "verada_rt_attach_handler", Global => null;
end Verada.Tasking;
