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-2007, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 GNU/Linux (GNU/LinuxThreads) 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.
47 with System.Tasking.Debug;
48 -- used for Known_Tasks
50 with System.Interrupt_Management;
51 -- used for Keep_Unmasked
52 -- Abort_Task_Interrupt
55 with System.OS_Primitives;
56 -- used for Delay_Modes
58 with System.Soft_Links;
59 -- used for Abort_Defer/Undefer
61 -- We use System.Soft_Links instead of System.Tasking.Initialization
62 -- because the later is a higher level package that we shouldn't depend on.
63 -- For example when using the restricted run time, it is replaced by
64 -- System.Tasking.Restricted.Stages.
66 with System.Stack_Checking.Operations;
67 -- Used for Invalidate_Stack_Cache;
70 -- used for Raise_Exception
71 -- Raise_From_Signal_Handler
74 with Ada.Unchecked_Conversion;
75 with Ada.Unchecked_Deallocation;
77 package body System.Task_Primitives.Operations is
79 package SSL renames System.Soft_Links;
80 package SC renames System.Stack_Checking.Operations;
82 use System.Tasking.Debug;
85 use System.OS_Interface;
86 use System.Parameters;
87 use System.OS_Primitives;
93 -- The followings are logically constants, but need to be initialized
96 Single_RTS_Lock : aliased RTS_Lock;
97 -- This is a lock to allow only one thread of control in the RTS at
98 -- a time; it is used to execute in mutual exclusion from all other tasks.
99 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
101 ATCB_Key : aliased pthread_key_t;
102 -- Key used to find the Ada Task_Id associated with a thread
104 Environment_Task_Id : Task_Id;
105 -- A variable to hold Task_Id for the environment task
107 Unblocked_Signal_Mask : aliased sigset_t;
108 -- The set of signals that should be unblocked in all tasks
110 -- The followings are internal configuration constants needed
112 Next_Serial_Number : Task_Serial_Number := 100;
113 -- We start at 100 (reserve some special values for using in error checks)
115 Time_Slice_Val : Integer;
116 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
118 Dispatching_Policy : Character;
119 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
121 -- The following are effectively constants, but they need to be initialized
122 -- by calling a pthread_ function.
124 Mutex_Attr : aliased pthread_mutexattr_t;
125 Cond_Attr : aliased pthread_condattr_t;
127 Foreign_Task_Elaborated : aliased Boolean := True;
128 -- Used to identified fake tasks (i.e., non-Ada Threads)
136 procedure Initialize (Environment_Task : Task_Id);
137 pragma Inline (Initialize);
138 -- Initialize various data needed by this package
140 function Is_Valid_Task return Boolean;
141 pragma Inline (Is_Valid_Task);
142 -- Does executing thread have a TCB?
144 procedure Set (Self_Id : Task_Id);
146 -- Set the self id for the current task
148 function Self return Task_Id;
149 pragma Inline (Self);
150 -- Return a pointer to the Ada Task Control Block of the calling task
154 package body Specific is separate;
155 -- The body of this package is target specific
157 ---------------------------------
158 -- Support for foreign threads --
159 ---------------------------------
161 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
162 -- Allocate and Initialize a new ATCB for the current Thread
164 function Register_Foreign_Thread
165 (Thread : Thread_Id) return Task_Id is separate;
167 -----------------------
168 -- Local Subprograms --
169 -----------------------
171 subtype unsigned_long is Interfaces.C.unsigned_long;
173 procedure Abort_Handler (signo : Signal);
175 function To_pthread_t is new Ada.Unchecked_Conversion
176 (unsigned_long, System.OS_Interface.pthread_t);
182 procedure Abort_Handler (signo : Signal) is
183 pragma Unreferenced (signo);
185 Self_Id : constant Task_Id := Self;
186 Result : Interfaces.C.int;
187 Old_Set : aliased sigset_t;
190 if ZCX_By_Default and then GCC_ZCX_Support then
194 if Self_Id.Deferral_Level = 0
195 and then Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level
196 and then not Self_Id.Aborting
198 Self_Id.Aborting := True;
200 -- Make sure signals used for RTS internal purpose are unmasked
205 Unblocked_Signal_Mask'Unchecked_Access,
206 Old_Set'Unchecked_Access);
207 pragma Assert (Result = 0);
209 raise Standard'Abort_Signal;
217 procedure Lock_RTS is
219 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
226 procedure Unlock_RTS is
228 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
235 -- The underlying thread system extends the memory (up to 2MB) when needed
237 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
238 pragma Unreferenced (T);
239 pragma Unreferenced (On);
248 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
250 return T.Common.LL.Thread;
257 function Self return Task_Id renames Specific.Self;
259 ---------------------
260 -- Initialize_Lock --
261 ---------------------
263 -- Note: mutexes and cond_variables needed per-task basis are
264 -- initialized in Initialize_TCB and the Storage_Error is
265 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
266 -- used in RTS is initialized before any status change of RTS.
267 -- Therefore rasing Storage_Error in the following routines
268 -- should be able to be handled safely.
270 procedure Initialize_Lock
271 (Prio : System.Any_Priority;
272 L : not null access Lock)
274 pragma Unreferenced (Prio);
276 Result : Interfaces.C.int;
279 Result := pthread_mutex_init (L, Mutex_Attr'Access);
281 pragma Assert (Result = 0 or else Result = ENOMEM);
283 if Result = ENOMEM then
284 Ada.Exceptions.Raise_Exception (Storage_Error'Identity,
285 "Failed to allocate a lock");
289 procedure Initialize_Lock
290 (L : not null access RTS_Lock;
293 pragma Unreferenced (Level);
295 Result : Interfaces.C.int;
298 Result := pthread_mutex_init (L, Mutex_Attr'Access);
300 pragma Assert (Result = 0 or else Result = ENOMEM);
302 if Result = ENOMEM then
311 procedure Finalize_Lock (L : not null access Lock) is
312 Result : Interfaces.C.int;
314 Result := pthread_mutex_destroy (L);
315 pragma Assert (Result = 0);
318 procedure Finalize_Lock (L : not null access RTS_Lock) is
319 Result : Interfaces.C.int;
321 Result := pthread_mutex_destroy (L);
322 pragma Assert (Result = 0);
330 (L : not null access Lock;
331 Ceiling_Violation : out Boolean)
333 Result : Interfaces.C.int;
335 Result := pthread_mutex_lock (L);
336 Ceiling_Violation := Result = EINVAL;
338 -- Assume the cause of EINVAL is a priority ceiling violation
340 pragma Assert (Result = 0 or else Result = EINVAL);
344 (L : not null access RTS_Lock;
345 Global_Lock : Boolean := False)
347 Result : Interfaces.C.int;
349 if not Single_Lock or else Global_Lock then
350 Result := pthread_mutex_lock (L);
351 pragma Assert (Result = 0);
355 procedure Write_Lock (T : Task_Id) is
356 Result : Interfaces.C.int;
358 if not Single_Lock then
359 Result := pthread_mutex_lock (T.Common.LL.L'Access);
360 pragma Assert (Result = 0);
369 (L : not null access Lock;
370 Ceiling_Violation : out Boolean)
373 Write_Lock (L, Ceiling_Violation);
380 procedure Unlock (L : not null access Lock) is
381 Result : Interfaces.C.int;
383 Result := pthread_mutex_unlock (L);
384 pragma Assert (Result = 0);
388 (L : not null access RTS_Lock;
389 Global_Lock : Boolean := False)
391 Result : Interfaces.C.int;
393 if not Single_Lock or else Global_Lock then
394 Result := pthread_mutex_unlock (L);
395 pragma Assert (Result = 0);
399 procedure Unlock (T : Task_Id) is
400 Result : Interfaces.C.int;
402 if not Single_Lock then
403 Result := pthread_mutex_unlock (T.Common.LL.L'Access);
404 pragma Assert (Result = 0);
412 -- Dynamic priority ceilings are not supported by the underlying system
414 procedure Set_Ceiling
415 (L : not null access Lock;
416 Prio : System.Any_Priority)
418 pragma Unreferenced (L, Prio);
429 Reason : System.Tasking.Task_States)
431 pragma Unreferenced (Reason);
433 Result : Interfaces.C.int;
436 pragma Assert (Self_ID = Self);
441 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
445 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
448 -- EINTR is not considered a failure
450 pragma Assert (Result = 0 or else Result = EINTR);
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 procedure Timed_Sleep
464 Mode : ST.Delay_Modes;
465 Reason : System.Tasking.Task_States;
466 Timedout : out Boolean;
467 Yielded : out Boolean)
469 pragma Unreferenced (Reason);
471 Base_Time : constant Duration := Monotonic_Clock;
472 Check_Time : Duration := Base_Time;
474 Request : aliased timespec;
475 Result : Interfaces.C.int;
481 if Mode = Relative then
482 Abs_Time := Duration'Min (Time, Max_Sensible_Delay) + Check_Time;
484 Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time);
487 if Abs_Time > Check_Time then
488 Request := To_Timespec (Abs_Time);
491 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
495 pthread_cond_timedwait
496 (Self_ID.Common.LL.CV'Access,
497 Single_RTS_Lock'Access,
502 pthread_cond_timedwait
503 (Self_ID.Common.LL.CV'Access,
504 Self_ID.Common.LL.L'Access,
508 Check_Time := Monotonic_Clock;
509 exit when Abs_Time <= Check_Time or else Check_Time < Base_Time;
511 if Result = 0 or else Result = EINTR then
513 -- Somebody may have called Wakeup for us
519 pragma Assert (Result = ETIMEDOUT);
528 -- This is for use in implementing delay statements, so we assume the
529 -- caller is abort-deferred but is holding no locks.
531 procedure Timed_Delay
534 Mode : ST.Delay_Modes)
536 Base_Time : constant Duration := Monotonic_Clock;
537 Check_Time : Duration := Base_Time;
539 Request : aliased timespec;
541 Result : Interfaces.C.int;
542 pragma Warnings (Off, Result);
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 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
565 Result := pthread_cond_timedwait
566 (Self_ID.Common.LL.CV'Access,
567 Single_RTS_Lock'Access,
570 Result := pthread_cond_timedwait
571 (Self_ID.Common.LL.CV'Access,
572 Self_ID.Common.LL.L'Access,
576 Check_Time := Monotonic_Clock;
577 exit when Abs_Time <= Check_Time or else Check_Time < Base_Time;
579 pragma Assert (Result = 0 or else
580 Result = ETIMEDOUT or else
584 Self_ID.Common.State := Runnable;
593 Result := sched_yield;
596 ---------------------
597 -- Monotonic_Clock --
598 ---------------------
600 function Monotonic_Clock return Duration is
601 TV : aliased struct_timeval;
602 Result : Interfaces.C.int;
604 Result := gettimeofday (TV'Access, System.Null_Address);
605 pragma Assert (Result = 0);
606 return To_Duration (TV);
613 function RT_Resolution return Duration is
622 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
623 pragma Unreferenced (Reason);
624 Result : Interfaces.C.int;
626 Result := pthread_cond_signal (T.Common.LL.CV'Access);
627 pragma Assert (Result = 0);
634 procedure Yield (Do_Yield : Boolean := True) is
635 Result : Interfaces.C.int;
636 pragma Unreferenced (Result);
639 Result := sched_yield;
647 procedure Set_Priority
649 Prio : System.Any_Priority;
650 Loss_Of_Inheritance : Boolean := False)
652 pragma Unreferenced (Loss_Of_Inheritance);
654 Result : Interfaces.C.int;
655 Param : aliased struct_sched_param;
657 function Get_Policy (Prio : System.Any_Priority) return Character;
658 pragma Import (C, Get_Policy, "__gnat_get_specific_dispatching");
659 -- Get priority specific dispatching policy
661 Priority_Specific_Policy : constant Character := Get_Policy (Prio);
662 -- Upper case first character of the policy name corresponding to the
663 -- task as set by a Priority_Specific_Dispatching pragma.
666 T.Common.Current_Priority := Prio;
668 -- Priorities are 1 .. 99 on GNU/Linux, so we map 0 .. 98 to 1 .. 99
670 Param.sched_priority := Interfaces.C.int (Prio) + 1;
672 if Dispatching_Policy = 'R'
673 or else Priority_Specific_Policy = 'R'
674 or else Time_Slice_Val > 0
677 pthread_setschedparam
678 (T.Common.LL.Thread, SCHED_RR, Param'Access);
680 elsif Dispatching_Policy = 'F'
681 or else Priority_Specific_Policy = 'F'
682 or else Time_Slice_Val = 0
685 pthread_setschedparam
686 (T.Common.LL.Thread, SCHED_FIFO, Param'Access);
689 Param.sched_priority := 0;
691 pthread_setschedparam
693 SCHED_OTHER, Param'Access);
696 pragma Assert (Result = 0 or else Result = EPERM);
703 function Get_Priority (T : Task_Id) return System.Any_Priority is
705 return T.Common.Current_Priority;
712 procedure Enter_Task (Self_ID : Task_Id) is
714 Self_ID.Common.LL.Thread := pthread_self;
716 Specific.Set (Self_ID);
720 for J in Known_Tasks'Range loop
721 if Known_Tasks (J) = null then
722 Known_Tasks (J) := Self_ID;
723 Self_ID.Known_Tasks_Index := J;
735 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
737 return new Ada_Task_Control_Block (Entry_Num);
744 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
746 -----------------------------
747 -- Register_Foreign_Thread --
748 -----------------------------
750 function Register_Foreign_Thread return Task_Id is
752 if Is_Valid_Task then
755 return Register_Foreign_Thread (pthread_self);
757 end Register_Foreign_Thread;
763 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
764 Result : Interfaces.C.int;
767 -- Give the task a unique serial number
769 Self_ID.Serial_Number := Next_Serial_Number;
770 Next_Serial_Number := Next_Serial_Number + 1;
771 pragma Assert (Next_Serial_Number /= 0);
773 Self_ID.Common.LL.Thread := To_pthread_t (-1);
775 if not Single_Lock then
776 Result := pthread_mutex_init (Self_ID.Common.LL.L'Access,
778 pragma Assert (Result = 0 or else Result = ENOMEM);
786 Result := pthread_cond_init (Self_ID.Common.LL.CV'Access,
788 pragma Assert (Result = 0 or else Result = ENOMEM);
793 if not Single_Lock then
794 Result := pthread_mutex_destroy (Self_ID.Common.LL.L'Access);
795 pragma Assert (Result = 0);
806 procedure Create_Task
808 Wrapper : System.Address;
809 Stack_Size : System.Parameters.Size_Type;
810 Priority : System.Any_Priority;
811 Succeeded : out Boolean)
813 Attributes : aliased pthread_attr_t;
814 Result : Interfaces.C.int;
817 Result := pthread_attr_init (Attributes'Access);
818 pragma Assert (Result = 0 or else Result = ENOMEM);
826 pthread_attr_setstacksize
827 (Attributes'Access, Interfaces.C.size_t (Stack_Size));
828 pragma Assert (Result = 0);
831 pthread_attr_setdetachstate
832 (Attributes'Access, PTHREAD_CREATE_DETACHED);
833 pragma Assert (Result = 0);
835 -- Since the initial signal mask of a thread is inherited from the
836 -- creator, and the Environment task has all its signals masked, we
837 -- do not need to manipulate caller's signal mask at this point.
838 -- All tasks in RTS will have All_Tasks_Mask initially.
840 Result := pthread_create
841 (T.Common.LL.Thread'Access,
843 Thread_Body_Access (Wrapper),
845 pragma Assert (Result = 0 or else Result = EAGAIN);
847 Succeeded := Result = 0;
849 Result := pthread_attr_destroy (Attributes'Access);
850 pragma Assert (Result = 0);
852 Set_Priority (T, Priority);
859 procedure Finalize_TCB (T : Task_Id) is
860 Result : Interfaces.C.int;
862 Is_Self : constant Boolean := T = Self;
864 procedure Free is new
865 Ada.Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
868 if not Single_Lock then
869 Result := pthread_mutex_destroy (T.Common.LL.L'Access);
870 pragma Assert (Result = 0);
873 Result := pthread_cond_destroy (T.Common.LL.CV'Access);
874 pragma Assert (Result = 0);
876 if T.Known_Tasks_Index /= -1 then
877 Known_Tasks (T.Known_Tasks_Index) := null;
879 SC.Invalidate_Stack_Cache (T.Common.Compiler_Data.Pri_Stack_Info'Access);
891 procedure Exit_Task is
900 procedure Abort_Task (T : Task_Id) is
901 Result : Interfaces.C.int;
906 Signal (System.Interrupt_Management.Abort_Task_Interrupt));
907 pragma Assert (Result = 0);
914 procedure Initialize (S : in out Suspension_Object) is
915 Result : Interfaces.C.int;
918 -- Initialize internal state (always to False (RM D.10(6)))
923 -- Initialize internal mutex
925 Result := pthread_mutex_init (S.L'Access, Mutex_Attr'Access);
927 pragma Assert (Result = 0 or else Result = ENOMEM);
929 if Result = ENOMEM then
933 -- Initialize internal condition variable
935 Result := pthread_cond_init (S.CV'Access, Cond_Attr'Access);
937 pragma Assert (Result = 0 or else Result = ENOMEM);
940 Result := pthread_mutex_destroy (S.L'Access);
941 pragma Assert (Result = 0);
943 if Result = ENOMEM then
953 procedure Finalize (S : in out Suspension_Object) is
954 Result : Interfaces.C.int;
957 -- Destroy internal mutex
959 Result := pthread_mutex_destroy (S.L'Access);
960 pragma Assert (Result = 0);
962 -- Destroy internal condition variable
964 Result := pthread_cond_destroy (S.CV'Access);
965 pragma Assert (Result = 0);
972 function Current_State (S : Suspension_Object) return Boolean is
974 -- We do not want to use lock on this read operation. State is marked
975 -- as Atomic so that we ensure that the value retrieved is correct.
984 procedure Set_False (S : in out Suspension_Object) is
985 Result : Interfaces.C.int;
990 Result := pthread_mutex_lock (S.L'Access);
991 pragma Assert (Result = 0);
995 Result := pthread_mutex_unlock (S.L'Access);
996 pragma Assert (Result = 0);
998 SSL.Abort_Undefer.all;
1005 procedure Set_True (S : in out Suspension_Object) is
1006 Result : Interfaces.C.int;
1009 SSL.Abort_Defer.all;
1011 Result := pthread_mutex_lock (S.L'Access);
1012 pragma Assert (Result = 0);
1014 -- If there is already a task waiting on this suspension object then
1015 -- we resume it, leaving the state of the suspension object to False,
1016 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1017 -- the state to True.
1023 Result := pthread_cond_signal (S.CV'Access);
1024 pragma Assert (Result = 0);
1030 Result := pthread_mutex_unlock (S.L'Access);
1031 pragma Assert (Result = 0);
1033 SSL.Abort_Undefer.all;
1036 ------------------------
1037 -- Suspend_Until_True --
1038 ------------------------
1040 procedure Suspend_Until_True (S : in out Suspension_Object) is
1041 Result : Interfaces.C.int;
1044 SSL.Abort_Defer.all;
1046 Result := pthread_mutex_lock (S.L'Access);
1047 pragma Assert (Result = 0);
1051 -- Program_Error must be raised upon calling Suspend_Until_True
1052 -- if another task is already waiting on that suspension object
1055 Result := pthread_mutex_unlock (S.L'Access);
1056 pragma Assert (Result = 0);
1058 SSL.Abort_Undefer.all;
1060 raise Program_Error;
1062 -- Suspend the task if the state is False. Otherwise, the task
1063 -- continues its execution, and the state of the suspension object
1064 -- is set to False (ARM D.10 par. 9).
1070 Result := pthread_cond_wait (S.CV'Access, S.L'Access);
1073 Result := pthread_mutex_unlock (S.L'Access);
1074 pragma Assert (Result = 0);
1076 SSL.Abort_Undefer.all;
1079 end Suspend_Until_True;
1087 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1088 pragma Unreferenced (Self_ID);
1093 --------------------
1094 -- Check_No_Locks --
1095 --------------------
1097 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1098 pragma Unreferenced (Self_ID);
1103 ----------------------
1104 -- Environment_Task --
1105 ----------------------
1107 function Environment_Task return Task_Id is
1109 return Environment_Task_Id;
1110 end Environment_Task;
1116 function Suspend_Task
1118 Thread_Self : Thread_Id) return Boolean
1121 if T.Common.LL.Thread /= Thread_Self then
1122 return pthread_kill (T.Common.LL.Thread, SIGSTOP) = 0;
1132 function Resume_Task
1134 Thread_Self : Thread_Id) return Boolean
1137 if T.Common.LL.Thread /= Thread_Self then
1138 return pthread_kill (T.Common.LL.Thread, SIGCONT) = 0;
1148 procedure Initialize (Environment_Task : Task_Id) is
1149 act : aliased struct_sigaction;
1150 old_act : aliased struct_sigaction;
1151 Tmp_Set : aliased sigset_t;
1152 Result : Interfaces.C.int;
1155 (Int : System.Interrupt_Management.Interrupt_ID) return Character;
1156 pragma Import (C, State, "__gnat_get_interrupt_state");
1157 -- Get interrupt state. Defined in a-init.c
1158 -- The input argument is the interrupt number,
1159 -- and the result is one of the following:
1161 Default : constant Character := 's';
1162 -- 'n' this interrupt not set by any Interrupt_State pragma
1163 -- 'u' Interrupt_State pragma set state to User
1164 -- 'r' Interrupt_State pragma set state to Runtime
1165 -- 's' Interrupt_State pragma set state to System (use "default"
1169 Environment_Task_Id := Environment_Task;
1171 Interrupt_Management.Initialize;
1173 -- Prepare the set of signals that should be unblocked in all tasks
1175 Result := sigemptyset (Unblocked_Signal_Mask'Access);
1176 pragma Assert (Result = 0);
1178 for J in Interrupt_Management.Interrupt_ID loop
1179 if System.Interrupt_Management.Keep_Unmasked (J) then
1180 Result := sigaddset (Unblocked_Signal_Mask'Access, Signal (J));
1181 pragma Assert (Result = 0);
1185 Result := pthread_mutexattr_init (Mutex_Attr'Access);
1186 pragma Assert (Result = 0);
1188 Result := pthread_condattr_init (Cond_Attr'Access);
1189 pragma Assert (Result = 0);
1191 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1193 -- Initialize the global RTS lock
1195 Specific.Initialize (Environment_Task);
1197 Enter_Task (Environment_Task);
1199 -- Install the abort-signal handler
1202 (System.Interrupt_Management.Abort_Task_Interrupt) /= Default
1205 act.sa_handler := Abort_Handler'Address;
1207 Result := sigemptyset (Tmp_Set'Access);
1208 pragma Assert (Result = 0);
1209 act.sa_mask := Tmp_Set;
1213 (Signal (Interrupt_Management.Abort_Task_Interrupt),
1214 act'Unchecked_Access,
1215 old_act'Unchecked_Access);
1216 pragma Assert (Result = 0);
1220 end System.Task_Primitives.Operations;