OSDN Git Service

* 5ataprop.adb, 5atpopsp.adb, 5ftaprop.adb, 5gmastop.adb,
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5vtpopde.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                GNU ADA 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 --                             $Revision: 1.1 $                             --
11 --                                                                          --
12 --              Copyright (C) 2000 Free Software Foundation, Inc.           --
13 --                                                                          --
14 -- GNARL is free software; you can  redistribute it  and/or modify it under --
15 -- terms of the  GNU General Public License as published  by the Free Soft- --
16 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
17 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
18 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
19 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
20 -- for  more details.  You should have  received  a copy of the GNU General --
21 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
22 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
23 -- MA 02111-1307, USA.                                                      --
24 --                                                                          --
25 -- As a special exception,  if other files  instantiate  generics from this --
26 -- unit, or you link  this unit with other files  to produce an executable, --
27 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
28 -- covered  by the  GNU  General  Public  License.  This exception does not --
29 -- however invalidate  any other reasons why  the executable file  might be --
30 -- covered by the  GNU Public License.                                      --
31 --                                                                          --
32 -- GNARL was developed by the GNARL team at Florida State University. It is --
33 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
34 -- State University (http://www.gnat.com).                                  --
35 --                                                                          --
36 ------------------------------------------------------------------------------
37 --   This package is for OpenVMS/Alpha
38 --
39 with System.OS_Interface;
40 with System.Tasking;
41 with Unchecked_Conversion;
42 package body System.Task_Primitives.Operations.DEC is
43
44    use System.OS_Interface;
45    use System.Tasking;
46    use System.Aux_DEC;
47    use type Interfaces.C.int;
48
49    --  The FAB_RAB_Type specifieds where the context field (the calling
50    --  task) is stored.  Other fields defined for FAB_RAB aren't need and
51    --  so are ignored.
52    type FAB_RAB_Type is
53    record
54       CTX : Unsigned_Longword;
55    end record;
56
57    for FAB_RAB_Type use
58    record
59       CTX at 24 range 0 .. 31;
60    end record;
61
62    for FAB_RAB_Type'Size use 224;
63
64    type FAB_RAB_Access_Type is access all FAB_RAB_Type;
65
66    -----------------------
67    -- Local Subprograms --
68    -----------------------
69
70    function To_Unsigned_Longword is new
71      Unchecked_Conversion (Task_ID, Unsigned_Longword);
72
73    function To_Task_Id is new
74      Unchecked_Conversion (Unsigned_Longword, Task_ID);
75
76    function To_FAB_RAB is new
77      Unchecked_Conversion (Address, FAB_RAB_Access_Type);
78
79    ---------------------------
80    -- Interrupt_AST_Handler --
81    ---------------------------
82
83    procedure Interrupt_AST_Handler (ID : Address) is
84       Result     : Interfaces.C.int;
85       AST_Self_ID    : Task_ID := To_Task_Id (ID);
86    begin
87       Result := pthread_cond_signal_int_np (AST_Self_ID.Common.LL.CV'Access);
88       pragma Assert (Result = 0);
89    end Interrupt_AST_Handler;
90
91    ---------------------
92    -- RMS_AST_Handler --
93    ---------------------
94
95    procedure RMS_AST_Handler (ID : Address) is
96       AST_Self_ID    : Task_ID := To_Task_Id (To_FAB_RAB (ID).CTX);
97       Result     : Interfaces.C.int;
98    begin
99       AST_Self_ID.Common.LL.AST_Pending := False;
100       Result := pthread_cond_signal_int_np (AST_Self_ID.Common.LL.CV'Access);
101       pragma Assert (Result = 0);
102    end RMS_AST_Handler;
103
104    ----------
105    -- Self --
106    ----------
107
108    function Self return Unsigned_Longword is
109       Self_ID : Task_ID := Self;
110    begin
111       Self_ID.Common.LL.AST_Pending := True;
112       return To_Unsigned_Longword (Self);
113    end Self;
114
115    -------------------------
116    -- Starlet_AST_Handler --
117    -------------------------
118
119    procedure Starlet_AST_Handler (ID : Address) is
120       Result     : Interfaces.C.int;
121       AST_Self_ID    : Task_ID := To_Task_Id (ID);
122    begin
123       AST_Self_ID.Common.LL.AST_Pending := False;
124       Result := pthread_cond_signal_int_np (AST_Self_ID.Common.LL.CV'Access);
125       pragma Assert (Result = 0);
126    end Starlet_AST_Handler;
127
128    ----------------
129    -- Task_Synch --
130    ----------------
131
132    procedure Task_Synch is
133       Synch_Self_ID : Task_ID := Self;
134    begin
135       Write_Lock (Synch_Self_ID);
136       Synch_Self_ID.Common.State := AST_Server_Sleep;
137       while Synch_Self_ID.Common.LL.AST_Pending loop
138          Sleep (Synch_Self_ID, AST_Server_Sleep);
139       end loop;
140       Synch_Self_ID.Common.State := Runnable;
141       Unlock (Synch_Self_ID);
142    end Task_Synch;
143
144 end System.Task_Primitives.Operations.DEC;