OSDN Git Service

* reload1.c (reload_cse_simplify): Fix typo in rtx code check.
[pf3gnuchains/gcc-fork.git] / gcc / ada / 4zsytaco.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUNTIME COMPONENTS                          --
4 --                                                                          --
5 --         A D A . S Y N C H R O N O U S _ T A S K _ C O N T R O L          --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                                                                          --
10 --            Copyright (C) 1992-2001 Free Software Foundation, Inc.        --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- As a special exception,  if other files  instantiate  generics from this --
24 -- unit, or you link  this unit with other files  to produce an executable, --
25 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
26 -- covered  by the  GNU  General  Public  License.  This exception does not --
27 -- however invalidate  any other reasons why  the executable file  might be --
28 -- covered by the  GNU Public License.                                      --
29 --                                                                          --
30 -- GNAT was originally developed  by the GNAT team at  New York University. --
31 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 with Interfaces.C;
36 package body Ada.Synchronous_Task_Control is
37    use System.OS_Interface;
38    use type Interfaces.C.int;
39
40    -------------------
41    -- Current_State --
42    -------------------
43
44    function Current_State (S : Suspension_Object) return Boolean is
45       St     : STATUS;
46       Result : Boolean := False;
47
48    begin
49       --  Determine state by attempting to take the semaphore with
50       --  a 0 timeout value.  Status = OK indicates the semaphore was
51       --  full, so reset it to the full state.
52
53       St := semTake (S.Sema, NO_WAIT);
54
55       if St = OK then
56          --  Took the semaphore. Reset semaphore state to FULL
57          Result := True;
58          St := semGive (S.Sema);
59       end if;
60
61       return Result;
62    end Current_State;
63
64    ---------------
65    -- Set_False --
66    ---------------
67
68    procedure Set_False (S : in out Suspension_Object) is
69       St : STATUS;
70    begin
71       --  Need to get the semaphore into the "empty" state.
72       --  On return, this task will have made the semaphore
73       --  empty (St = OK) or have left it empty.
74       St := semTake (S.Sema, NO_WAIT);
75    end Set_False;
76
77    --------------
78    -- Set_True --
79    --------------
80
81    procedure Set_True (S : in out Suspension_Object) is
82       St : STATUS;
83    begin
84       St := semGive (S.Sema);
85    end Set_True;
86
87    ------------------------
88    -- Suspend_Until_True --
89    ------------------------
90
91    procedure Suspend_Until_True (S : in out Suspension_Object) is
92       St : STATUS;
93
94       --  Declare local exception so the mutex can still be reset
95       --  to full if Program_Error is raised
96
97       Task_Already_Pending : exception;
98    begin
99       --  Determine whether another task is pending on the suspension
100       --  object. Should never be called from an ISR. Therefore semTake can
101       --  be called on the mutex
102       St := semTake (S.Mutex, NO_WAIT);
103
104       if St = OK then
105          --  Wait for suspension object
106
107          St := semTake (S.Sema, WAIT_FOREVER);
108          St := semGive (S.Mutex);
109
110       else
111          --  Another task is pending on the suspension object
112
113          raise Task_Already_Pending;
114       end if;
115    exception
116       when Task_Already_Pending =>
117          raise Program_Error;
118       when others =>
119          St := semGive (S.Mutex);
120          raise;
121    end Suspend_Until_True;
122
123    procedure Initialize (S : in out Suspension_Object) is
124    begin
125       S.Sema := semBCreate (SEM_Q_FIFO, SEM_EMPTY);
126
127       --  Use simpler binary semaphore instead of VxWorks
128       --  mutual exclusion semaphore, because we don't need
129       --  the fancier semantics and their overhead.
130
131       S.Mutex := semBCreate (SEM_Q_FIFO, SEM_FULL);
132    end Initialize;
133
134    procedure Finalize (S : in out Suspension_Object) is
135       St : STATUS;
136    begin
137       St := semDelete (S.Sema);
138       St := semDelete (S.Mutex);
139    end Finalize;
140
141 end Ada.Synchronous_Task_Control;