home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / a-taside.adb < prev    next >
Text File  |  2000-07-19  |  5KB  |  154 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                        GNAT RUN-TIME COMPONENTS                          --
  4. --                                                                          --
  5. --              A D A . T A S K _ I D E N T I F I C A T I O N               --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.18 $
  10. --                                                                          --
  11. --           Copyright (C) 1992-1999 Free Software Foundation, Inc.         --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. with System.Address_Image;
  37. --  used for the function itself
  38.  
  39. with System.Tasking;
  40. --  used for Task_List
  41.  
  42. with System.Tasking.Stages;
  43. --  used for Terminated
  44. --           Abort_Tasks
  45.  
  46. with System.Tasking.Rendezvous;
  47. --  used for Callable
  48.  
  49. with System.Task_Primitives.Operations;
  50. --  used for Self
  51.  
  52. with System.Task_Info;
  53. use type System.Task_Info.Task_Image_Type;
  54.  
  55. with Unchecked_Conversion;
  56.  
  57. package body Ada.Task_Identification is
  58.  
  59.    function Convert_Ids (T : Task_Id) return System.Tasking.Task_ID;
  60.    function Convert_Ids (T : System.Tasking.Task_ID) return Task_Id;
  61.    pragma Inline (Convert_Ids);
  62.  
  63.    function Convert_Ids (T : Task_Id) return System.Tasking.Task_ID is
  64.    begin
  65.       return System.Tasking.Task_ID (T);
  66.    end Convert_Ids;
  67.  
  68.    function Convert_Ids (T : System.Tasking.Task_ID) return Task_Id is
  69.    begin
  70.       return Task_Id (T);
  71.    end Convert_Ids;
  72.  
  73.    ---------
  74.    -- "=" --
  75.    ---------
  76.  
  77.    function  "=" (Left, Right : Task_Id) return Boolean is
  78.    begin
  79.       return System.Tasking."=" (Convert_Ids (Left), Convert_Ids (Right));
  80.    end "=";
  81.  
  82.    -----------------
  83.    -- Abort_Task --
  84.    ----------------
  85.  
  86.    procedure Abort_Task (T : in out Task_Id) is
  87.    begin
  88.       if T = Null_Task_Id then
  89.          raise Program_Error;
  90.       else
  91.          System.Tasking.Stages.Abort_Tasks
  92.            (System.Tasking.Task_List'(1 => Convert_Ids (T)));
  93.       end if;
  94.    end Abort_Task;
  95.  
  96.    ------------------
  97.    -- Current_Task --
  98.    ------------------
  99.  
  100.    function Current_Task return Task_Id is
  101.    begin
  102.       return Convert_Ids (System.Task_Primitives.Operations.Self);
  103.    end Current_Task;
  104.  
  105.    -----------
  106.    -- Image --
  107.    -----------
  108.  
  109.    function Image (T : Task_Id) return String is
  110.       use System.Task_Info;
  111.       function To_Address is new
  112.         Unchecked_Conversion (Task_Id, System.Address);
  113.  
  114.    begin
  115.       if T = Null_Task_Id then
  116.          return "";
  117.  
  118.       elsif T.Common.Task_Image = null then
  119.          return System.Address_Image (To_Address (T));
  120.  
  121.       else
  122.          return T.Common.Task_Image.all
  123.             & "_" &  System.Address_Image (To_Address (T));
  124.       end if;
  125.    end Image;
  126.  
  127.    -----------------
  128.    -- Is_Callable --
  129.    -----------------
  130.  
  131.    function Is_Callable (T : Task_Id) return Boolean is
  132.    begin
  133.       if T = Null_Task_Id then
  134.          raise Program_Error;
  135.       else
  136.          return System.Tasking.Rendezvous.Callable (Convert_Ids (T));
  137.       end if;
  138.    end Is_Callable;
  139.  
  140.    -------------------
  141.    -- Is_Terminated --
  142.    -------------------
  143.  
  144.    function Is_Terminated (T : Task_Id) return Boolean is
  145.    begin
  146.       if T = Null_Task_Id then
  147.          raise Program_Error;
  148.       else
  149.          return System.Tasking.Stages.Terminated (Convert_Ids (T));
  150.       end if;
  151.    end Is_Terminated;
  152.  
  153. end Ada.Task_Identification;
  154.