OSDN Git Service

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