OSDN Git Service

2004-05-17 Steve Kargl <kargls@comcast.net>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-tpopde-vms.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS               --
4 --                                                                          --
5 --                   SYSTEM.TASK_PRIMITIVES.OPERATIONS.DEC                  --
6 --                                                                          --
7 --                                  B o d y                                 --
8 --                                                                          --
9 --           Copyright (C) 2000-2004 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 2,  or (at your option) any later ver- --
14 -- sion. GNARL 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.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNARL was developed by the GNARL team at Florida State University.       --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --   This package is for OpenVMS/Alpha
35
36 with System.OS_Interface;
37 with System.Parameters;
38 with System.Tasking;
39 with Unchecked_Conversion;
40 with System.Soft_Links;
41
42 package body System.Task_Primitives.Operations.DEC is
43
44    use System.OS_Interface;
45    use System.Parameters;
46    use System.Tasking;
47    use System.Aux_DEC;
48    use type Interfaces.C.int;
49
50    package SSL renames System.Soft_Links;
51
52    --  The FAB_RAB_Type specifies where the context field (the calling
53    --  task) is stored.  Other fields defined for FAB_RAB arent' need and
54    --  so are ignored.
55
56    type FAB_RAB_Type is record
57       CTX : Unsigned_Longword;
58    end record;
59
60    for FAB_RAB_Type use record
61       CTX at 24 range 0 .. 31;
62    end record;
63
64    for FAB_RAB_Type'Size use 224;
65
66    type FAB_RAB_Access_Type is access all FAB_RAB_Type;
67
68    -----------------------
69    -- Local Subprograms --
70    -----------------------
71
72    function To_Unsigned_Longword is new
73      Unchecked_Conversion (Task_Id, Unsigned_Longword);
74
75    function To_Task_Id is new
76      Unchecked_Conversion (Unsigned_Longword, Task_Id);
77
78    function To_FAB_RAB is new
79      Unchecked_Conversion (Address, FAB_RAB_Access_Type);
80
81    ---------------------------
82    -- Interrupt_AST_Handler --
83    ---------------------------
84
85    procedure Interrupt_AST_Handler (ID : Address) is
86       Result      : Interfaces.C.int;
87       AST_Self_ID : constant Task_Id := To_Task_Id (ID);
88    begin
89       Result := pthread_cond_signal_int_np (AST_Self_ID.Common.LL.CV'Access);
90       pragma Assert (Result = 0);
91    end Interrupt_AST_Handler;
92
93    ---------------------
94    -- RMS_AST_Handler --
95    ---------------------
96
97    procedure RMS_AST_Handler (ID : Address) is
98       AST_Self_ID : constant Task_Id := To_Task_Id (To_FAB_RAB (ID).CTX);
99       Result      : Interfaces.C.int;
100
101    begin
102       AST_Self_ID.Common.LL.AST_Pending := False;
103       Result := pthread_cond_signal_int_np (AST_Self_ID.Common.LL.CV'Access);
104       pragma Assert (Result = 0);
105    end RMS_AST_Handler;
106
107    ----------
108    -- Self --
109    ----------
110
111    function Self return Unsigned_Longword is
112       Self_ID : constant Task_Id := Self;
113    begin
114       Self_ID.Common.LL.AST_Pending := True;
115       return To_Unsigned_Longword (Self);
116    end Self;
117
118    -------------------------
119    -- Starlet_AST_Handler --
120    -------------------------
121
122    procedure Starlet_AST_Handler (ID : Address) is
123       Result      : Interfaces.C.int;
124       AST_Self_ID : constant Task_Id := To_Task_Id (ID);
125    begin
126       AST_Self_ID.Common.LL.AST_Pending := False;
127       Result := pthread_cond_signal_int_np (AST_Self_ID.Common.LL.CV'Access);
128       pragma Assert (Result = 0);
129    end Starlet_AST_Handler;
130
131    ----------------
132    -- Task_Synch --
133    ----------------
134
135    procedure Task_Synch is
136       Synch_Self_ID : constant Task_Id := Self;
137
138    begin
139       if Single_Lock then
140          Lock_RTS;
141       else
142          Write_Lock (Synch_Self_ID);
143       end if;
144
145       SSL.Abort_Defer.all;
146       Synch_Self_ID.Common.State := AST_Server_Sleep;
147
148       while Synch_Self_ID.Common.LL.AST_Pending loop
149          Sleep (Synch_Self_ID, AST_Server_Sleep);
150       end loop;
151
152       Synch_Self_ID.Common.State := Runnable;
153
154       if Single_Lock then
155          Unlock_RTS;
156       else
157          Unlock (Synch_Self_ID);
158       end if;
159
160       SSL.Abort_Undefer.all;
161    end Task_Synch;
162
163 end System.Task_Primitives.Operations.DEC;