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-2005, 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 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.
43 with System.Tasking.Debug;
44 -- used for Known_Tasks
50 with System.Interrupt_Management;
51 -- used for Keep_Unmasked
52 -- Abort_Task_Interrupt
55 with System.Parameters;
59 -- used for Ada_Task_Control_Block
63 -- used for Raise_Exception
64 -- Raise_From_Signal_Handler
67 with System.Soft_Links;
68 -- used for Defer/Undefer_Abort
70 -- Note that we do not use System.Tasking.Initialization directly since
71 -- this is a higher level package that we shouldn't depend on. For example
72 -- when using the restricted run time, it is replaced by
73 -- System.Tasking.Restricted.Stages.
75 with System.OS_Primitives;
76 -- used for Delay_Modes
78 with System.Soft_Links;
79 -- used for Abort_Defer/Undefer
81 with Unchecked_Conversion;
82 with Unchecked_Deallocation;
84 package body System.Task_Primitives.Operations is
86 use System.Tasking.Debug;
89 use System.OS_Interface;
90 use System.Parameters;
91 use System.OS_Primitives;
93 package SSL renames System.Soft_Links;
99 -- The followings are logically constants, but need to be initialized
102 Single_RTS_Lock : aliased RTS_Lock;
103 -- This is a lock to allow only one thread of control in the RTS at
104 -- a time; it is used to execute in mutual exclusion from all other tasks.
105 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
107 ATCB_Key : aliased pthread_key_t;
108 -- Key used to find the Ada Task_Id associated with a thread
110 Environment_Task_Id : Task_Id;
111 -- A variable to hold Task_Id for the environment task
113 Unblocked_Signal_Mask : aliased sigset_t;
114 -- The set of signals that should unblocked in all tasks
116 -- The followings are internal configuration constants needed
118 Priority_Ceiling_Emulation : constant Boolean := True;
120 Next_Serial_Number : Task_Serial_Number := 100;
121 -- We start at 100, to reserve some special values for
122 -- using in error checking.
124 Time_Slice_Val : Integer;
125 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
127 Dispatching_Policy : Character;
128 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
130 FIFO_Within_Priorities : constant Boolean := Dispatching_Policy = 'F';
131 -- Indicates whether FIFO_Within_Priorities is set
133 -- The following are effectively constants, but they need to
134 -- be initialized by calling a pthread_ function.
136 Mutex_Attr : aliased pthread_mutexattr_t;
137 Cond_Attr : aliased pthread_condattr_t;
139 Foreign_Task_Elaborated : aliased Boolean := True;
140 -- Used to identified fake tasks (i.e., non-Ada Threads)
148 procedure Initialize (Environment_Task : Task_Id);
149 pragma Inline (Initialize);
150 -- Initialize various data needed by this package
152 function Is_Valid_Task return Boolean;
153 pragma Inline (Is_Valid_Task);
154 -- Does executing thread have a TCB?
156 procedure Set (Self_Id : Task_Id);
158 -- Set the self id for the current task
160 function Self return Task_Id;
161 pragma Inline (Self);
162 -- Return a pointer to the Ada Task Control Block of the calling task.
166 package body Specific is separate;
167 -- The body of this package is target specific
169 ---------------------------------
170 -- Support for foreign threads --
171 ---------------------------------
173 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
174 -- Allocate and Initialize a new ATCB for the current Thread
176 function Register_Foreign_Thread
177 (Thread : Thread_Id) return Task_Id is separate;
179 -----------------------
180 -- Local Subprograms --
181 -----------------------
183 subtype unsigned_long is Interfaces.C.unsigned_long;
185 procedure Abort_Handler (signo : Signal);
187 function To_pthread_t is new Unchecked_Conversion
188 (unsigned_long, System.OS_Interface.pthread_t);
194 procedure Abort_Handler (signo : Signal) is
195 pragma Unreferenced (signo);
197 Self_Id : constant Task_Id := Self;
198 Result : Interfaces.C.int;
199 Old_Set : aliased sigset_t;
202 if ZCX_By_Default and then GCC_ZCX_Support then
206 if Self_Id.Deferral_Level = 0
207 and then Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level
208 and then not Self_Id.Aborting
210 Self_Id.Aborting := True;
212 -- Make sure signals used for RTS internal purpose are unmasked
214 Result := pthread_sigmask (SIG_UNBLOCK,
215 Unblocked_Signal_Mask'Unchecked_Access, Old_Set'Unchecked_Access);
216 pragma Assert (Result = 0);
218 raise Standard'Abort_Signal;
226 procedure Lock_RTS is
228 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
235 procedure Unlock_RTS is
237 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
244 -- The underlying thread system extends the memory (up to 2MB) when needed
246 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
247 pragma Unreferenced (T);
248 pragma Unreferenced (On);
257 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
259 return T.Common.LL.Thread;
266 function Self return Task_Id renames Specific.Self;
268 ---------------------
269 -- Initialize_Lock --
270 ---------------------
272 -- Note: mutexes and cond_variables needed per-task basis are
273 -- initialized in Initialize_TCB and the Storage_Error is
274 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
275 -- used in RTS is initialized before any status change of RTS.
276 -- Therefore rasing Storage_Error in the following routines
277 -- should be able to be handled safely.
279 procedure Initialize_Lock
280 (Prio : System.Any_Priority;
283 Result : Interfaces.C.int;
286 if Priority_Ceiling_Emulation then
290 Result := pthread_mutex_init (L.L'Access, Mutex_Attr'Access);
292 pragma Assert (Result = 0 or else Result = ENOMEM);
294 if Result = ENOMEM then
295 Ada.Exceptions.Raise_Exception (Storage_Error'Identity,
296 "Failed to allocate a lock");
300 procedure Initialize_Lock (L : access RTS_Lock; Level : Lock_Level) is
301 pragma Unreferenced (Level);
303 Result : Interfaces.C.int;
306 Result := pthread_mutex_init (L, Mutex_Attr'Access);
308 pragma Assert (Result = 0 or else Result = ENOMEM);
310 if Result = ENOMEM then
319 procedure Finalize_Lock (L : access Lock) is
320 Result : Interfaces.C.int;
322 Result := pthread_mutex_destroy (L.L'Access);
323 pragma Assert (Result = 0);
326 procedure Finalize_Lock (L : access RTS_Lock) is
327 Result : Interfaces.C.int;
329 Result := pthread_mutex_destroy (L);
330 pragma Assert (Result = 0);
337 procedure Write_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
338 Result : Interfaces.C.int;
341 if Priority_Ceiling_Emulation then
343 Self_ID : constant Task_Id := Self;
346 if Self_ID.Common.LL.Active_Priority > L.Ceiling then
347 Ceiling_Violation := True;
351 L.Saved_Priority := Self_ID.Common.LL.Active_Priority;
353 if Self_ID.Common.LL.Active_Priority < L.Ceiling then
354 Self_ID.Common.LL.Active_Priority := L.Ceiling;
357 Result := pthread_mutex_lock (L.L'Access);
358 pragma Assert (Result = 0);
359 Ceiling_Violation := False;
363 Result := pthread_mutex_lock (L.L'Access);
364 Ceiling_Violation := Result = EINVAL;
366 -- Assume the cause of EINVAL is a priority ceiling violation
368 pragma Assert (Result = 0 or else Result = EINVAL);
373 (L : access RTS_Lock;
374 Global_Lock : Boolean := False)
376 Result : Interfaces.C.int;
378 if not Single_Lock or else Global_Lock then
379 Result := pthread_mutex_lock (L);
380 pragma Assert (Result = 0);
384 procedure Write_Lock (T : Task_Id) is
385 Result : Interfaces.C.int;
387 if not Single_Lock then
388 Result := pthread_mutex_lock (T.Common.LL.L'Access);
389 pragma Assert (Result = 0);
397 procedure Read_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
399 Write_Lock (L, Ceiling_Violation);
406 procedure Unlock (L : access Lock) is
407 Result : Interfaces.C.int;
410 if Priority_Ceiling_Emulation then
412 Self_ID : constant Task_Id := Self;
415 Result := pthread_mutex_unlock (L.L'Access);
416 pragma Assert (Result = 0);
418 if Self_ID.Common.LL.Active_Priority > L.Saved_Priority then
419 Self_ID.Common.LL.Active_Priority := L.Saved_Priority;
424 Result := pthread_mutex_unlock (L.L'Access);
425 pragma Assert (Result = 0);
429 procedure Unlock (L : access RTS_Lock; Global_Lock : Boolean := False) is
430 Result : Interfaces.C.int;
432 if not Single_Lock or else Global_Lock then
433 Result := pthread_mutex_unlock (L);
434 pragma Assert (Result = 0);
438 procedure Unlock (T : Task_Id) is
439 Result : Interfaces.C.int;
441 if not Single_Lock then
442 Result := pthread_mutex_unlock (T.Common.LL.L'Access);
443 pragma Assert (Result = 0);
453 Reason : System.Tasking.Task_States)
455 pragma Unreferenced (Reason);
457 Result : Interfaces.C.int;
460 pragma Assert (Self_ID = Self);
463 Result := pthread_cond_wait
464 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
466 Result := pthread_cond_wait
467 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
470 -- EINTR is not considered a failure
472 pragma Assert (Result = 0 or else Result = EINTR);
479 -- This is for use within the run-time system, so abort is
480 -- assumed to be already deferred, and the caller should be
481 -- holding its own ATCB lock.
483 procedure Timed_Sleep
486 Mode : ST.Delay_Modes;
487 Reason : System.Tasking.Task_States;
488 Timedout : out Boolean;
489 Yielded : out Boolean)
491 pragma Unreferenced (Reason);
493 Check_Time : constant Duration := Monotonic_Clock;
495 Request : aliased timespec;
496 Result : Interfaces.C.int;
502 if Mode = Relative then
503 Abs_Time := Duration'Min (Time, Max_Sensible_Delay) + Check_Time;
505 Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time);
508 if Abs_Time > Check_Time then
509 Request := To_Timespec (Abs_Time);
512 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
513 or else Self_ID.Pending_Priority_Change;
516 Result := pthread_cond_timedwait
517 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access,
521 Result := pthread_cond_timedwait
522 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access,
526 exit when Abs_Time <= Monotonic_Clock;
528 if Result = 0 or Result = EINTR then
529 -- somebody may have called Wakeup for us
534 pragma Assert (Result = ETIMEDOUT);
543 -- This is for use in implementing delay statements, so
544 -- we assume the caller is abort-deferred but is holding
547 procedure Timed_Delay
550 Mode : ST.Delay_Modes)
552 Check_Time : constant Duration := Monotonic_Clock;
554 Request : aliased timespec;
555 Result : Interfaces.C.int;
558 -- Only the little window between deferring abort and
559 -- locking Self_ID is the reason we need to
560 -- check for pending abort and priority change below! :(
568 Write_Lock (Self_ID);
570 if Mode = Relative then
571 Abs_Time := Time + Check_Time;
573 Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time);
576 if Abs_Time > Check_Time then
577 Request := To_Timespec (Abs_Time);
578 Self_ID.Common.State := Delay_Sleep;
581 if Self_ID.Pending_Priority_Change then
582 Self_ID.Pending_Priority_Change := False;
583 Self_ID.Common.Base_Priority := Self_ID.New_Base_Priority;
584 Set_Priority (Self_ID, Self_ID.Common.Base_Priority);
587 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
590 Result := pthread_cond_timedwait (Self_ID.Common.LL.CV'Access,
591 Single_RTS_Lock'Access, Request'Access);
593 Result := pthread_cond_timedwait (Self_ID.Common.LL.CV'Access,
594 Self_ID.Common.LL.L'Access, Request'Access);
597 exit when Abs_Time <= Monotonic_Clock;
599 pragma Assert (Result = 0 or else
600 Result = ETIMEDOUT or else
604 Self_ID.Common.State := Runnable;
613 Result := sched_yield;
614 SSL.Abort_Undefer.all;
617 ---------------------
618 -- Monotonic_Clock --
619 ---------------------
621 function Monotonic_Clock return Duration is
622 TV : aliased struct_timeval;
623 Result : Interfaces.C.int;
625 Result := gettimeofday (TV'Access, System.Null_Address);
626 pragma Assert (Result = 0);
627 return To_Duration (TV);
634 function RT_Resolution return Duration is
643 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
644 pragma Unreferenced (Reason);
645 Result : Interfaces.C.int;
647 Result := pthread_cond_signal (T.Common.LL.CV'Access);
648 pragma Assert (Result = 0);
655 procedure Yield (Do_Yield : Boolean := True) is
656 Result : Interfaces.C.int;
657 pragma Unreferenced (Result);
660 Result := sched_yield;
668 procedure Set_Priority
670 Prio : System.Any_Priority;
671 Loss_Of_Inheritance : Boolean := False)
673 pragma Unreferenced (Loss_Of_Inheritance);
675 Result : Interfaces.C.int;
676 Param : aliased struct_sched_param;
679 T.Common.Current_Priority := Prio;
681 if Priority_Ceiling_Emulation then
682 if T.Common.LL.Active_Priority < Prio then
683 T.Common.LL.Active_Priority := Prio;
687 -- Priorities are in range 1 .. 99 on GNU/Linux, so we map
688 -- map 0 .. 31 to 1 .. 32
690 Param.sched_priority := Interfaces.C.int (Prio) + 1;
692 if Time_Slice_Val > 0 then
693 Result := pthread_setschedparam
694 (T.Common.LL.Thread, SCHED_RR, Param'Access);
696 elsif FIFO_Within_Priorities or else Time_Slice_Val = 0 then
697 Result := pthread_setschedparam
698 (T.Common.LL.Thread, SCHED_FIFO, Param'Access);
701 Param.sched_priority := 0;
702 Result := pthread_setschedparam
703 (T.Common.LL.Thread, SCHED_OTHER, Param'Access);
706 pragma Assert (Result = 0 or else Result = EPERM);
713 function Get_Priority (T : Task_Id) return System.Any_Priority is
715 return T.Common.Current_Priority;
722 procedure Enter_Task (Self_ID : Task_Id) is
724 Self_ID.Common.LL.Thread := pthread_self;
726 Specific.Set (Self_ID);
730 for J in Known_Tasks'Range loop
731 if Known_Tasks (J) = null then
732 Known_Tasks (J) := Self_ID;
733 Self_ID.Known_Tasks_Index := J;
745 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
747 return new Ada_Task_Control_Block (Entry_Num);
754 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
756 -----------------------------
757 -- Register_Foreign_Thread --
758 -----------------------------
760 function Register_Foreign_Thread return Task_Id is
762 if Is_Valid_Task then
765 return Register_Foreign_Thread (pthread_self);
767 end Register_Foreign_Thread;
773 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
774 Result : Interfaces.C.int;
777 -- Give the task a unique serial number
779 Self_ID.Serial_Number := Next_Serial_Number;
780 Next_Serial_Number := Next_Serial_Number + 1;
781 pragma Assert (Next_Serial_Number /= 0);
783 Self_ID.Common.LL.Thread := To_pthread_t (-1);
785 if not Single_Lock then
786 Result := pthread_mutex_init (Self_ID.Common.LL.L'Access,
788 pragma Assert (Result = 0 or else Result = ENOMEM);
796 Result := pthread_cond_init (Self_ID.Common.LL.CV'Access,
798 pragma Assert (Result = 0 or else Result = ENOMEM);
803 if not Single_Lock then
804 Result := pthread_mutex_destroy (Self_ID.Common.LL.L'Access);
805 pragma Assert (Result = 0);
816 procedure Create_Task
818 Wrapper : System.Address;
819 Stack_Size : System.Parameters.Size_Type;
820 Priority : System.Any_Priority;
821 Succeeded : out Boolean)
823 Adjusted_Stack_Size : Interfaces.C.size_t;
825 Attributes : aliased pthread_attr_t;
826 Result : Interfaces.C.int;
829 if Stack_Size = Unspecified_Size then
830 Adjusted_Stack_Size := Interfaces.C.size_t (Default_Stack_Size);
832 elsif Stack_Size < Minimum_Stack_Size then
833 Adjusted_Stack_Size := Interfaces.C.size_t (Minimum_Stack_Size);
836 Adjusted_Stack_Size := Interfaces.C.size_t (Stack_Size);
839 Result := pthread_attr_init (Attributes'Access);
840 pragma Assert (Result = 0 or else Result = ENOMEM);
848 pthread_attr_setstacksize
849 (Attributes'Access, Adjusted_Stack_Size);
850 pragma Assert (Result = 0);
853 pthread_attr_setdetachstate
854 (Attributes'Access, PTHREAD_CREATE_DETACHED);
855 pragma Assert (Result = 0);
857 -- Since the initial signal mask of a thread is inherited from the
858 -- creator, and the Environment task has all its signals masked, we
859 -- do not need to manipulate caller's signal mask at this point.
860 -- All tasks in RTS will have All_Tasks_Mask initially.
862 Result := pthread_create
863 (T.Common.LL.Thread'Access,
865 Thread_Body_Access (Wrapper),
867 pragma Assert (Result = 0 or else Result = EAGAIN);
869 Succeeded := Result = 0;
871 Result := pthread_attr_destroy (Attributes'Access);
872 pragma Assert (Result = 0);
874 Set_Priority (T, Priority);
881 procedure Finalize_TCB (T : Task_Id) is
882 Result : Interfaces.C.int;
884 Is_Self : constant Boolean := T = Self;
886 procedure Free is new
887 Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
890 if not Single_Lock then
891 Result := pthread_mutex_destroy (T.Common.LL.L'Access);
892 pragma Assert (Result = 0);
895 Result := pthread_cond_destroy (T.Common.LL.CV'Access);
896 pragma Assert (Result = 0);
898 if T.Known_Tasks_Index /= -1 then
899 Known_Tasks (T.Known_Tasks_Index) := null;
913 procedure Exit_Task is
922 procedure Abort_Task (T : Task_Id) is
923 Result : Interfaces.C.int;
925 Result := pthread_kill (T.Common.LL.Thread,
926 Signal (System.Interrupt_Management.Abort_Task_Interrupt));
927 pragma Assert (Result = 0);
934 procedure Initialize (S : in out Suspension_Object) is
935 Result : Interfaces.C.int;
937 -- Initialize internal state. It is always initialized to False (ARM
943 -- Initialize internal mutex
945 Result := pthread_mutex_init (S.L'Access, Mutex_Attr'Access);
947 pragma Assert (Result = 0 or else Result = ENOMEM);
949 if Result = ENOMEM then
953 -- Initialize internal condition variable
955 Result := pthread_cond_init (S.CV'Access, Cond_Attr'Access);
957 pragma Assert (Result = 0 or else Result = ENOMEM);
960 Result := pthread_mutex_destroy (S.L'Access);
961 pragma Assert (Result = 0);
963 if Result = ENOMEM then
973 procedure Finalize (S : in out Suspension_Object) is
974 Result : Interfaces.C.int;
976 -- Destroy internal mutex
978 Result := pthread_mutex_destroy (S.L'Access);
979 pragma Assert (Result = 0);
981 -- Destroy internal condition variable
983 Result := pthread_cond_destroy (S.CV'Access);
984 pragma Assert (Result = 0);
991 function Current_State (S : Suspension_Object) return Boolean is
993 -- We do not want to use lock on this read operation. State is marked
994 -- as Atomic so that we ensure that the value retrieved is correct.
1003 procedure Set_False (S : in out Suspension_Object) is
1004 Result : Interfaces.C.int;
1006 Result := pthread_mutex_lock (S.L'Access);
1007 pragma Assert (Result = 0);
1011 Result := pthread_mutex_unlock (S.L'Access);
1012 pragma Assert (Result = 0);
1019 procedure Set_True (S : in out Suspension_Object) is
1020 Result : Interfaces.C.int;
1022 Result := pthread_mutex_lock (S.L'Access);
1023 pragma Assert (Result = 0);
1025 -- If there is already a task waiting on this suspension object then
1026 -- we resume it, leaving the state of the suspension object to False,
1027 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1028 -- the state to True.
1034 Result := pthread_cond_signal (S.CV'Access);
1035 pragma Assert (Result = 0);
1040 Result := pthread_mutex_unlock (S.L'Access);
1041 pragma Assert (Result = 0);
1044 ------------------------
1045 -- Suspend_Until_True --
1046 ------------------------
1048 procedure Suspend_Until_True (S : in out Suspension_Object) is
1049 Result : Interfaces.C.int;
1051 Result := pthread_mutex_lock (S.L'Access);
1052 pragma Assert (Result = 0);
1055 -- Program_Error must be raised upon calling Suspend_Until_True
1056 -- if another task is already waiting on that suspension object
1057 -- (ARM D.10 par. 10).
1059 Result := pthread_mutex_unlock (S.L'Access);
1060 pragma Assert (Result = 0);
1062 raise Program_Error;
1064 -- Suspend the task if the state is False. Otherwise, the task
1065 -- continues its execution, and the state of the suspension object
1066 -- is set to False (ARM D.10 par. 9).
1072 Result := pthread_cond_wait (S.CV'Access, S.L'Access);
1076 Result := pthread_mutex_unlock (S.L'Access);
1077 pragma Assert (Result = 0);
1078 end Suspend_Until_True;
1086 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1087 pragma Unreferenced (Self_ID);
1092 --------------------
1093 -- Check_No_Locks --
1094 --------------------
1096 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1097 pragma Unreferenced (Self_ID);
1102 ----------------------
1103 -- Environment_Task --
1104 ----------------------
1106 function Environment_Task return Task_Id is
1108 return Environment_Task_Id;
1109 end Environment_Task;
1115 function Suspend_Task
1117 Thread_Self : Thread_Id) return Boolean
1120 if T.Common.LL.Thread /= Thread_Self then
1121 return pthread_kill (T.Common.LL.Thread, SIGSTOP) = 0;
1131 function Resume_Task
1133 Thread_Self : Thread_Id) return Boolean
1136 if T.Common.LL.Thread /= Thread_Self then
1137 return pthread_kill (T.Common.LL.Thread, SIGCONT) = 0;
1147 procedure Initialize (Environment_Task : Task_Id) is
1148 act : aliased struct_sigaction;
1149 old_act : aliased struct_sigaction;
1150 Tmp_Set : aliased sigset_t;
1151 Result : Interfaces.C.int;
1154 (Int : System.Interrupt_Management.Interrupt_ID) return Character;
1155 pragma Import (C, State, "__gnat_get_interrupt_state");
1156 -- Get interrupt state. Defined in a-init.c
1157 -- The input argument is the interrupt number,
1158 -- and the result is one of the following:
1160 Default : constant Character := 's';
1161 -- 'n' this interrupt not set by any Interrupt_State pragma
1162 -- 'u' Interrupt_State pragma set state to User
1163 -- 'r' Interrupt_State pragma set state to Runtime
1164 -- 's' Interrupt_State pragma set state to System (use "default"
1168 Environment_Task_Id := Environment_Task;
1170 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1172 -- Initialize the global RTS lock
1174 Specific.Initialize (Environment_Task);
1176 Enter_Task (Environment_Task);
1178 -- Install the abort-signal handler
1180 if State (System.Interrupt_Management.Abort_Task_Interrupt)
1184 act.sa_handler := Abort_Handler'Address;
1186 Result := sigemptyset (Tmp_Set'Access);
1187 pragma Assert (Result = 0);
1188 act.sa_mask := Tmp_Set;
1192 (Signal (Interrupt_Management.Abort_Task_Interrupt),
1193 act'Unchecked_Access,
1194 old_act'Unchecked_Access);
1195 pragma Assert (Result = 0);
1201 Result : Interfaces.C.int;
1203 -- Prepare the set of signals that should unblocked in all tasks
1205 Result := sigemptyset (Unblocked_Signal_Mask'Access);
1206 pragma Assert (Result = 0);
1208 for J in Interrupt_Management.Interrupt_ID loop
1209 if System.Interrupt_Management.Keep_Unmasked (J) then
1210 Result := sigaddset (Unblocked_Signal_Mask'Access, Signal (J));
1211 pragma Assert (Result = 0);
1215 Result := pthread_mutexattr_init (Mutex_Attr'Access);
1216 pragma Assert (Result = 0);
1218 Result := pthread_condattr_init (Cond_Attr'Access);
1219 pragma Assert (Result = 0);
1221 end System.Task_Primitives.Operations;