OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [ada/] [s-osprim-vxworks.adb] - Blame information for rev 329

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 281 jeremybenn
------------------------------------------------------------------------------
2
--                                                                          --
3
--                 GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                 --
4
--                                                                          --
5
--                  S Y S T E M . O S _ P R I M I T I V E S                 --
6
--                                                                          --
7
--                                  B o d y                                 --
8
--                                                                          --
9
--          Copyright (C) 1998-2009, Free Software Foundation, Inc.         --
10
--                                                                          --
11
-- GNARL 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
-- As a special exception under Section 7 of GPL version 3, you are granted --
19
-- additional permissions described in the GCC Runtime Library Exception,   --
20
-- version 3.1, as published by the Free Software Foundation.               --
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
--  This version is for VxWorks targets
33
 
34
with System.OS_Interface;
35
--  Since the thread library is part of the VxWorks kernel, using OS_Interface
36
--  is not a problem here, as long as we only use System.OS_Interface as a
37
--  set of C imported routines: using Ada routines from this package would
38
--  create a dependency on libgnarl in libgnat, which is not desirable.
39
 
40
with Interfaces.C;
41
 
42
package body System.OS_Primitives is
43
 
44
   use System.OS_Interface;
45
   use type Interfaces.C.int;
46
 
47
   ------------------------
48
   -- Internal functions --
49
   ------------------------
50
 
51
   function To_Clock_Ticks (D : Duration) return int;
52
   --  Convert a duration value (in seconds) into clock ticks.
53
   --  Note that this routine is duplicated from System.OS_Interface since
54
   --  as explained above, we do not want to depend on libgnarl
55
 
56
   function To_Clock_Ticks (D : Duration) return int is
57
      Ticks          : Long_Long_Integer;
58
      Rate_Duration  : Duration;
59
      Ticks_Duration : Duration;
60
 
61
   begin
62
      if D < 0.0 then
63
         return -1;
64
      end if;
65
 
66
      --  Ensure that the duration can be converted to ticks
67
      --  at the current clock tick rate without overflowing.
68
 
69
      Rate_Duration := Duration (sysClkRateGet);
70
 
71
      if D > (Duration'Last / Rate_Duration) then
72
         Ticks := Long_Long_Integer (int'Last);
73
      else
74
         Ticks_Duration := D * Rate_Duration;
75
         Ticks := Long_Long_Integer (Ticks_Duration);
76
 
77
         if Ticks_Duration > Duration (Ticks) then
78
            Ticks := Ticks + 1;
79
         end if;
80
 
81
         if Ticks > Long_Long_Integer (int'Last) then
82
            Ticks := Long_Long_Integer (int'Last);
83
         end if;
84
      end if;
85
 
86
      return int (Ticks);
87
   end To_Clock_Ticks;
88
 
89
   -----------
90
   -- Clock --
91
   -----------
92
 
93
   function Clock return Duration is
94
      TS     : aliased timespec;
95
      Result : int;
96
   begin
97
      Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access);
98
      pragma Assert (Result = 0);
99
      return Duration (TS.ts_sec) + Duration (TS.ts_nsec) / 10#1#E9;
100
   end Clock;
101
 
102
   ---------------------
103
   -- Monotonic_Clock --
104
   ---------------------
105
 
106
   function Monotonic_Clock return Duration renames Clock;
107
 
108
   -----------------
109
   -- Timed_Delay --
110
   -----------------
111
 
112
   procedure Timed_Delay
113
     (Time : Duration;
114
      Mode : Integer)
115
   is
116
      Rel_Time   : Duration;
117
      Abs_Time   : Duration;
118
      Base_Time  : constant Duration := Clock;
119
      Check_Time : Duration := Base_Time;
120
      Ticks      : int;
121
 
122
      Result     : int;
123
      pragma Unreferenced (Result);
124
 
125
   begin
126
      if Mode = Relative then
127
         Rel_Time := Time;
128
         Abs_Time := Time + Check_Time;
129
      else
130
         Rel_Time := Time - Check_Time;
131
         Abs_Time := Time;
132
      end if;
133
 
134
      if Rel_Time > 0.0 then
135
         loop
136
            Ticks := To_Clock_Ticks (Rel_Time);
137
 
138
            if Mode = Relative and then Ticks < int'Last then
139
               --  The first tick will delay anytime between 0 and
140
               --  1 / sysClkRateGet seconds, so we need to add one to
141
               --  be on the safe side.
142
 
143
               Ticks := Ticks + 1;
144
            end if;
145
 
146
            Result := taskDelay (Ticks);
147
            Check_Time := Clock;
148
 
149
            exit when Abs_Time <= Check_Time or else Check_Time < Base_Time;
150
 
151
            Rel_Time := Abs_Time - Check_Time;
152
         end loop;
153
      end if;
154
   end Timed_Delay;
155
 
156
   ----------------
157
   -- Initialize --
158
   ----------------
159
 
160
   procedure Initialize is
161
   begin
162
      null;
163
   end Initialize;
164
 
165
end System.OS_Primitives;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.