File : s-osinte-lynxos178.adb


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                 GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                 --
   4 --                                                                          --
   5 --                   S Y S T E M . O S _ I N T E R F A C E                  --
   6 --                                                                          --
   7 --                                  B o d y                                 --
   8 --                                                                          --
   9 --                     Copyright (C) 2001-2016, AdaCore                     --
  10 --                                                                          --
  11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  12 -- terms of the  GNU General Public License as published  by the Free Soft- --
  13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
  14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  16 -- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
  17 --                                                                          --
  18 --                                                                          --
  19 --                                                                          --
  20 --                                                                          --
  21 --                                                                          --
  22 -- You should have received a copy of the GNU General Public License and    --
  23 -- a copy of the GCC Runtime Library Exception along with this program;     --
  24 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
  25 -- <http://www.gnu.org/licenses/>.                                          --
  26 --                                                                          --
  27 -- GNARL was developed by the GNARL team at Florida State University.       --
  28 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
  29 --                                                                          --
  30 ------------------------------------------------------------------------------
  31 
  32 --  Version of System.OS_Interface for LynxOS-178 (POSIX Threads)
  33 
  34 pragma Polling (Off);
  35 --  Turn off polling, we do not want ATC polling to take place during tasking
  36 --  operations. It may cause infinite loops and other problems.
  37 
  38 package body System.OS_Interface is
  39 
  40    use Interfaces.C;
  41 
  42    ------------------
  43    --  Current_CPU --
  44    ------------------
  45 
  46    function Current_CPU return Multiprocessors.CPU is
  47    begin
  48       --  No multiprocessor support, always return the first CPU Id
  49 
  50       return Multiprocessors.CPU'First;
  51    end Current_CPU;
  52 
  53    --------------------
  54    --  Get_Affinity  --
  55    --------------------
  56 
  57    function Get_Affinity (Id : Thread_Id) return Multiprocessors.CPU_Range is
  58       pragma Unreferenced (Id);
  59 
  60    begin
  61       --  No multiprocessor support, always return Not_A_Specific_CPU
  62 
  63       return Multiprocessors.Not_A_Specific_CPU;
  64    end Get_Affinity;
  65 
  66    ---------------
  67    --  Get_CPU  --
  68    ---------------
  69 
  70    function Get_CPU  (Id : Thread_Id) return Multiprocessors.CPU is
  71       pragma Unreferenced (Id);
  72 
  73    begin
  74       --  No multiprocessor support, always return the first CPU Id
  75 
  76       return Multiprocessors.CPU'First;
  77    end Get_CPU;
  78 
  79    -------------------
  80    -- Get_Page_Size --
  81    -------------------
  82 
  83    SC_PAGESIZE : constant := 17;
  84    --  C macro to get pagesize value from sysconf
  85 
  86    function sysconf (name : int) return long;
  87    pragma Import (C, sysconf, "sysconf");
  88 
  89    function Get_Page_Size return int is
  90    begin
  91       return int (sysconf (SC_PAGESIZE));
  92    end Get_Page_Size;
  93 
  94    -----------------
  95    -- To_Duration --
  96    -----------------
  97 
  98    function To_Duration (TS : timespec) return Duration is
  99    begin
 100       return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
 101    end To_Duration;
 102 
 103    ------------------------
 104    -- To_Target_Priority --
 105    ------------------------
 106 
 107    function To_Target_Priority
 108      (Prio : System.Any_Priority) return Interfaces.C.int
 109    is
 110    begin
 111       return Interfaces.C.int (Prio);
 112    end To_Target_Priority;
 113 
 114    -----------------
 115    -- To_Timespec --
 116    -----------------
 117 
 118    function To_Timespec (D : Duration) return timespec is
 119       S : time_t;
 120       F : Duration;
 121 
 122    begin
 123       S := time_t (Long_Long_Integer (D));
 124       F := D - Duration (S);
 125 
 126       --  If F is negative due to a round-up, adjust for positive F value
 127 
 128       if F < 0.0 then
 129          S := S - 1;
 130          F := F + 1.0;
 131       end if;
 132 
 133       return timespec'(tv_sec => S,
 134                        tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
 135    end To_Timespec;
 136 
 137    -------------
 138    -- sigwait --
 139    -------------
 140 
 141    function sigwait
 142      (set :  access sigset_t;
 143       sig :  access Signal)
 144       return int
 145    is
 146       function sigwaitinfo
 147         (set   : access sigset_t;
 148          info  : System.Address) return Signal;
 149       pragma Import (C, sigwaitinfo, "sigwaitinfo");
 150 
 151    begin
 152       sig.all := sigwaitinfo (set, Null_Address);
 153 
 154       if sig.all = -1 then
 155          return errno;
 156       end if;
 157 
 158       return 0;
 159    end sigwait;
 160 
 161    --------------------
 162    -- Get_Stack_Base --
 163    --------------------
 164 
 165    function Get_Stack_Base (thread : pthread_t) return Address is
 166       pragma Warnings (Off, thread);
 167    begin
 168       return Null_Address;
 169    end Get_Stack_Base;
 170 
 171    ------------------
 172    -- pthread_init --
 173    ------------------
 174 
 175    procedure pthread_init is
 176    begin
 177       null;
 178    end pthread_init;
 179 
 180 end System.OS_Interface;