1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . T A S K _ P R I M I T I V E S . O P E R A T I O N S --
11 -- Copyright (C) 1991-2001 Florida State University --
13 -- GNARL 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. GNARL 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 GNARL; 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 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
37 -- This is an OS/2 version of this package
39 -- This package contains all the GNULL primitives that interface directly
40 -- with the underlying OS.
43 -- Turn off polling, we do not want ATC polling to take place during
44 -- tasking operations. It causes infinite loops and other problems.
46 with System.Tasking.Debug;
47 -- used for Known_Tasks
52 with Interfaces.C.Strings;
55 with Interfaces.OS2Lib.Errors;
56 with Interfaces.OS2Lib.Threads;
57 with Interfaces.OS2Lib.Synchronization;
59 with System.Parameters;
65 with System.Parameters;
68 with System.Soft_Links;
69 -- used for Defer/Undefer_Abort
71 -- Note that we do not use System.Tasking.Initialization directly since
72 -- this is a higher level package that we shouldn't depend on. For example
73 -- when using the restricted run time, it is replaced by
74 -- System.Tasking.Restricted.Initialization
76 with System.OS_Primitives;
77 -- used for Delay_Modes
80 with Unchecked_Conversion;
81 with Unchecked_Deallocation;
83 package body System.Task_Primitives.Operations is
85 package IC renames Interfaces.C;
86 package ICS renames Interfaces.C.Strings;
87 package OSP renames System.OS_Primitives;
88 package SSL renames System.Soft_Links;
90 use Interfaces.OS2Lib;
91 use Interfaces.OS2Lib.Errors;
92 use Interfaces.OS2Lib.Threads;
93 use Interfaces.OS2Lib.Synchronization;
94 use System.Tasking.Debug;
96 use System.OS_Interface;
98 use System.OS_Primitives;
100 ----------------------
101 -- Local Constants --
102 ----------------------
104 Max_Locks_Per_Task : constant := 100;
105 Suppress_Owner_Check : constant Boolean := False;
111 type Microseconds is new IC.long;
112 subtype Lock_Range is Integer range 0 .. Max_Locks_Per_Task;
118 -- The OS/2 DosAllocThreadLocalMemory API is used to allocate our TCB_Ptr.
120 -- This API reserves a small range of virtual addresses that is backed
121 -- by different physical memory for each running thread. In this case we
122 -- create a pointer at a fixed address that points to the TCB_Ptr for the
123 -- running thread. So all threads will be able to query and update their
124 -- own TCB_Ptr without destroying the TCB_Ptr of other threads.
126 type Thread_Local_Data is record
127 Self_ID : Task_ID; -- ID of the current thread
128 Lock_Prio_Level : Lock_Range; -- Nr of priority changes due to locks
130 -- ... room for expansion here, if we decide to make access to
131 -- jump-buffer and exception stack more efficient in future
134 type Access_Thread_Local_Data is access all Thread_Local_Data;
136 -- Pointer to Thread Local Data
137 Thread_Local_Data_Ptr : aliased Access_Thread_Local_Data;
139 type PPTLD is access all Access_Thread_Local_Data;
141 All_Tasks_L : aliased System.Task_Primitives.RTS_Lock;
142 -- See comments on locking rules in System.Tasking (spec).
144 Environment_Task_ID : Task_ID;
145 -- A variable to hold Task_ID for the environment task.
147 -----------------------
148 -- Local Subprograms --
149 -----------------------
151 function To_PPVOID is new Unchecked_Conversion (PPTLD, PPVOID);
152 function To_Address is new Unchecked_Conversion (Task_ID, System.Address);
153 function To_PFNTHREAD is
154 new Unchecked_Conversion (System.Address, PFNTHREAD);
156 function To_MS (D : Duration) return ULONG;
158 procedure Set_Temporary_Priority
160 New_Priority : in System.Any_Priority);
166 function To_MS (D : Duration) return ULONG is
168 return ULONG (D * 1_000);
175 function Monotonic_Clock return Duration renames OSP.Monotonic_Clock;
181 function RT_Resolution return Duration is
190 -- OS/2 only has limited support for asynchronous signals.
191 -- It seems not to be possible to jump out of an exception
192 -- handler or to change the execution context of the thread.
193 -- So asynchonous transfer of control is not supported.
199 -- The underlying thread system sets a guard page at the
200 -- bottom of a thread stack, so nothing is needed.
201 -- ??? Check the comment above
203 procedure Stack_Guard (T : ST.Task_ID; On : Boolean) is
212 function Get_Thread_Id (T : ST.Task_ID) return OSI.Thread_Id is
214 return OSI.Thread_Id (T.Common.LL.Thread);
221 function Self return Task_ID is
222 Self_ID : Task_ID renames Thread_Local_Data_Ptr.Self_ID;
225 -- Check that the thread local data has been initialized.
228 ((Thread_Local_Data_Ptr /= null
229 and then Thread_Local_Data_Ptr.Self_ID /= null));
234 ---------------------
235 -- Initialize_Lock --
236 ---------------------
238 procedure Initialize_Lock
239 (Prio : System.Any_Priority;
244 (ICS.Null_Ptr, L.Mutex'Unchecked_Access, 0, False32) /= NO_ERROR
249 pragma Assert (L.Mutex /= 0, "Error creating Mutex");
251 L.Owner_ID := Null_Address;
254 procedure Initialize_Lock (L : access RTS_Lock; Level : Lock_Level) is
257 (ICS.Null_Ptr, L.Mutex'Unchecked_Access, 0, False32) /= NO_ERROR
262 pragma Assert (L.Mutex /= 0, "Error creating Mutex");
264 L.Priority := System.Any_Priority'Last;
265 L.Owner_ID := Null_Address;
272 procedure Finalize_Lock (L : access Lock) is
274 Must_Not_Fail (DosCloseMutexSem (L.Mutex));
277 procedure Finalize_Lock (L : access RTS_Lock) is
279 Must_Not_Fail (DosCloseMutexSem (L.Mutex));
286 procedure Write_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
287 Self_ID : constant Task_ID := Thread_Local_Data_Ptr.Self_ID;
288 Old_Priority : constant Any_Priority :=
289 Self_ID.Common.LL.Current_Priority;
292 if L.Priority < Old_Priority then
293 Ceiling_Violation := True;
297 Ceiling_Violation := False;
299 -- Increase priority before getting the lock
300 -- to prevent priority inversion
302 Thread_Local_Data_Ptr.Lock_Prio_Level :=
303 Thread_Local_Data_Ptr.Lock_Prio_Level + 1;
304 if L.Priority > Old_Priority then
305 Set_Temporary_Priority (Self_ID, L.Priority);
308 -- Request the lock and then update the lock owner data
310 Must_Not_Fail (DosRequestMutexSem (L.Mutex, SEM_INDEFINITE_WAIT));
311 L.Owner_Priority := Old_Priority;
312 L.Owner_ID := Self_ID.all'Address;
315 procedure Write_Lock (L : access RTS_Lock) is
316 Self_ID : constant Task_ID := Thread_Local_Data_Ptr.Self_ID;
317 Old_Priority : constant Any_Priority :=
318 Self_ID.Common.LL.Current_Priority;
321 -- Increase priority before getting the lock
322 -- to prevent priority inversion
324 Thread_Local_Data_Ptr.Lock_Prio_Level :=
325 Thread_Local_Data_Ptr.Lock_Prio_Level + 1;
327 if L.Priority > Old_Priority then
328 Set_Temporary_Priority (Self_ID, L.Priority);
331 -- Request the lock and then update the lock owner data
333 Must_Not_Fail (DosRequestMutexSem (L.Mutex, SEM_INDEFINITE_WAIT));
334 L.Owner_Priority := Old_Priority;
335 L.Owner_ID := Self_ID.all'Address;
338 procedure Write_Lock (T : Task_ID) is
340 -- Request the lock and then update the lock owner data
343 (DosRequestMutexSem (T.Common.LL.L.Mutex, SEM_INDEFINITE_WAIT));
344 T.Common.LL.L.Owner_ID := Null_Address;
351 procedure Read_Lock (L : access Lock; Ceiling_Violation : out Boolean)
358 procedure Unlock (L : access Lock) is
359 Self_ID : constant Task_ID := Thread_Local_Data_Ptr.Self_ID;
360 Old_Priority : constant Any_Priority := L.Owner_Priority;
363 -- Check that this task holds the lock
365 pragma Assert (Suppress_Owner_Check
366 or else L.Owner_ID = Self_ID.all'Address);
368 -- Upate the owner data
370 L.Owner_ID := Null_Address;
372 -- Do the actual unlocking. No more references
373 -- to owner data of L after this point.
375 Must_Not_Fail (DosReleaseMutexSem (L.Mutex));
377 -- Reset priority after unlocking to avoid priority inversion
379 Thread_Local_Data_Ptr.Lock_Prio_Level :=
380 Thread_Local_Data_Ptr.Lock_Prio_Level - 1;
381 if L.Priority /= Old_Priority then
382 Set_Temporary_Priority (Self_ID, Old_Priority);
386 procedure Unlock (L : access RTS_Lock) is
387 Self_ID : constant Task_ID := Thread_Local_Data_Ptr.Self_ID;
388 Old_Priority : constant Any_Priority := L.Owner_Priority;
391 -- Check that this task holds the lock
393 pragma Assert (Suppress_Owner_Check
394 or else L.Owner_ID = Self_ID.all'Address);
396 -- Upate the owner data
398 L.Owner_ID := Null_Address;
400 -- Do the actual unlocking. No more references
401 -- to owner data of L after this point.
403 Must_Not_Fail (DosReleaseMutexSem (L.Mutex));
405 -- Reset priority after unlocking to avoid priority inversion
406 Thread_Local_Data_Ptr.Lock_Prio_Level :=
407 Thread_Local_Data_Ptr.Lock_Prio_Level - 1;
409 if L.Priority /= Old_Priority then
410 Set_Temporary_Priority (Self_ID, Old_Priority);
414 procedure Unlock (T : Task_ID) is
416 -- Check the owner data
418 pragma Assert (Suppress_Owner_Check
419 or else T.Common.LL.L.Owner_ID = Null_Address);
421 -- Do the actual unlocking. No more references
422 -- to owner data of T.Common.LL.L after this point.
424 Must_Not_Fail (DosReleaseMutexSem (T.Common.LL.L.Mutex));
431 procedure Sleep (Self_ID : Task_ID;
432 Reason : System.Tasking.Task_States) is
433 Count : aliased ULONG; -- Used to store dummy result
436 -- Must reset Cond BEFORE L is unlocked.
439 (DosResetEventSem (Self_ID.Common.LL.CV, Count'Unchecked_Access));
442 -- No problem if we are interrupted here.
443 -- If the condition is signaled, DosWaitEventSem will simply not block.
446 (DosWaitEventSem (Self_ID.Common.LL.CV, SEM_INDEFINITE_WAIT));
448 -- Since L was previously accquired, lock operation should not fail.
450 Write_Lock (Self_ID);
457 -- This is for use within the run-time system, so abort is
458 -- assumed to be already deferred, and the caller should be
459 -- holding its own ATCB lock.
461 -- Pre-assertion: Cond is posted
464 -- Post-assertion: Cond is posted
467 procedure Timed_Sleep
470 Mode : ST.Delay_Modes;
471 Reason : System.Tasking.Task_States;
472 Timedout : out Boolean;
473 Yielded : out Boolean)
475 Check_Time : constant Duration := OSP.Monotonic_Clock;
480 Count : aliased ULONG; -- Used to store dummy result
483 -- Must reset Cond BEFORE Self_ID is unlocked.
486 (DosResetEventSem (Self_ID.Common.LL.CV,
487 Count'Unchecked_Access));
493 if Mode = Relative then
495 Abs_Time := Duration'Min (Time, Max_Sensible_Delay) + Check_Time;
497 Rel_Time := Time - Check_Time;
501 if Rel_Time > 0.0 then
503 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
504 or else Self_ID.Pending_Priority_Change;
506 Time_Out := To_MS (Rel_Time);
507 Result := DosWaitEventSem (Self_ID.Common.LL.CV, Time_Out);
509 ((Result = NO_ERROR or Result = ERROR_TIMEOUT
510 or Result = ERROR_INTERRUPT));
513 -- What to do with error condition ERROR_NOT_ENOUGH_MEMORY? Can
514 -- we raise an exception here? And what about ERROR_INTERRUPT?
515 -- Should that be treated as a simple timeout?
516 -- For now, consider only ERROR_TIMEOUT to be a timeout.
518 exit when Abs_Time <= OSP.Monotonic_Clock;
520 if Result /= ERROR_TIMEOUT then
521 -- somebody may have called Wakeup for us
526 Rel_Time := Abs_Time - OSP.Monotonic_Clock;
530 -- Ensure post-condition
532 Write_Lock (Self_ID);
535 Sem_Must_Not_Fail (DosPostEventSem (Self_ID.Common.LL.CV));
543 procedure Timed_Delay
546 Mode : ST.Delay_Modes)
548 Check_Time : constant Duration := OSP.Monotonic_Clock;
551 Timedout : Boolean := True;
554 Count : aliased ULONG; -- Used to store dummy result
557 -- Only the little window between deferring abort and
558 -- locking Self_ID is the reason we need to
559 -- check for pending abort and priority change below! :(
562 Write_Lock (Self_ID);
564 -- Must reset Cond BEFORE Self_ID is unlocked.
567 (DosResetEventSem (Self_ID.Common.LL.CV,
568 Count'Unchecked_Access));
571 if Mode = Relative then
573 Abs_Time := Time + Check_Time;
575 Rel_Time := Time - Check_Time;
579 if Rel_Time > 0.0 then
580 Self_ID.Common.State := Delay_Sleep;
582 if Self_ID.Pending_Priority_Change then
583 Self_ID.Pending_Priority_Change := False;
584 Self_ID.Common.Base_Priority := Self_ID.New_Base_Priority;
585 Set_Priority (Self_ID, Self_ID.Common.Base_Priority);
588 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
590 Time_Out := To_MS (Rel_Time);
591 Result := DosWaitEventSem (Self_ID.Common.LL.CV, Time_Out);
593 exit when Abs_Time <= OSP.Monotonic_Clock;
595 Rel_Time := Abs_Time - OSP.Monotonic_Clock;
598 Self_ID.Common.State := Runnable;
599 Timedout := Result = ERROR_TIMEOUT;
602 -- Ensure post-condition
604 Write_Lock (Self_ID);
607 Sem_Must_Not_Fail (DosPostEventSem (Self_ID.Common.LL.CV));
611 System.OS_Interface.Yield;
612 SSL.Abort_Undefer.all;
619 procedure Wakeup (T : Task_ID; Reason : System.Tasking.Task_States) is
621 Sem_Must_Not_Fail (DosPostEventSem (T.Common.LL.CV));
628 procedure Yield (Do_Yield : Boolean := True) is
631 System.OS_Interface.Yield;
635 ----------------------------
636 -- Set_Temporary_Priority --
637 ----------------------------
639 procedure Set_Temporary_Priority
641 New_Priority : System.Any_Priority)
644 Delta_Priority : Integer;
647 -- When Lock_Prio_Level = 0, we always need to set the
648 -- Active_Priority. In this way we can make priority changes
649 -- due to locking independent of those caused by calling
652 if Thread_Local_Data_Ptr.Lock_Prio_Level = 0
653 or else New_Priority < T.Common.Current_Priority
655 Delta_Priority := T.Common.Current_Priority -
656 T.Common.LL.Current_Priority;
658 Delta_Priority := New_Priority - T.Common.LL.Current_Priority;
661 if Delta_Priority /= 0 then
663 -- ??? There is a race-condition here
664 -- The TCB is updated before the system call to make
665 -- pre-emption in the critical section less likely.
667 T.Common.LL.Current_Priority :=
668 T.Common.LL.Current_Priority + Delta_Priority;
670 (DosSetPriority (Scope => PRTYS_THREAD,
671 Class => PRTYC_NOCHANGE,
672 Delta_P => IC.long (Delta_Priority),
673 PorTid => T.Common.LL.Thread));
675 end Set_Temporary_Priority;
681 procedure Set_Priority
683 Prio : System.Any_Priority;
684 Loss_Of_Inheritance : Boolean := False) is
686 T.Common.Current_Priority := Prio;
687 Set_Temporary_Priority (T, Prio);
694 function Get_Priority (T : Task_ID) return System.Any_Priority is
696 return T.Common.Current_Priority;
703 procedure Enter_Task (Self_ID : Task_ID) is
706 -- Initialize thread local data. Must be done first.
708 Thread_Local_Data_Ptr.Self_ID := Self_ID;
709 Thread_Local_Data_Ptr.Lock_Prio_Level := 0;
712 for I in Known_Tasks'Range loop
713 if Known_Tasks (I) = null then
714 Known_Tasks (I) := Self_ID;
715 Self_ID.Known_Tasks_Index := I;
719 Unlock_All_Tasks_List;
721 -- For OS/2, we can set Self_ID.Common.LL.Thread in
722 -- Create_Task, since the thread is created suspended.
723 -- That is, there is no danger of the thread racing ahead
724 -- and trying to reference Self_ID.Common.LL.Thread before it
725 -- has been initialized.
727 -- .... Do we need to do anything with signals for OS/2 ???
735 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_ID is
737 return new Ada_Task_Control_Block (Entry_Num);
740 ----------------------
742 ----------------------
744 procedure Initialize_TCB (Self_ID : Task_ID; Succeeded : out Boolean) is
746 if DosCreateEventSem (ICS.Null_Ptr,
747 Self_ID.Common.LL.CV'Unchecked_Access, 0, True32) = NO_ERROR
749 if DosCreateMutexSem (ICS.Null_Ptr,
750 Self_ID.Common.LL.L.Mutex'Unchecked_Access, 0, False32) /= NO_ERROR
753 Must_Not_Fail (DosCloseEventSem (Self_ID.Common.LL.CV));
758 pragma Assert (Self_ID.Common.LL.L.Mutex /= 0);
760 -- We now want to do the equivalent of:
763 -- (Self_ID.Common.LL.L'Unchecked_Access, ATCB_Level);
765 -- But we avoid that because the Initialize_TCB routine has an
766 -- exception handler, and it is too early for us to deal with
767 -- installing handlers (see comment below), so we do our own
768 -- Initialize_Lock operation manually.
770 Self_ID.Common.LL.L.Priority := System.Any_Priority'Last;
771 Self_ID.Common.LL.L.Owner_ID := Null_Address;
777 -- Note: at one time we had anb exception handler here, whose code
782 -- Assumes any failure must be due to insufficient resources
784 -- when Storage_Error =>
785 -- Must_Not_Fail (DosCloseEventSem (Self_ID.Common.LL.CV));
786 -- Succeeded := False;
788 -- but that won't work with the old exception scheme, since it would
789 -- result in messing with Jmpbuf values too early. If and when we get
790 -- switched entirely to the new zero-cost exception scheme, we could
791 -- put this handler back in!
799 procedure Create_Task
801 Wrapper : System.Address;
802 Stack_Size : System.Parameters.Size_Type;
803 Priority : System.Any_Priority;
804 Succeeded : out Boolean)
806 Result : aliased APIRET;
807 Adjusted_Stack_Size : System.Parameters.Size_Type;
808 use System.Parameters;
811 -- In OS/2 the allocated stack size should be based on the
812 -- amount of address space that should be reserved for the stack.
813 -- Actual memory will only be used when the stack is touched anyway.
815 -- The new minimum size is 12 kB, although the EMX docs
816 -- recommend a minimum size of 32 kB. (The original was 4 kB)
817 -- Systems that use many tasks (say > 30) and require much
818 -- memory may run out of virtual address space, since OS/2
819 -- has a per-process limit of 512 MB, of which max. 300 MB is
820 -- usable in practise.
822 if Stack_Size = Unspecified_Size then
823 Adjusted_Stack_Size := Default_Stack_Size;
825 elsif Stack_Size < Minimum_Stack_Size then
826 Adjusted_Stack_Size := Minimum_Stack_Size;
829 Adjusted_Stack_Size := Stack_Size;
833 -- Because DosCreateThread is called directly here, the
834 -- C RTL doesn't get initialized for the new thead. EMX by
835 -- default uses per-thread local heaps in addition to the
836 -- global heap. There might be other effects of by-passing the
839 -- When using _beginthread the newly created thread is not
840 -- blocked initially. Does this matter or can I create the
841 -- thread running anyway? The LL.Thread variable will be set
842 -- anyway because the variable is passed by reference to OS/2.
844 T.Common.LL.Wrapper := To_PFNTHREAD (Wrapper);
846 -- The OS implicitly gives the new task the priority of this task.
848 T.Common.LL.Current_Priority := Self.Common.LL.Current_Priority;
850 -- If task was locked before activator task was
851 -- initialized, assume it has OS standard priority
853 if T.Common.LL.L.Owner_Priority not in Any_Priority'Range then
854 T.Common.LL.L.Owner_Priority := 1;
857 -- Create the thread, in blocked mode
859 Result := DosCreateThread
860 (F_ptid => T.Common.LL.Thread'Unchecked_Access,
861 pfn => T.Common.LL.Wrapper,
862 param => To_Address (T),
863 flag => Block_Child + Commit_Stack,
864 cbStack => ULONG (Adjusted_Stack_Size));
866 Succeeded := (Result = NO_ERROR);
868 if not Succeeded then
872 -- Set the new thread's priority
873 -- (child has inherited priority from parent)
875 Set_Priority (T, Priority);
877 -- Start the thread executing
879 Must_Not_Fail (DosResumeThread (T.Common.LL.Thread));
887 procedure Finalize_TCB (T : Task_ID) is
890 procedure Free is new
891 Unchecked_Deallocation (Ada_Task_Control_Block, Task_ID);
893 Must_Not_Fail (DosCloseEventSem (T.Common.LL.CV));
894 Finalize_Lock (T.Common.LL.L'Unchecked_Access);
895 if T.Known_Tasks_Index /= -1 then
896 Known_Tasks (T.Known_Tasks_Index) := null;
905 procedure Exit_Task is
907 DosExit (EXIT_THREAD, 0);
909 -- Do not finalize TCB here.
910 -- GNARL layer is responsible for that.
918 procedure Abort_Task (T : Task_ID) is
922 -- Task abortion not implemented yet.
923 -- Should perform other action ???
931 -- Dummy versions. The only currently working versions is for solaris
934 function Check_Exit (Self_ID : ST.Task_ID) return Boolean is
936 return Check_No_Locks (Self_ID);
943 function Check_No_Locks (Self_ID : ST.Task_ID) return Boolean is
944 TLD : constant Access_Thread_Local_Data := Thread_Local_Data_Ptr;
946 return Self_ID = TLD.Self_ID
947 and then TLD.Lock_Prio_Level = 0;
950 ----------------------
951 -- Environment_Task --
952 ----------------------
954 function Environment_Task return Task_ID is
956 return Environment_Task_ID;
957 end Environment_Task;
959 -------------------------
960 -- Lock_All_Tasks_List --
961 -------------------------
963 procedure Lock_All_Tasks_List is
965 Write_Lock (All_Tasks_L'Access);
966 end Lock_All_Tasks_List;
968 ---------------------------
969 -- Unlock_All_Tasks_List --
970 ---------------------------
972 procedure Unlock_All_Tasks_List is
974 Unlock (All_Tasks_L'Access);
975 end Unlock_All_Tasks_List;
981 function Suspend_Task
983 Thread_Self : Thread_Id) return Boolean is
985 if Thread_Id (T.Common.LL.Thread) /= Thread_Self then
986 return DosSuspendThread (T.Common.LL.Thread) = NO_ERROR;
998 Thread_Self : Thread_Id) return Boolean is
1000 if Thread_Id (T.Common.LL.Thread) /= Thread_Self then
1001 return DosResumeThread (T.Common.LL.Thread) = NO_ERROR;
1011 procedure Initialize (Environment_Task : Task_ID) is
1012 Succeeded : Boolean;
1015 Environment_Task_ID := Environment_Task;
1017 Initialize_Lock (All_Tasks_L'Access, All_Tasks_Level);
1018 -- Initialize the lock used to synchronize chain of all ATCBs.
1020 -- Set ID of environment task.
1022 Thread_Local_Data_Ptr.Self_ID := Environment_Task;
1023 Environment_Task.Common.LL.Thread := 1; -- By definition
1025 -- This priority is unknown in fact.
1026 -- If actual current priority is different,
1027 -- it will get synchronized later on anyway.
1029 Environment_Task.Common.LL.Current_Priority :=
1030 Environment_Task.Common.Current_Priority;
1032 -- Initialize TCB for this task.
1033 -- This includes all the normal task-external initialization.
1034 -- This is also done by Initialize_ATCB, why ???
1036 Initialize_TCB (Environment_Task, Succeeded);
1038 -- Consider raising Storage_Error,
1039 -- if propagation can be tolerated ???
1041 pragma Assert (Succeeded);
1043 -- Do normal task-internal initialization,
1044 -- which depends on an initialized TCB.
1046 Enter_Task (Environment_Task);
1048 -- Insert here any other special
1049 -- initialization needed for the environment task.
1054 -- Initialize pointer to task local data.
1055 -- This is done once, for all tasks.
1057 Must_Not_Fail (DosAllocThreadLocalMemory
1058 ((Thread_Local_Data'Size + 31) / 32, -- nr of 32-bit words
1059 To_PPVOID (Thread_Local_Data_Ptr'Access)));
1061 -- Initialize thread local data for main thread
1063 Thread_Local_Data_Ptr.Self_ID := null;
1064 Thread_Local_Data_Ptr.Lock_Prio_Level := 0;
1066 end System.Task_Primitives.Operations;