home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / ada / a-dynpri.adb < prev    next >
Text File  |  1996-09-28  |  4KB  |  112 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                 A D A . D Y N A M I C _ P R I O R I T I E S              --
  6. --                                                                          --
  7. --                                  B o d y                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.11 $                             --
  10. --                                                                          --
  11. --     Copyright (c) 1991,1992,1993,1994,1995 FSU, All Rights Reserved      --
  12. --                                                                          --
  13. -- GNARL is free software; you can redistribute it  and/or modify it  under --
  14. -- terms  of  the  GNU  Library General Public License  as published by the --
  15. -- Free Software  Foundation;  either version 2, or (at  your  option)  any --
  16. -- later  version.  GNARL is distributed  in the hope that  it will be use- --
  17. -- ful, but but WITHOUT ANY WARRANTY;  without even the implied warranty of --
  18. -- MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Gen- --
  19. -- eral Library Public License  for more details.  You should have received --
  20. -- a  copy of the GNU Library General Public License along with GNARL;  see --
  21. -- file COPYING.LIB.  If not,  write to the  Free Software Foundation,  675 --
  22. -- Mass Ave, Cambridge, MA 02139, USA.                                      --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System.Tasking; use System.Tasking;
  27.  
  28. with System.Tasking.Stages;
  29. --  Used for, System.Tasking.Stages.Terminated
  30.  
  31. with System.Task_Primitives; use System.Task_Primitives;
  32.  
  33. with Unchecked_Conversion;
  34.  
  35. package body Ada.Dynamic_Priorities is
  36.  
  37.    function Convert_Ids is new
  38.      Unchecked_Conversion
  39.        (Task_Identification.Task_Id, System.Tasking.Task_ID);
  40.  
  41.    ------------------
  42.    -- Set_Priority --
  43.    ------------------
  44.  
  45.    --  Change base priority of a task dynamically
  46.  
  47.    procedure Set_Priority
  48.      (Priority : System.Any_Priority;
  49.       T : Ada.Task_Identification.Task_ID :=
  50.           Ada.Task_Identification.Current_Task)
  51.    is
  52.       Target : constant Task_ID := Convert_Ids (T);
  53.       Source : constant Task_ID := Self;
  54.       Error  : Boolean;
  55.  
  56.    begin
  57.       if Task_Identification.Is_Terminated (T) then
  58.          raise Tasking_Error;
  59.       end if;
  60.  
  61.       if T = Ada.Task_Identification.Null_Task_Id then
  62.          raise Program_Error;
  63.       end if;
  64.  
  65.       System.Task_Primitives.Write_Lock (Target.L, Error);
  66.  
  67.       if Source = Target then
  68.          Target.Current_Priority := Priority;
  69.          Target.Base_Priority := Priority;
  70.          System.Task_Primitives.Set_Priority (Target.LL_TCB'Access, Priority);
  71.  
  72.       else
  73.  
  74.          Target.New_Base_Priority := Priority;
  75.          Target.Pending_Priority_Change := True;
  76.          Target.Pending_Action := True;
  77.  
  78.          Cond_Signal (Target.Cond);
  79.          --  If the task is suspended, wake it up to perform the change.
  80.  
  81.          --  check for ceiling violations ???
  82.       end if;
  83.  
  84.       System.Task_Primitives.Unlock (Target.L);
  85.  
  86.    end Set_Priority;
  87.  
  88.    ------------------
  89.    -- Get_Priority --
  90.    ------------------
  91.  
  92.    --  Inquire base priority of a task
  93.  
  94.    function Get_Priority
  95.      (T : Ada.Task_Identification.Task_ID :=
  96.           Ada.Task_Identification.Current_Task)
  97.      return System.Any_Priority is
  98.  
  99.    begin
  100.       if Task_Identification.Is_Terminated (T) then
  101.          raise Tasking_Error;
  102.       end if;
  103.  
  104.       if T = Ada.Task_Identification.Null_Task_Id then
  105.          raise Program_Error;
  106.       end if;
  107.  
  108.       return Convert_Ids (T).Base_Priority;
  109.    end Get_Priority;
  110.  
  111. end Ada.Dynamic_Priorities;
  112.