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 --
9 -- Copyright (C) 1992-2003, Free Software Foundation, Inc. --
11 -- GNARL 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. GNARL 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 GNARL; 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 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
32 ------------------------------------------------------------------------------
34 -- This is a DEC Unix 4.0d version of this package
36 -- This package contains all the GNULL primitives that interface directly
37 -- with the underlying OS.
40 -- Turn off polling, we do not want ATC polling to take place during
41 -- tasking operations. It causes infinite loops and other problems.
43 with System.Tasking.Debug;
44 -- used for Known_Tasks
46 with System.Task_Info;
47 -- used for Task_Info_Type
50 -- used for Shift_Left
56 with System.Interrupt_Management;
57 -- used for Keep_Unmasked
58 -- Abort_Task_Interrupt
61 with System.Interrupt_Management.Operations;
62 -- used for Set_Interrupt_Mask
64 pragma Elaborate_All (System.Interrupt_Management.Operations);
66 with System.Parameters;
70 -- used for Ada_Task_Control_Block
72 -- ATCB components and types
74 with System.Soft_Links;
75 -- used for Defer/Undefer_Abort
77 -- Note that we do not use System.Tasking.Initialization directly since
78 -- this is a higher level package that we shouldn't depend on. For example
79 -- when using the restricted run time, it is replaced by
80 -- System.Tasking.Restricted.Initialization
82 with System.OS_Primitives;
83 -- used for Delay_Modes
85 with Unchecked_Conversion;
86 with Unchecked_Deallocation;
88 package body System.Task_Primitives.Operations is
90 use System.Tasking.Debug;
93 use System.OS_Interface;
94 use System.Parameters;
95 use System.OS_Primitives;
97 package SSL renames System.Soft_Links;
103 -- The followings are logically constants, but need to be initialized
106 Single_RTS_Lock : aliased RTS_Lock;
107 -- This is a lock to allow only one thread of control in the RTS at
108 -- a time; it is used to execute in mutual exclusion from all other tasks.
109 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
111 ATCB_Key : aliased pthread_key_t;
112 -- Key used to find the Ada Task_ID associated with a thread
114 Environment_Task_ID : Task_ID;
115 -- A variable to hold Task_ID for the environment task.
117 Unblocked_Signal_Mask : aliased sigset_t;
118 -- The set of signals that should unblocked in all tasks
120 Time_Slice_Val : Integer;
121 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
123 Locking_Policy : Character;
124 pragma Import (C, Locking_Policy, "__gl_locking_policy");
126 Dispatching_Policy : Character;
127 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
129 FIFO_Within_Priorities : constant Boolean := Dispatching_Policy = 'F';
130 -- Indicates whether FIFO_Within_Priorities is set.
134 Foreign_Task_Elaborated : aliased Boolean := True;
135 -- Used to identified fake tasks (i.e., non-Ada Threads).
143 procedure Initialize (Environment_Task : Task_ID);
144 pragma Inline (Initialize);
145 -- Initialize various data needed by this package.
147 function Is_Valid_Task return Boolean;
148 pragma Inline (Is_Valid_Task);
149 -- Does executing thread have a TCB?
151 procedure Set (Self_Id : Task_ID);
153 -- Set the self id for the current task.
155 function Self return Task_ID;
156 pragma Inline (Self);
157 -- Return a pointer to the Ada Task Control Block of the calling task.
161 package body Specific is separate;
162 -- The body of this package is target specific.
164 ---------------------------------
165 -- Support for foreign threads --
166 ---------------------------------
168 function Register_Foreign_Thread (Thread : Thread_Id) return Task_ID;
169 -- Allocate and Initialize a new ATCB for the current Thread.
171 function Register_Foreign_Thread
172 (Thread : Thread_Id) return Task_ID is separate;
174 -----------------------
175 -- Local Subprograms --
176 -----------------------
178 procedure Abort_Handler (Sig : Signal);
179 -- Signal handler used to implement asynchronous abortion.
181 function To_Address is new Unchecked_Conversion (Task_ID, System.Address);
187 procedure Abort_Handler (Sig : Signal) is
188 pragma Unreferenced (Sig);
190 T : constant Task_ID := Self;
191 Result : Interfaces.C.int;
192 Old_Set : aliased sigset_t;
195 -- It is not safe to raise an exception when using ZCX and the GCC
196 -- exception handling mechanism.
198 if ZCX_By_Default and then GCC_ZCX_Support then
202 if T.Deferral_Level = 0
203 and then T.Pending_ATC_Level < T.ATC_Nesting_Level and then
208 -- Make sure signals used for RTS internal purpose are unmasked
210 Result := pthread_sigmask (SIG_UNBLOCK,
211 Unblocked_Signal_Mask'Unchecked_Access, Old_Set'Unchecked_Access);
212 pragma Assert (Result = 0);
214 raise Standard'Abort_Signal;
222 -- The underlying thread system sets a guard page at the
223 -- bottom of a thread stack, so nothing is needed.
225 procedure Stack_Guard (T : ST.Task_ID; On : Boolean) is
226 pragma Unreferenced (T);
227 pragma Unreferenced (On);
237 function Get_Thread_Id (T : ST.Task_ID) return OSI.Thread_Id is
239 return T.Common.LL.Thread;
246 function Self return Task_ID renames Specific.Self;
248 ---------------------
249 -- Initialize_Lock --
250 ---------------------
252 -- Note: mutexes and cond_variables needed per-task basis are
253 -- initialized in Initialize_TCB and the Storage_Error is
254 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
255 -- used in RTS is initialized before any status change of RTS.
256 -- Therefore rasing Storage_Error in the following routines
257 -- should be able to be handled safely.
259 procedure Initialize_Lock
260 (Prio : System.Any_Priority;
263 Attributes : aliased pthread_mutexattr_t;
264 Result : Interfaces.C.int;
267 Result := pthread_mutexattr_init (Attributes'Access);
268 pragma Assert (Result = 0 or else Result = ENOMEM);
270 if Result = ENOMEM then
274 if Locking_Policy = 'C' then
275 L.Ceiling := Interfaces.C.int (Prio);
278 Result := pthread_mutex_init (L.L'Access, Attributes'Access);
279 pragma Assert (Result = 0 or else Result = ENOMEM);
281 if Result = ENOMEM then
282 Result := pthread_mutexattr_destroy (Attributes'Access);
286 Result := pthread_mutexattr_destroy (Attributes'Access);
287 pragma Assert (Result = 0);
290 procedure Initialize_Lock (L : access RTS_Lock; Level : Lock_Level) is
291 pragma Unreferenced (Level);
293 Attributes : aliased pthread_mutexattr_t;
294 Result : Interfaces.C.int;
297 Result := pthread_mutexattr_init (Attributes'Access);
298 pragma Assert (Result = 0 or else Result = ENOMEM);
300 if Result = ENOMEM then
304 Result := pthread_mutex_init (L, Attributes'Access);
305 pragma Assert (Result = 0 or else Result = ENOMEM);
307 if Result = ENOMEM then
308 Result := pthread_mutexattr_destroy (Attributes'Access);
312 Result := pthread_mutexattr_destroy (Attributes'Access);
313 pragma Assert (Result = 0);
320 procedure Finalize_Lock (L : access Lock) is
321 Result : Interfaces.C.int;
323 Result := pthread_mutex_destroy (L.L'Access);
324 pragma Assert (Result = 0);
327 procedure Finalize_Lock (L : access RTS_Lock) is
328 Result : Interfaces.C.int;
330 Result := pthread_mutex_destroy (L);
331 pragma Assert (Result = 0);
338 procedure Write_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
339 Result : Interfaces.C.int;
341 All_Tasks_Link : Task_ID;
342 Current_Prio : System.Any_Priority;
345 -- Perform ceiling checks only when this is the locking policy in use.
347 if Locking_Policy = 'C' then
349 All_Tasks_Link := Self_ID.Common.All_Tasks_Link;
350 Current_Prio := Get_Priority (Self_ID);
352 -- If there is no other task, no need to check priorities
354 if All_Tasks_Link /= Null_Task
355 and then L.Ceiling < Interfaces.C.int (Current_Prio)
357 Ceiling_Violation := True;
362 Result := pthread_mutex_lock (L.L'Access);
363 pragma Assert (Result = 0);
365 Ceiling_Violation := False;
369 (L : access RTS_Lock; Global_Lock : Boolean := False)
371 Result : Interfaces.C.int;
373 if not Single_Lock or else Global_Lock then
374 Result := pthread_mutex_lock (L);
375 pragma Assert (Result = 0);
379 procedure Write_Lock (T : Task_ID) is
380 Result : Interfaces.C.int;
382 if not Single_Lock then
383 Result := pthread_mutex_lock (T.Common.LL.L'Access);
384 pragma Assert (Result = 0);
392 procedure Read_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
394 Write_Lock (L, Ceiling_Violation);
401 procedure Unlock (L : access Lock) is
402 Result : Interfaces.C.int;
404 Result := pthread_mutex_unlock (L.L'Access);
405 pragma Assert (Result = 0);
408 procedure Unlock (L : access RTS_Lock; Global_Lock : Boolean := False) is
409 Result : Interfaces.C.int;
411 if not Single_Lock or else Global_Lock then
412 Result := pthread_mutex_unlock (L);
413 pragma Assert (Result = 0);
417 procedure Unlock (T : Task_ID) is
418 Result : Interfaces.C.int;
420 if not Single_Lock then
421 Result := pthread_mutex_unlock (T.Common.LL.L'Access);
422 pragma Assert (Result = 0);
432 Reason : System.Tasking.Task_States)
434 pragma Unreferenced (Reason);
436 Result : Interfaces.C.int;
440 Result := pthread_cond_wait
441 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
443 Result := pthread_cond_wait
444 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
447 -- EINTR is not considered a failure.
449 pragma Assert (Result = 0 or else Result = EINTR);
456 -- This is for use within the run-time system, so abort is
457 -- assumed to be already deferred, and the caller should be
458 -- holding its own ATCB lock.
460 procedure Timed_Sleep
463 Mode : ST.Delay_Modes;
464 Reason : System.Tasking.Task_States;
465 Timedout : out Boolean;
466 Yielded : out Boolean)
468 pragma Unreferenced (Reason);
470 Check_Time : constant Duration := Monotonic_Clock;
472 Request : aliased timespec;
473 Result : Interfaces.C.int;
479 if Mode = Relative then
480 Abs_Time := Duration'Min (Time, Max_Sensible_Delay) + Check_Time;
482 Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time);
485 if Abs_Time > Check_Time then
486 Request := To_Timespec (Abs_Time);
489 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
490 or else Self_ID.Pending_Priority_Change;
493 Result := pthread_cond_timedwait
494 (Self_ID.Common.LL.CV'Access,
495 Single_RTS_Lock'Access,
499 Result := pthread_cond_timedwait
500 (Self_ID.Common.LL.CV'Access,
501 Self_ID.Common.LL.L'Access,
505 exit when Abs_Time <= Monotonic_Clock;
507 if Result = 0 or Result = EINTR then
509 -- Somebody may have called Wakeup for us
515 pragma Assert (Result = ETIMEDOUT);
524 -- This is for use in implementing delay statements, so
525 -- we assume the caller is abort-deferred but is holding
528 procedure Timed_Delay
531 Mode : ST.Delay_Modes)
533 Check_Time : constant Duration := Monotonic_Clock;
535 Request : aliased timespec;
536 Result : Interfaces.C.int;
539 -- Only the little window between deferring abort and
540 -- locking Self_ID is the reason we need to
541 -- check for pending abort and priority change below! :(
549 Write_Lock (Self_ID);
551 if Mode = Relative then
552 Abs_Time := Time + Check_Time;
554 Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time);
557 if Abs_Time > Check_Time then
558 Request := To_Timespec (Abs_Time);
559 Self_ID.Common.State := Delay_Sleep;
562 if Self_ID.Pending_Priority_Change then
563 Self_ID.Pending_Priority_Change := False;
564 Self_ID.Common.Base_Priority := Self_ID.New_Base_Priority;
565 Set_Priority (Self_ID, Self_ID.Common.Base_Priority);
568 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
571 Result := pthread_cond_timedwait
572 (Self_ID.Common.LL.CV'Access,
573 Single_RTS_Lock'Access,
576 Result := pthread_cond_timedwait (Self_ID.Common.LL.CV'Access,
577 Self_ID.Common.LL.L'Access, Request'Access);
580 exit when Abs_Time <= Monotonic_Clock;
582 pragma Assert (Result = 0 or else
583 Result = ETIMEDOUT or else
587 Self_ID.Common.State := Runnable;
597 SSL.Abort_Undefer.all;
600 ---------------------
601 -- Monotonic_Clock --
602 ---------------------
604 function Monotonic_Clock return Duration is
605 TS : aliased timespec;
606 Result : Interfaces.C.int;
609 Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access);
610 pragma Assert (Result = 0);
611 return To_Duration (TS);
618 function RT_Resolution return Duration is
620 return 1.0 / 1024.0; -- Clock on DEC Alpha ticks at 1024 Hz
627 procedure Wakeup (T : Task_ID; Reason : System.Tasking.Task_States) is
628 pragma Unreferenced (Reason);
630 Result : Interfaces.C.int;
633 Result := pthread_cond_signal (T.Common.LL.CV'Access);
634 pragma Assert (Result = 0);
641 procedure Yield (Do_Yield : Boolean := True) is
642 Result : Interfaces.C.int;
645 Result := sched_yield;
653 procedure Set_Priority
655 Prio : System.Any_Priority;
656 Loss_Of_Inheritance : Boolean := False)
658 pragma Unreferenced (Loss_Of_Inheritance);
660 Result : Interfaces.C.int;
661 Param : aliased struct_sched_param;
664 T.Common.Current_Priority := Prio;
665 Param.sched_priority := Interfaces.C.int (Underlying_Priorities (Prio));
667 if Time_Slice_Val > 0 then
668 Result := pthread_setschedparam
669 (T.Common.LL.Thread, SCHED_RR, Param'Access);
671 elsif FIFO_Within_Priorities or else Time_Slice_Val = 0 then
672 Result := pthread_setschedparam
673 (T.Common.LL.Thread, SCHED_FIFO, Param'Access);
676 Result := pthread_setschedparam
677 (T.Common.LL.Thread, SCHED_OTHER, Param'Access);
680 pragma Assert (Result = 0);
687 function Get_Priority (T : Task_ID) return System.Any_Priority is
689 return T.Common.Current_Priority;
696 procedure Enter_Task (Self_ID : Task_ID) is
698 Self_ID.Common.LL.Thread := pthread_self;
699 Specific.Set (Self_ID);
703 for J in Known_Tasks'Range loop
704 if Known_Tasks (J) = null then
705 Known_Tasks (J) := Self_ID;
706 Self_ID.Known_Tasks_Index := J;
718 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_ID is
720 return new Ada_Task_Control_Block (Entry_Num);
727 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
729 -----------------------------
730 -- Register_Foreign_Thread --
731 -----------------------------
733 function Register_Foreign_Thread return Task_ID is
735 if Is_Valid_Task then
738 return Register_Foreign_Thread (pthread_self);
740 end Register_Foreign_Thread;
746 procedure Initialize_TCB (Self_ID : Task_ID; Succeeded : out Boolean) is
747 Mutex_Attr : aliased pthread_mutexattr_t;
748 Result : Interfaces.C.int;
749 Cond_Attr : aliased pthread_condattr_t;
752 if not Single_Lock then
753 Result := pthread_mutexattr_init (Mutex_Attr'Access);
754 pragma Assert (Result = 0 or else Result = ENOMEM);
757 Result := pthread_mutex_init
758 (Self_ID.Common.LL.L'Access, Mutex_Attr'Access);
759 pragma Assert (Result = 0 or else Result = ENOMEM);
767 Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
768 pragma Assert (Result = 0);
771 Result := pthread_condattr_init (Cond_Attr'Access);
772 pragma Assert (Result = 0 or else Result = ENOMEM);
775 Result := pthread_cond_init
776 (Self_ID.Common.LL.CV'Access, Cond_Attr'Access);
777 pragma Assert (Result = 0 or else Result = ENOMEM);
783 if not Single_Lock then
784 Result := pthread_mutex_destroy (Self_ID.Common.LL.L'Access);
785 pragma Assert (Result = 0);
791 Result := pthread_condattr_destroy (Cond_Attr'Access);
792 pragma Assert (Result = 0);
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 Attributes : aliased pthread_attr_t;
807 Adjusted_Stack_Size : Interfaces.C.size_t;
808 Result : Interfaces.C.int;
809 Param : aliased System.OS_Interface.struct_sched_param;
811 function Thread_Body_Access is new
812 Unchecked_Conversion (System.Address, Thread_Body);
814 use System.Task_Info;
817 if Stack_Size = Unspecified_Size then
818 Adjusted_Stack_Size := Interfaces.C.size_t (Default_Stack_Size);
820 elsif Stack_Size < Minimum_Stack_Size then
821 Adjusted_Stack_Size := Interfaces.C.size_t (Minimum_Stack_Size);
824 Adjusted_Stack_Size := Interfaces.C.size_t (Stack_Size);
827 Result := pthread_attr_init (Attributes'Access);
828 pragma Assert (Result = 0 or else Result = ENOMEM);
835 Result := pthread_attr_setdetachstate
836 (Attributes'Access, PTHREAD_CREATE_DETACHED);
837 pragma Assert (Result = 0);
839 Result := pthread_attr_setstacksize
840 (Attributes'Access, Adjusted_Stack_Size);
841 pragma Assert (Result = 0);
843 Param.sched_priority :=
844 Interfaces.C.int (Underlying_Priorities (Priority));
845 Result := pthread_attr_setschedparam
846 (Attributes'Access, Param'Access);
847 pragma Assert (Result = 0);
849 if Time_Slice_Val > 0 then
850 Result := pthread_attr_setschedpolicy
851 (Attributes'Access, System.OS_Interface.SCHED_RR);
853 elsif FIFO_Within_Priorities or else Time_Slice_Val = 0 then
854 Result := pthread_attr_setschedpolicy
855 (Attributes'Access, System.OS_Interface.SCHED_FIFO);
858 Result := pthread_attr_setschedpolicy
859 (Attributes'Access, System.OS_Interface.SCHED_OTHER);
862 pragma Assert (Result = 0);
864 -- Set the scheduling parameters explicitly, since this is the
865 -- only way to force the OS to take e.g. the sched policy and scope
866 -- attributes into account.
868 Result := pthread_attr_setinheritsched
869 (Attributes'Access, PTHREAD_EXPLICIT_SCHED);
870 pragma Assert (Result = 0);
872 T.Common.Current_Priority := Priority;
874 if T.Common.Task_Info /= null then
875 case T.Common.Task_Info.Contention_Scope is
876 when System.Task_Info.Process_Scope =>
877 Result := pthread_attr_setscope
878 (Attributes'Access, PTHREAD_SCOPE_PROCESS);
880 when System.Task_Info.System_Scope =>
881 Result := pthread_attr_setscope
882 (Attributes'Access, PTHREAD_SCOPE_SYSTEM);
884 when System.Task_Info.Default_Scope =>
888 pragma Assert (Result = 0);
891 -- Since the initial signal mask of a thread is inherited from the
892 -- creator, and the Environment task has all its signals masked, we
893 -- do not need to manipulate caller's signal mask at this point.
894 -- All tasks in RTS will have All_Tasks_Mask initially.
896 Result := pthread_create
897 (T.Common.LL.Thread'Access,
899 Thread_Body_Access (Wrapper),
901 pragma Assert (Result = 0 or else Result = EAGAIN);
903 Succeeded := Result = 0;
905 Result := pthread_attr_destroy (Attributes'Access);
906 pragma Assert (Result = 0);
908 if T.Common.Task_Info /= null then
909 -- ??? We're using a process-wide function to implement a task
910 -- specific characteristic.
912 if T.Common.Task_Info.Bind_To_Cpu_Number = 0 then
913 Result := bind_to_cpu (Curpid, 0);
914 elsif T.Common.Task_Info.Bind_To_Cpu_Number > 0 then
915 Result := bind_to_cpu
917 Interfaces.C.unsigned_long (
918 Interfaces.Shift_Left
919 (Interfaces.Unsigned_64'(1),
920 T.Common.Task_Info.Bind_To_Cpu_Number - 1)));
921 pragma Assert (Result = 0);
930 procedure Finalize_TCB (T : Task_ID) is
931 Result : Interfaces.C.int;
933 Is_Self : constant Boolean := T = Self;
935 procedure Free is new
936 Unchecked_Deallocation (Ada_Task_Control_Block, Task_ID);
939 if not Single_Lock then
940 Result := pthread_mutex_destroy (T.Common.LL.L'Access);
941 pragma Assert (Result = 0);
944 Result := pthread_cond_destroy (T.Common.LL.CV'Access);
945 pragma Assert (Result = 0);
947 if T.Known_Tasks_Index /= -1 then
948 Known_Tasks (T.Known_Tasks_Index) := null;
954 Result := pthread_setspecific (ATCB_Key, System.Null_Address);
955 pragma Assert (Result = 0);
964 procedure Exit_Task is
973 procedure Abort_Task (T : Task_ID) is
974 Result : Interfaces.C.int;
980 Signal (System.Interrupt_Management.Abort_Task_Interrupt));
981 pragma Assert (Result = 0);
990 function Check_Exit (Self_ID : ST.Task_ID) return Boolean is
991 pragma Unreferenced (Self_ID);
1001 function Check_No_Locks (Self_ID : ST.Task_ID) return Boolean is
1002 pragma Unreferenced (Self_ID);
1008 ----------------------
1009 -- Environment_Task --
1010 ----------------------
1012 function Environment_Task return Task_ID is
1014 return Environment_Task_ID;
1015 end Environment_Task;
1021 procedure Lock_RTS is
1023 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1030 procedure Unlock_RTS is
1032 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1039 function Suspend_Task
1041 Thread_Self : Thread_Id)
1044 pragma Warnings (Off, T);
1045 pragma Warnings (Off, Thread_Self);
1055 function Resume_Task
1057 Thread_Self : Thread_Id)
1060 pragma Warnings (Off, T);
1061 pragma Warnings (Off, Thread_Self);
1071 procedure Initialize (Environment_Task : Task_ID) is
1072 act : aliased struct_sigaction;
1073 old_act : aliased struct_sigaction;
1074 Tmp_Set : aliased sigset_t;
1075 Result : Interfaces.C.int;
1077 function State (Int : System.Interrupt_Management.Interrupt_ID)
1079 pragma Import (C, State, "__gnat_get_interrupt_state");
1080 -- Get interrupt state. Defined in a-init.c
1081 -- The input argument is the interrupt number,
1082 -- and the result is one of the following:
1084 Default : constant Character := 's';
1085 -- 'n' this interrupt not set by any Interrupt_State pragma
1086 -- 'u' Interrupt_State pragma set state to User
1087 -- 'r' Interrupt_State pragma set state to Runtime
1088 -- 's' Interrupt_State pragma set state to System (use "default"
1092 Environment_Task_ID := Environment_Task;
1094 -- Initialize the lock used to synchronize chain of all ATCBs.
1096 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1098 Specific.Initialize (Environment_Task);
1100 Enter_Task (Environment_Task);
1102 -- Install the abort-signal handler
1104 if State (System.Interrupt_Management.Abort_Task_Interrupt)
1108 act.sa_handler := Abort_Handler'Address;
1110 Result := sigemptyset (Tmp_Set'Access);
1111 pragma Assert (Result = 0);
1112 act.sa_mask := Tmp_Set;
1116 (Signal (System.Interrupt_Management.Abort_Task_Interrupt),
1117 act'Unchecked_Access,
1118 old_act'Unchecked_Access);
1119 pragma Assert (Result = 0);
1125 Result : Interfaces.C.int;
1128 -- Mask Environment task for all signals. The original mask of the
1129 -- Environment task will be recovered by Interrupt_Server task
1130 -- during the elaboration of s-interr.adb.
1132 System.Interrupt_Management.Operations.Set_Interrupt_Mask
1133 (System.Interrupt_Management.Operations.All_Tasks_Mask'Access);
1135 -- Prepare the set of signals that should unblocked in all tasks
1137 Result := sigemptyset (Unblocked_Signal_Mask'Access);
1138 pragma Assert (Result = 0);
1140 for J in Interrupt_Management.Interrupt_ID loop
1141 if System.Interrupt_Management.Keep_Unmasked (J) then
1142 Result := sigaddset (Unblocked_Signal_Mask'Access, Signal (J));
1143 pragma Assert (Result = 0);
1149 end System.Task_Primitives.Operations;