New Language: Ada
[gcc.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 -- $Revision: 1.12 $ --
10 -- --
11 -- Copyright (C) 1993-1997 Free Software Foundation, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
30 -- --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 -- --
34 ------------------------------------------------------------------------------
35
36 with Interfaces.C;
37
38 package Interfaces.OS2Lib.Threads is
39 pragma Preelaborate (Threads);
40
41 package IC renames Interfaces.C;
42
43 type PID is new IC.unsigned_long;
44 type PPID is access all PID;
45 -- Process ID, and pointer to process ID
46
47 type TID is new IC.unsigned_long;
48 type PTID is access all TID;
49 -- Thread ID, and pointer to thread ID
50
51 -------------------------------------------------------------
52 -- Thread Creation, Activation, Suspension And Termination --
53 -------------------------------------------------------------
54
55 -- Note: <bsedos.h> defines the "Informations" and "param" parameter below
56 -- as a ULONG, but everyone knows that in general an address will be passed
57 -- to it. We declared it here with type PVOID (which it should have had)
58 -- because Ada is a bit more sensitive to mixing integers and addresses.
59
60 type PFNTHREAD is access procedure (Informations : System.Address);
61 -- TBSL should use PVOID instead of Address as per above node ???
62
63 function DosCreateThread
64 (F_ptid : PTID;
65 pfn : PFNTHREAD;
66 param : PVOID;
67 flag : ULONG;
68 cbStack : ULONG)
69 return APIRET;
70 pragma Import (C, DosCreateThread, "DosCreateThread");
71
72 Block_Child : constant := 1;
73 No_Block_Child : constant := 0;
74 Commit_Stack : constant := 2;
75 No_Commit_Stack : constant := 0;
76 -- Values for "flag" parameter in DosCreateThread call
77
78 procedure DosExit (Action : ULONG; Result : ULONG);
79 pragma Import (C, DosExit, "DosExit");
80
81 EXIT_THREAD : constant := 0;
82 EXIT_PROCESS : constant := 1;
83 -- Values for "Action" parameter in Dos_Exit call
84
85 function DosResumeThread (Id : TID) return APIRET;
86 pragma Import (C, DosResumeThread, "DosResumeThread");
87
88 function DosSuspendThread (Id : TID) return APIRET;
89 pragma Import (C, DosSuspendThread, "DosSuspendThread");
90
91 procedure DosWaitThread (Thread_Ptr : PTID; Option : ULONG);
92 pragma Import (C, DosWaitThread, "DosWaitThread");
93
94 function DosKillThread (Id : TID) return APIRET;
95 pragma Import (C, DosKillThread, "DosKillThread");
96
97
98 DCWW_WAIT : constant := 0;
99 DCWW_NOWAIT : constant := 1;
100 -- Values for "Option" parameter in DosWaitThread call
101
102 ---------------------------------------------------
103 -- Accessing properties of Threads and Processes --
104 ---------------------------------------------------
105
106 -- Structures translated from BSETIB.H
107
108 -- Thread Information Block (TIB)
109 -- Need documentation clarifying distinction between TIB, TIB2 ???
110
111 -- GB970409: Changed TIB2 structure, because the tib2_ulprio field
112 -- is not the actual priority but contains two byte fields
113 -- that hold the priority class and rank respectively.
114 -- A proper Ada style record with explicit representation
115 -- avoids this kind of errors.
116
117 type TIB2 is record
118 Thread_ID : TID;
119 Prio_Rank : UCHAR;
120 Prio_Class : UCHAR;
121 Version : ULONG; -- Version number for this structure
122 Must_Complete_Count : USHORT; -- Must Complete count
123 Must_Complete_Force : USHORT; -- Must Complete force flag
124 end record;
125
126 type PTIB2 is access all TIB2;
127
128 -- Thread Information Block (TIB)
129
130 type TIB is record
131 tib_pexchain : PVOID; -- Head of exception handler chain
132 tib_pstack : PVOID; -- Pointer to base of stack
133 tib_pstacklimit : PVOID; -- Pointer to end of stack
134 System : PTIB2; -- Pointer to system specific TIB
135 tib_version : ULONG; -- Version number for this TIB structure
136 tib_ordinal : ULONG; -- Thread ordinal number
137 end record;
138
139 type PTIB is access all TIB;
140
141 -- Process Information Block (PIB)
142
143 type PIB is record
144 pib_ulpid : ULONG; -- Process I.D.
145 pib_ulppid : ULONG; -- Parent process I.D.
146 pib_hmte : ULONG; -- Program (.EXE) module handle
147 pib_pchcmd : PCHAR; -- Command line pointer
148 pib_pchenv : PCHAR; -- Environment pointer
149 pib_flstatus : ULONG; -- Process' status bits
150 pib_ultype : ULONG; -- Process' type code
151 end record;
152
153 type PPIB is access all PIB;
154
155 function DosGetInfoBlocks
156 (Pptib : access PTIB;
157 Pppib : access PPIB)
158 return APIRET;
159 pragma Import (C, DosGetInfoBlocks, "DosGetInfoBlocks");
160
161 -- Thread local memory
162
163 -- This function allocates a block of memory that is unique, or local, to
164 -- a thread.
165
166 function DosAllocThreadLocalMemory
167 (cb : ULONG; -- Number of 4-byte DWORDs to allocate
168 p : access PVOID) -- Address of the memory block
169 return
170 APIRET; -- Return Code (rc)
171 pragma Import
172 (Convention => C,
173 Entity => DosAllocThreadLocalMemory,
174 Link_Name => "_DosAllocThreadLocalMemory");
175
176 -----------------
177 -- Priorities --
178 -----------------
179
180 function DosSetPriority
181 (Scope : ULONG;
182 Class : ULONG;
183 Delta_P : IC.long;
184 PorTid : TID)
185 return APIRET;
186 pragma Import (C, DosSetPriority, "DosSetPriority");
187
188 PRTYS_PROCESS : constant := 0;
189 PRTYS_PROCESSTREE : constant := 1;
190 PRTYS_THREAD : constant := 2;
191 -- Values for "Scope" parameter in DosSetPriority call
192
193 PRTYC_NOCHANGE : constant := 0;
194 PRTYC_IDLETIME : constant := 1;
195 PRTYC_REGULAR : constant := 2;
196 PRTYC_TIMECRITICAL : constant := 3;
197 PRTYC_FOREGROUNDSERVER : constant := 4;
198 -- Values for "class" parameter in DosSetPriority call
199
200 end Interfaces.OS2Lib.Threads;