OSDN Git Service

* 1aexcept.adb, 1aexcept.ads, 1ic.ads, 1ssecsta.adb,
[pf3gnuchains/gcc-fork.git] / gcc / ada / i-os2thr.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --             I N T E R F A C E S . O S 2 L I B . T H R E A D S            --
6 --                                                                          --
7 --                                  S p e c                                 --
8 --                                                                          --
9 --          Copyright (C) 1993-1997 Free Software Foundation, Inc.          --
10 --                                                                          --
11 -- GNAT 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.  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.  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 GNAT;  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 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 with Interfaces.C;
35
36 package Interfaces.OS2Lib.Threads is
37 pragma Preelaborate (Threads);
38
39    package IC renames Interfaces.C;
40
41    type PID is new IC.unsigned_long;
42    type PPID is access all PID;
43    --  Process ID, and pointer to process ID
44
45    type TID is new IC.unsigned_long;
46    type PTID is access all TID;
47    --  Thread ID, and pointer to thread ID
48
49    -------------------------------------------------------------
50    -- Thread Creation, Activation, Suspension And Termination --
51    -------------------------------------------------------------
52
53    --  Note: <bsedos.h> defines the "Informations" and "param" parameter below
54    --  as a ULONG, but everyone knows that in general an address will be passed
55    --  to it. We declared it here with type PVOID (which it should have had)
56    --  because Ada is a bit more sensitive to mixing integers and addresses.
57
58    type PFNTHREAD is access procedure (Informations : System.Address);
59    --  TBSL should use PVOID instead of Address as per above node ???
60
61    function DosCreateThread
62      (F_ptid  : PTID;
63       pfn     : PFNTHREAD;
64       param   : PVOID;
65       flag    : ULONG;
66       cbStack : ULONG)
67       return    APIRET;
68    pragma Import (C, DosCreateThread, "DosCreateThread");
69
70    Block_Child     : constant := 1;
71    No_Block_Child  : constant := 0;
72    Commit_Stack    : constant := 2;
73    No_Commit_Stack : constant := 0;
74    --  Values for "flag" parameter in DosCreateThread call
75
76    procedure DosExit (Action : ULONG; Result : ULONG);
77    pragma Import (C, DosExit, "DosExit");
78
79    EXIT_THREAD  : constant := 0;
80    EXIT_PROCESS : constant := 1;
81    --  Values for "Action" parameter in Dos_Exit call
82
83    function DosResumeThread (Id : TID) return APIRET;
84    pragma Import (C, DosResumeThread, "DosResumeThread");
85
86    function DosSuspendThread (Id : TID) return APIRET;
87    pragma Import (C, DosSuspendThread, "DosSuspendThread");
88
89    procedure DosWaitThread (Thread_Ptr : PTID; Option : ULONG);
90    pragma Import (C, DosWaitThread, "DosWaitThread");
91
92    function DosKillThread (Id : TID) return APIRET;
93    pragma Import (C, DosKillThread, "DosKillThread");
94
95
96    DCWW_WAIT   : constant := 0;
97    DCWW_NOWAIT : constant := 1;
98    --  Values for "Option" parameter in DosWaitThread call
99
100    ---------------------------------------------------
101    -- Accessing properties of Threads and Processes --
102    ---------------------------------------------------
103
104    --  Structures translated from BSETIB.H
105
106    --  Thread Information Block (TIB)
107    --  Need documentation clarifying distinction between TIB, TIB2 ???
108
109    --  GB970409: Changed TIB2 structure, because the tib2_ulprio field
110    --            is not the actual priority but contains two byte fields
111    --            that hold the priority class and rank respectively.
112    --            A proper Ada style record with explicit representation
113    --            avoids this kind of errors.
114
115    type TIB2 is record
116       Thread_ID           : TID;
117       Prio_Rank           : UCHAR;
118       Prio_Class          : UCHAR;
119       Version             : ULONG;  -- Version number for this structure
120       Must_Complete_Count : USHORT; -- Must Complete count
121       Must_Complete_Force : USHORT; -- Must Complete force flag
122    end record;
123
124    type PTIB2 is access all TIB2;
125
126    --  Thread Information Block (TIB)
127
128    type TIB is record
129       tib_pexchain      : PVOID;  -- Head of exception handler chain
130       tib_pstack        : PVOID;  -- Pointer to base of stack
131       tib_pstacklimit   : PVOID;  -- Pointer to end of stack
132       System            : PTIB2;  -- Pointer to system specific TIB
133       tib_version       : ULONG;  -- Version number for this TIB structure
134       tib_ordinal       : ULONG;  -- Thread ordinal number
135    end record;
136
137    type PTIB is access all TIB;
138
139    --  Process Information Block (PIB)
140
141    type PIB is record
142       pib_ulpid         : ULONG;   -- Process I.D.
143       pib_ulppid        : ULONG;   -- Parent process I.D.
144       pib_hmte          : ULONG;   -- Program (.EXE) module handle
145       pib_pchcmd        : PCHAR;   -- Command line pointer
146       pib_pchenv        : PCHAR;   -- Environment pointer
147       pib_flstatus      : ULONG;   -- Process' status bits
148       pib_ultype        : ULONG;   -- Process' type code
149    end record;
150
151    type PPIB is access all PIB;
152
153    function DosGetInfoBlocks
154      (Pptib : access PTIB;
155       Pppib : access PPIB)
156       return  APIRET;
157    pragma Import (C, DosGetInfoBlocks, "DosGetInfoBlocks");
158
159    --  Thread local memory
160
161    --  This function allocates a block of memory that is unique, or local, to
162    --  a thread.
163
164    function DosAllocThreadLocalMemory
165      (cb : ULONG;               -- Number of 4-byte DWORDs to allocate
166       p  : access PVOID)        -- Address of the memory block
167    return
168       APIRET;                   -- Return Code (rc)
169    pragma Import
170      (Convention => C,
171       Entity     => DosAllocThreadLocalMemory,
172       Link_Name  => "_DosAllocThreadLocalMemory");
173
174    -----------------
175    --  Priorities --
176    -----------------
177
178    function DosSetPriority
179      (Scope   : ULONG;
180       Class   : ULONG;
181       Delta_P : IC.long;
182       PorTid  : TID)
183       return    APIRET;
184    pragma Import (C, DosSetPriority, "DosSetPriority");
185
186    PRTYS_PROCESS     : constant := 0;
187    PRTYS_PROCESSTREE : constant := 1;
188    PRTYS_THREAD      : constant := 2;
189    --  Values for "Scope" parameter in DosSetPriority call
190
191    PRTYC_NOCHANGE         : constant := 0;
192    PRTYC_IDLETIME         : constant := 1;
193    PRTYC_REGULAR          : constant := 2;
194    PRTYC_TIMECRITICAL     : constant := 3;
195    PRTYC_FOREGROUNDSERVER : constant := 4;
196    --  Values for "class" parameter in DosSetPriority call
197
198 end Interfaces.OS2Lib.Threads;