1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- I N T E R F A C E S . O S 2 L I B . T H R E A D S --
9 -- Copyright (C) 1993-1997 Free Software Foundation, Inc. --
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. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
36 package Interfaces.OS2Lib.Threads is
37 pragma Preelaborate (Threads);
39 package IC renames Interfaces.C;
41 type PID is new IC.unsigned_long;
42 type PPID is access all PID;
43 -- Process ID, and pointer to process ID
45 type TID is new IC.unsigned_long;
46 type PTID is access all TID;
47 -- Thread ID, and pointer to thread ID
49 -------------------------------------------------------------
50 -- Thread Creation, Activation, Suspension And Termination --
51 -------------------------------------------------------------
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.
58 type PFNTHREAD is access procedure (Informations : System.Address);
59 -- TBSL should use PVOID instead of Address as per above node ???
61 function DosCreateThread
68 pragma Import (C, DosCreateThread, "DosCreateThread");
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
76 procedure DosExit (Action : ULONG; Result : ULONG);
77 pragma Import (C, DosExit, "DosExit");
79 EXIT_THREAD : constant := 0;
80 EXIT_PROCESS : constant := 1;
81 -- Values for "Action" parameter in Dos_Exit call
83 function DosResumeThread (Id : TID) return APIRET;
84 pragma Import (C, DosResumeThread, "DosResumeThread");
86 function DosSuspendThread (Id : TID) return APIRET;
87 pragma Import (C, DosSuspendThread, "DosSuspendThread");
89 procedure DosWaitThread (Thread_Ptr : PTID; Option : ULONG);
90 pragma Import (C, DosWaitThread, "DosWaitThread");
92 function DosKillThread (Id : TID) return APIRET;
93 pragma Import (C, DosKillThread, "DosKillThread");
96 DCWW_WAIT : constant := 0;
97 DCWW_NOWAIT : constant := 1;
98 -- Values for "Option" parameter in DosWaitThread call
100 ---------------------------------------------------
101 -- Accessing properties of Threads and Processes --
102 ---------------------------------------------------
104 -- Structures translated from BSETIB.H
106 -- Thread Information Block (TIB)
107 -- Need documentation clarifying distinction between TIB, TIB2 ???
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.
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
124 type PTIB2 is access all TIB2;
126 -- Thread Information Block (TIB)
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
137 type PTIB is access all TIB;
139 -- Process Information Block (PIB)
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
151 type PPIB is access all PIB;
153 function DosGetInfoBlocks
154 (Pptib : access PTIB;
157 pragma Import (C, DosGetInfoBlocks, "DosGetInfoBlocks");
159 -- Thread local memory
161 -- This function allocates a block of memory that is unique, or local, to
164 function DosAllocThreadLocalMemory
165 (cb : ULONG; -- Number of 4-byte DWORDs to allocate
166 p : access PVOID) -- Address of the memory block
168 APIRET; -- Return Code (rc)
171 Entity => DosAllocThreadLocalMemory,
172 Link_Name => "_DosAllocThreadLocalMemory");
178 function DosSetPriority
184 pragma Import (C, DosSetPriority, "DosSetPriority");
186 PRTYS_PROCESS : constant := 0;
187 PRTYS_PROCESSTREE : constant := 1;
188 PRTYS_THREAD : constant := 2;
189 -- Values for "Scope" parameter in DosSetPriority call
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
198 end Interfaces.OS2Lib.Threads;