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 -- $Revision: 1.12 $ --
11 -- Copyright (C) 1993-1997 Free Software Foundation, Inc. --
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. --
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. --
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). --
34 ------------------------------------------------------------------------------
38 package Interfaces.OS2Lib.Threads is
39 pragma Preelaborate (Threads);
41 package IC renames Interfaces.C;
43 type PID is new IC.unsigned_long;
44 type PPID is access all PID;
45 -- Process ID, and pointer to process ID
47 type TID is new IC.unsigned_long;
48 type PTID is access all TID;
49 -- Thread ID, and pointer to thread ID
51 -------------------------------------------------------------
52 -- Thread Creation, Activation, Suspension And Termination --
53 -------------------------------------------------------------
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.
60 type PFNTHREAD is access procedure (Informations : System.Address);
61 -- TBSL should use PVOID instead of Address as per above node ???
63 function DosCreateThread
70 pragma Import (C, DosCreateThread, "DosCreateThread");
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
78 procedure DosExit (Action : ULONG; Result : ULONG);
79 pragma Import (C, DosExit, "DosExit");
81 EXIT_THREAD : constant := 0;
82 EXIT_PROCESS : constant := 1;
83 -- Values for "Action" parameter in Dos_Exit call
85 function DosResumeThread (Id : TID) return APIRET;
86 pragma Import (C, DosResumeThread, "DosResumeThread");
88 function DosSuspendThread (Id : TID) return APIRET;
89 pragma Import (C, DosSuspendThread, "DosSuspendThread");
91 procedure DosWaitThread (Thread_Ptr : PTID; Option : ULONG);
92 pragma Import (C, DosWaitThread, "DosWaitThread");
94 function DosKillThread (Id : TID) return APIRET;
95 pragma Import (C, DosKillThread, "DosKillThread");
98 DCWW_WAIT : constant := 0;
99 DCWW_NOWAIT : constant := 1;
100 -- Values for "Option" parameter in DosWaitThread call
102 ---------------------------------------------------
103 -- Accessing properties of Threads and Processes --
104 ---------------------------------------------------
106 -- Structures translated from BSETIB.H
108 -- Thread Information Block (TIB)
109 -- Need documentation clarifying distinction between TIB, TIB2 ???
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.
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
126 type PTIB2 is access all TIB2;
128 -- Thread Information Block (TIB)
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
139 type PTIB is access all TIB;
141 -- Process Information Block (PIB)
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
153 type PPIB is access all PIB;
155 function DosGetInfoBlocks
156 (Pptib : access PTIB;
159 pragma Import (C, DosGetInfoBlocks, "DosGetInfoBlocks");
161 -- Thread local memory
163 -- This function allocates a block of memory that is unique, or local, to
166 function DosAllocThreadLocalMemory
167 (cb : ULONG; -- Number of 4-byte DWORDs to allocate
168 p : access PVOID) -- Address of the memory block
170 APIRET; -- Return Code (rc)
173 Entity => DosAllocThreadLocalMemory,
174 Link_Name => "_DosAllocThreadLocalMemory");
180 function DosSetPriority
186 pragma Import (C, DosSetPriority, "DosSetPriority");
188 PRTYS_PROCESS : constant := 0;
189 PRTYS_PROCESSTREE : constant := 1;
190 PRTYS_THREAD : constant := 2;
191 -- Values for "Scope" parameter in DosSetPriority call
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
200 end Interfaces.OS2Lib.Threads;