OSDN Git Service

Update FSF address
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-tpopde-vms.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                 GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                 --
4 --                                                                          --
5 --    S Y S T E M . T A S K _ P R I M I T I V E S . O P E R A T I O N S .   --
6 --                                   D E C                                  --
7 --                                                                          --
8 --                                  B o d y                                 --
9 --                                                                          --
10 --           Copyright (C) 2000-2005 Free Software Foundation, Inc.         --
11 --                                                                          --
12 -- GNARL 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. GNARL 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 GNARL; see file COPYING.  If not, write --
20 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
21 -- Boston, MA 02110-1301, 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 -- GNARL was developed by the GNARL team at Florida State University.       --
31 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --   This package is for OpenVMS/Alpha
36
37 with System.OS_Interface;
38 with System.Parameters;
39 with System.Tasking;
40 with Unchecked_Conversion;
41 with System.Soft_Links;
42
43 package body System.Task_Primitives.Operations.DEC is
44
45    use System.OS_Interface;
46    use System.Parameters;
47    use System.Tasking;
48    use System.Aux_DEC;
49    use type Interfaces.C.int;
50
51    package SSL renames System.Soft_Links;
52
53    --  The FAB_RAB_Type specifies where the context field (the calling
54    --  task) is stored.  Other fields defined for FAB_RAB arent' need and
55    --  so are ignored.
56
57    type FAB_RAB_Type is record
58       CTX : Unsigned_Longword;
59    end record;
60
61    for FAB_RAB_Type use record
62       CTX at 24 range 0 .. 31;
63    end record;
64
65    for FAB_RAB_Type'Size use 224;
66
67    type FAB_RAB_Access_Type is access all FAB_RAB_Type;
68
69    -----------------------
70    -- Local Subprograms --
71    -----------------------
72
73    pragma Warnings (Off);
74    --  Task_Id is 64 bits wide (but only 32 bits significant) on Integrity/VMS
75
76    function To_Unsigned_Longword is new
77      Unchecked_Conversion (Task_Id, Unsigned_Longword);
78
79    function To_Task_Id is new
80      Unchecked_Conversion (Unsigned_Longword, Task_Id);
81
82    pragma Warnings (On);
83
84    function To_FAB_RAB is new
85      Unchecked_Conversion (Address, FAB_RAB_Access_Type);
86
87    ---------------------------
88    -- Interrupt_AST_Handler --
89    ---------------------------
90
91    procedure Interrupt_AST_Handler (ID : Address) is
92       Result      : Interfaces.C.int;
93       AST_Self_ID : constant Task_Id := To_Task_Id (ID);
94    begin
95       Result := pthread_cond_signal_int_np (AST_Self_ID.Common.LL.CV'Access);
96       pragma Assert (Result = 0);
97    end Interrupt_AST_Handler;
98
99    ---------------------
100    -- RMS_AST_Handler --
101    ---------------------
102
103    procedure RMS_AST_Handler (ID : Address) is
104       AST_Self_ID : constant Task_Id := To_Task_Id (To_FAB_RAB (ID).CTX);
105       Result      : Interfaces.C.int;
106
107    begin
108       AST_Self_ID.Common.LL.AST_Pending := False;
109       Result := pthread_cond_signal_int_np (AST_Self_ID.Common.LL.CV'Access);
110       pragma Assert (Result = 0);
111    end RMS_AST_Handler;
112
113    ----------
114    -- Self --
115    ----------
116
117    function Self return Unsigned_Longword is
118       Self_ID : constant Task_Id := Self;
119    begin
120       Self_ID.Common.LL.AST_Pending := True;
121       return To_Unsigned_Longword (Self);
122    end Self;
123
124    -------------------------
125    -- Starlet_AST_Handler --
126    -------------------------
127
128    procedure Starlet_AST_Handler (ID : Address) is
129       Result      : Interfaces.C.int;
130       AST_Self_ID : constant Task_Id := To_Task_Id (ID);
131    begin
132       AST_Self_ID.Common.LL.AST_Pending := False;
133       Result := pthread_cond_signal_int_np (AST_Self_ID.Common.LL.CV'Access);
134       pragma Assert (Result = 0);
135    end Starlet_AST_Handler;
136
137    ----------------
138    -- Task_Synch --
139    ----------------
140
141    procedure Task_Synch is
142       Synch_Self_ID : constant Task_Id := Self;
143
144    begin
145       if Single_Lock then
146          Lock_RTS;
147       else
148          Write_Lock (Synch_Self_ID);
149       end if;
150
151       SSL.Abort_Defer.all;
152       Synch_Self_ID.Common.State := AST_Server_Sleep;
153
154       while Synch_Self_ID.Common.LL.AST_Pending loop
155          Sleep (Synch_Self_ID, AST_Server_Sleep);
156       end loop;
157
158       Synch_Self_ID.Common.State := Runnable;
159
160       if Single_Lock then
161          Unlock_RTS;
162       else
163          Unlock (Synch_Self_ID);
164       end if;
165
166       SSL.Abort_Undefer.all;
167    end Task_Synch;
168
169 end System.Task_Primitives.Operations.DEC;