1 ------------------------------------------------------------------------------
3 -- GNAT 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-2008, 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 HP-UX DCE threads (HPUX 10) version of this package
36 -- This package contains all the GNULL primitives that interface directly with
40 -- Turn off polling, we do not want ATC polling to take place during tasking
41 -- operations. It causes infinite loops and other problems.
43 with Ada.Unchecked_Conversion;
44 with Ada.Unchecked_Deallocation;
48 with System.Tasking.Debug;
49 with System.Interrupt_Management;
50 with System.OS_Primitives;
51 with System.Task_Primitives.Interrupt_Operations;
53 pragma Warnings (Off);
54 with System.Interrupt_Management.Operations;
55 pragma Elaborate_All (System.Interrupt_Management.Operations);
58 with System.Soft_Links;
59 -- We use System.Soft_Links instead of System.Tasking.Initialization
60 -- because the later is a higher level package that we shouldn't depend on.
61 -- For example when using the restricted run time, it is replaced by
62 -- System.Tasking.Restricted.Stages.
64 package body System.Task_Primitives.Operations is
66 package SSL renames System.Soft_Links;
68 use System.Tasking.Debug;
71 use System.OS_Interface;
72 use System.Parameters;
73 use System.OS_Primitives;
75 package PIO renames System.Task_Primitives.Interrupt_Operations;
81 -- The followings are logically constants, but need to be initialized
84 Single_RTS_Lock : aliased RTS_Lock;
85 -- This is a lock to allow only one thread of control in the RTS at
86 -- a time; it is used to execute in mutual exclusion from all other tasks.
87 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
89 ATCB_Key : aliased pthread_key_t;
90 -- Key used to find the Ada Task_Id associated with a thread
92 Environment_Task_Id : Task_Id;
93 -- A variable to hold Task_Id for the environment task
95 Unblocked_Signal_Mask : aliased sigset_t;
96 -- The set of signals that should unblocked in all tasks
98 Time_Slice_Val : Integer;
99 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
101 Dispatching_Policy : Character;
102 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
104 -- Note: the reason that Locking_Policy is not needed is that this
105 -- is not implemented for DCE threads. The HPUX 10 port is at this
106 -- stage considered dead, and no further work is planned on it.
108 Foreign_Task_Elaborated : aliased Boolean := True;
109 -- Used to identified fake tasks (i.e., non-Ada Threads)
117 procedure Initialize (Environment_Task : Task_Id);
118 pragma Inline (Initialize);
119 -- Initialize various data needed by this package
121 function Is_Valid_Task return Boolean;
122 pragma Inline (Is_Valid_Task);
123 -- Does the executing thread have a TCB?
125 procedure Set (Self_Id : Task_Id);
127 -- Set the self id for the current task
129 function Self return Task_Id;
130 pragma Inline (Self);
131 -- Return a pointer to the Ada Task Control Block of the calling task
135 package body Specific is separate;
136 -- The body of this package is target specific
138 ---------------------------------
139 -- Support for foreign threads --
140 ---------------------------------
142 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
143 -- Allocate and Initialize a new ATCB for the current Thread
145 function Register_Foreign_Thread
146 (Thread : Thread_Id) return Task_Id is separate;
148 -----------------------
149 -- Local Subprograms --
150 -----------------------
152 procedure Abort_Handler (Sig : Signal);
154 function To_Address is
155 new Ada.Unchecked_Conversion (Task_Id, System.Address);
161 procedure Abort_Handler (Sig : Signal) is
162 pragma Unreferenced (Sig);
164 Self_Id : constant Task_Id := Self;
165 Result : Interfaces.C.int;
166 Old_Set : aliased sigset_t;
169 if Self_Id.Deferral_Level = 0
170 and then Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level
171 and then not Self_Id.Aborting
173 Self_Id.Aborting := True;
175 -- Make sure signals used for RTS internal purpose are unmasked
180 Unblocked_Signal_Mask'Access,
182 pragma Assert (Result = 0);
184 raise Standard'Abort_Signal;
192 -- The underlying thread system sets a guard page at the bottom of a thread
193 -- stack, so nothing is needed.
194 -- ??? Check the comment above
196 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
197 pragma Unreferenced (T, On);
206 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
208 return T.Common.LL.Thread;
215 function Self return Task_Id renames Specific.Self;
217 ---------------------
218 -- Initialize_Lock --
219 ---------------------
221 -- Note: mutexes and cond_variables needed per-task basis are initialized
222 -- in Initialize_TCB and the Storage_Error is handled. Other mutexes (such
223 -- as RTS_Lock, Memory_Lock...) used in RTS is initialized before any
224 -- status change of RTS. Therefore raising Storage_Error in the following
225 -- routines should be able to be handled safely.
227 procedure Initialize_Lock
228 (Prio : System.Any_Priority;
229 L : not null access Lock)
231 Attributes : aliased pthread_mutexattr_t;
232 Result : Interfaces.C.int;
235 Result := pthread_mutexattr_init (Attributes'Access);
236 pragma Assert (Result = 0 or else Result = ENOMEM);
238 if Result = ENOMEM then
244 Result := pthread_mutex_init (L.L'Access, Attributes'Access);
245 pragma Assert (Result = 0 or else Result = ENOMEM);
247 if Result = ENOMEM then
251 Result := pthread_mutexattr_destroy (Attributes'Access);
252 pragma Assert (Result = 0);
255 procedure Initialize_Lock
256 (L : not null access RTS_Lock;
259 pragma Unreferenced (Level);
261 Attributes : aliased pthread_mutexattr_t;
262 Result : Interfaces.C.int;
265 Result := pthread_mutexattr_init (Attributes'Access);
266 pragma Assert (Result = 0 or else Result = ENOMEM);
268 if Result = ENOMEM then
272 Result := pthread_mutex_init (L, Attributes'Access);
274 pragma Assert (Result = 0 or else Result = ENOMEM);
276 if Result = ENOMEM then
280 Result := pthread_mutexattr_destroy (Attributes'Access);
281 pragma Assert (Result = 0);
288 procedure Finalize_Lock (L : not null access Lock) is
289 Result : Interfaces.C.int;
291 Result := pthread_mutex_destroy (L.L'Access);
292 pragma Assert (Result = 0);
295 procedure Finalize_Lock (L : not null access RTS_Lock) is
296 Result : Interfaces.C.int;
298 Result := pthread_mutex_destroy (L);
299 pragma Assert (Result = 0);
307 (L : not null access Lock;
308 Ceiling_Violation : out Boolean)
310 Result : Interfaces.C.int;
313 L.Owner_Priority := Get_Priority (Self);
315 if L.Priority < L.Owner_Priority then
316 Ceiling_Violation := True;
320 Result := pthread_mutex_lock (L.L'Access);
321 pragma Assert (Result = 0);
322 Ceiling_Violation := False;
326 (L : not null access RTS_Lock;
327 Global_Lock : Boolean := False)
329 Result : Interfaces.C.int;
331 if not Single_Lock or else Global_Lock then
332 Result := pthread_mutex_lock (L);
333 pragma Assert (Result = 0);
337 procedure Write_Lock (T : Task_Id) is
338 Result : Interfaces.C.int;
340 if not Single_Lock then
341 Result := pthread_mutex_lock (T.Common.LL.L'Access);
342 pragma Assert (Result = 0);
351 (L : not null access Lock;
352 Ceiling_Violation : out Boolean)
355 Write_Lock (L, Ceiling_Violation);
362 procedure Unlock (L : not null access Lock) is
363 Result : Interfaces.C.int;
365 Result := pthread_mutex_unlock (L.L'Access);
366 pragma Assert (Result = 0);
370 (L : not null access RTS_Lock;
371 Global_Lock : Boolean := False)
373 Result : Interfaces.C.int;
375 if not Single_Lock or else Global_Lock then
376 Result := pthread_mutex_unlock (L);
377 pragma Assert (Result = 0);
381 procedure Unlock (T : Task_Id) is
382 Result : Interfaces.C.int;
384 if not Single_Lock then
385 Result := pthread_mutex_unlock (T.Common.LL.L'Access);
386 pragma Assert (Result = 0);
394 -- Dynamic priority ceilings are not supported by the underlying system
396 procedure Set_Ceiling
397 (L : not null access Lock;
398 Prio : System.Any_Priority)
400 pragma Unreferenced (L, Prio);
411 Reason : System.Tasking.Task_States)
413 pragma Unreferenced (Reason);
415 Result : Interfaces.C.int;
420 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
424 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
427 -- EINTR is not considered a failure
429 pragma Assert (Result = 0 or else Result = EINTR);
436 procedure Timed_Sleep
439 Mode : ST.Delay_Modes;
440 Reason : System.Tasking.Task_States;
441 Timedout : out Boolean;
442 Yielded : out Boolean)
444 pragma Unreferenced (Reason);
446 Check_Time : constant Duration := Monotonic_Clock;
448 Request : aliased timespec;
449 Result : Interfaces.C.int;
455 if Mode = Relative then
456 Abs_Time := Duration'Min (Time, Max_Sensible_Delay) + Check_Time;
458 Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time);
461 if Abs_Time > Check_Time then
462 Request := To_Timespec (Abs_Time);
465 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
469 pthread_cond_timedwait
470 (Self_ID.Common.LL.CV'Access,
471 Single_RTS_Lock'Access,
476 pthread_cond_timedwait
477 (Self_ID.Common.LL.CV'Access,
478 Self_ID.Common.LL.L'Access,
482 exit when Abs_Time <= Monotonic_Clock;
484 if Result = 0 or Result = EINTR then
486 -- Somebody may have called Wakeup for us
492 pragma Assert (Result = ETIMEDOUT);
501 procedure Timed_Delay
504 Mode : ST.Delay_Modes)
506 Check_Time : constant Duration := Monotonic_Clock;
508 Request : aliased timespec;
510 Result : Interfaces.C.int;
511 pragma Warnings (Off, Result);
518 Write_Lock (Self_ID);
520 if Mode = Relative then
521 Abs_Time := Time + Check_Time;
523 Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time);
526 if Abs_Time > Check_Time then
527 Request := To_Timespec (Abs_Time);
528 Self_ID.Common.State := Delay_Sleep;
531 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
535 pthread_cond_timedwait
536 (Self_ID.Common.LL.CV'Access,
537 Single_RTS_Lock'Access,
541 pthread_cond_timedwait
542 (Self_ID.Common.LL.CV'Access,
543 Self_ID.Common.LL.L'Access,
547 exit when Abs_Time <= Monotonic_Clock;
549 pragma Assert (Result = 0 or else
550 Result = ETIMEDOUT or else
554 Self_ID.Common.State := Runnable;
563 Result := sched_yield;
566 ---------------------
567 -- Monotonic_Clock --
568 ---------------------
570 function Monotonic_Clock return Duration is
571 TS : aliased timespec;
572 Result : Interfaces.C.int;
574 Result := Clock_Gettime (CLOCK_REALTIME, TS'Unchecked_Access);
575 pragma Assert (Result = 0);
576 return To_Duration (TS);
583 function RT_Resolution return Duration is
592 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
593 pragma Unreferenced (Reason);
594 Result : Interfaces.C.int;
596 Result := pthread_cond_signal (T.Common.LL.CV'Access);
597 pragma Assert (Result = 0);
604 procedure Yield (Do_Yield : Boolean := True) is
605 Result : Interfaces.C.int;
606 pragma Unreferenced (Result);
609 Result := sched_yield;
617 type Prio_Array_Type is array (System.Any_Priority) of Integer;
618 pragma Atomic_Components (Prio_Array_Type);
620 Prio_Array : Prio_Array_Type;
621 -- Global array containing the id of the currently running task for
624 -- Note: assume we are on single processor with run-til-blocked scheduling
626 procedure Set_Priority
628 Prio : System.Any_Priority;
629 Loss_Of_Inheritance : Boolean := False)
631 Result : Interfaces.C.int;
632 Array_Item : Integer;
633 Param : aliased struct_sched_param;
635 function Get_Policy (Prio : System.Any_Priority) return Character;
636 pragma Import (C, Get_Policy, "__gnat_get_specific_dispatching");
637 -- Get priority specific dispatching policy
639 Priority_Specific_Policy : constant Character := Get_Policy (Prio);
640 -- Upper case first character of the policy name corresponding to the
641 -- task as set by a Priority_Specific_Dispatching pragma.
644 Param.sched_priority := Interfaces.C.int (Underlying_Priorities (Prio));
646 if Dispatching_Policy = 'R'
647 or else Priority_Specific_Policy = 'R'
648 or else Time_Slice_Val > 0
651 pthread_setschedparam
652 (T.Common.LL.Thread, SCHED_RR, Param'Access);
654 elsif Dispatching_Policy = 'F'
655 or else Priority_Specific_Policy = 'F'
656 or else Time_Slice_Val = 0
659 pthread_setschedparam
660 (T.Common.LL.Thread, SCHED_FIFO, Param'Access);
664 pthread_setschedparam
665 (T.Common.LL.Thread, SCHED_OTHER, Param'Access);
668 pragma Assert (Result = 0);
670 if Dispatching_Policy = 'F' or else Priority_Specific_Policy = 'F' then
672 -- Annex D requirement [RM D.2.2 par. 9]:
673 -- If the task drops its priority due to the loss of inherited
674 -- priority, it is added at the head of the ready queue for its
675 -- new active priority.
677 if Loss_Of_Inheritance
678 and then Prio < T.Common.Current_Priority
680 Array_Item := Prio_Array (T.Common.Base_Priority) + 1;
681 Prio_Array (T.Common.Base_Priority) := Array_Item;
684 -- Let some processes a chance to arrive
688 -- Then wait for our turn to proceed
690 exit when Array_Item = Prio_Array (T.Common.Base_Priority)
691 or else Prio_Array (T.Common.Base_Priority) = 1;
694 Prio_Array (T.Common.Base_Priority) :=
695 Prio_Array (T.Common.Base_Priority) - 1;
699 T.Common.Current_Priority := Prio;
706 function Get_Priority (T : Task_Id) return System.Any_Priority is
708 return T.Common.Current_Priority;
715 procedure Enter_Task (Self_ID : Task_Id) is
717 Self_ID.Common.LL.Thread := pthread_self;
718 Specific.Set (Self_ID);
722 for J in Known_Tasks'Range loop
723 if Known_Tasks (J) = null then
724 Known_Tasks (J) := Self_ID;
725 Self_ID.Known_Tasks_Index := J;
737 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
739 return new Ada_Task_Control_Block (Entry_Num);
746 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
748 -----------------------------
749 -- Register_Foreign_Thread --
750 -----------------------------
752 function Register_Foreign_Thread return Task_Id is
754 if Is_Valid_Task then
757 return Register_Foreign_Thread (pthread_self);
759 end Register_Foreign_Thread;
765 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
766 Mutex_Attr : aliased pthread_mutexattr_t;
767 Result : Interfaces.C.int;
768 Cond_Attr : aliased pthread_condattr_t;
771 if not Single_Lock then
772 Result := pthread_mutexattr_init (Mutex_Attr'Access);
773 pragma Assert (Result = 0 or else Result = ENOMEM);
778 (Self_ID.Common.LL.L'Access, Mutex_Attr'Access);
779 pragma Assert (Result = 0 or else Result = ENOMEM);
787 Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
788 pragma Assert (Result = 0);
791 Result := pthread_condattr_init (Cond_Attr'Access);
792 pragma Assert (Result = 0 or else Result = ENOMEM);
797 (Self_ID.Common.LL.CV'Access,
799 pragma Assert (Result = 0 or else Result = ENOMEM);
805 if not Single_Lock then
806 Result := pthread_mutex_destroy (Self_ID.Common.LL.L'Access);
807 pragma Assert (Result = 0);
813 Result := pthread_condattr_destroy (Cond_Attr'Access);
814 pragma Assert (Result = 0);
821 procedure Create_Task
823 Wrapper : System.Address;
824 Stack_Size : System.Parameters.Size_Type;
825 Priority : System.Any_Priority;
826 Succeeded : out Boolean)
828 Attributes : aliased pthread_attr_t;
829 Result : Interfaces.C.int;
831 function Thread_Body_Access is new
832 Ada.Unchecked_Conversion (System.Address, Thread_Body);
835 Result := pthread_attr_init (Attributes'Access);
836 pragma Assert (Result = 0 or else Result = ENOMEM);
843 Result := pthread_attr_setstacksize
844 (Attributes'Access, Interfaces.C.size_t (Stack_Size));
845 pragma Assert (Result = 0);
847 -- Since the initial signal mask of a thread is inherited from the
848 -- creator, and the Environment task has all its signals masked, we
849 -- do not need to manipulate caller's signal mask at this point.
850 -- All tasks in RTS will have All_Tasks_Mask initially.
852 Result := pthread_create
853 (T.Common.LL.Thread'Access,
855 Thread_Body_Access (Wrapper),
857 pragma Assert (Result = 0 or else Result = EAGAIN);
859 Succeeded := Result = 0;
861 pthread_detach (T.Common.LL.Thread'Access);
862 -- Detach the thread using pthread_detach, since DCE threads do not have
863 -- pthread_attr_set_detachstate.
865 Result := pthread_attr_destroy (Attributes'Access);
866 pragma Assert (Result = 0);
868 Set_Priority (T, Priority);
875 procedure Finalize_TCB (T : Task_Id) is
876 Result : Interfaces.C.int;
878 Is_Self : constant Boolean := T = Self;
880 procedure Free is new
881 Ada.Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
884 if not Single_Lock then
885 Result := pthread_mutex_destroy (T.Common.LL.L'Access);
886 pragma Assert (Result = 0);
889 Result := pthread_cond_destroy (T.Common.LL.CV'Access);
890 pragma Assert (Result = 0);
892 if T.Known_Tasks_Index /= -1 then
893 Known_Tasks (T.Known_Tasks_Index) := null;
907 procedure Exit_Task is
916 procedure Abort_Task (T : Task_Id) is
918 -- Interrupt Server_Tasks may be waiting on an "event" flag (signal)
920 if T.Common.State = Interrupt_Server_Blocked_On_Event_Flag then
921 System.Interrupt_Management.Operations.Interrupt_Self_Process
922 (System.Interrupt_Management.Interrupt_ID
923 (PIO.Get_Interrupt_ID (T)));
931 procedure Initialize (S : in out Suspension_Object) is
932 Mutex_Attr : aliased pthread_mutexattr_t;
933 Cond_Attr : aliased pthread_condattr_t;
934 Result : Interfaces.C.int;
936 -- Initialize internal state (always to False (ARM D.10(6)))
941 -- Initialize internal mutex
943 Result := pthread_mutex_init (S.L'Access, Mutex_Attr'Access);
944 pragma Assert (Result = 0 or else Result = ENOMEM);
946 if Result = ENOMEM then
950 -- Initialize internal condition variable
952 Result := pthread_cond_init (S.CV'Access, Cond_Attr'Access);
953 pragma Assert (Result = 0 or else Result = ENOMEM);
956 Result := pthread_mutex_destroy (S.L'Access);
957 pragma Assert (Result = 0);
959 if Result = ENOMEM then
969 procedure Finalize (S : in out Suspension_Object) is
970 Result : Interfaces.C.int;
973 -- Destroy internal mutex
975 Result := pthread_mutex_destroy (S.L'Access);
976 pragma Assert (Result = 0);
978 -- Destroy internal condition variable
980 Result := pthread_cond_destroy (S.CV'Access);
981 pragma Assert (Result = 0);
988 function Current_State (S : Suspension_Object) return Boolean is
990 -- We do not want to use lock on this read operation. State is marked
991 -- as Atomic so that we ensure that the value retrieved is correct.
1000 procedure Set_False (S : in out Suspension_Object) is
1001 Result : Interfaces.C.int;
1004 SSL.Abort_Defer.all;
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);
1014 SSL.Abort_Undefer.all;
1021 procedure Set_True (S : in out Suspension_Object) is
1022 Result : Interfaces.C.int;
1025 SSL.Abort_Defer.all;
1027 Result := pthread_mutex_lock (S.L'Access);
1028 pragma Assert (Result = 0);
1030 -- If there is already a task waiting on this suspension object then
1031 -- we resume it, leaving the state of the suspension object to False,
1032 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1033 -- the state to True.
1039 Result := pthread_cond_signal (S.CV'Access);
1040 pragma Assert (Result = 0);
1046 Result := pthread_mutex_unlock (S.L'Access);
1047 pragma Assert (Result = 0);
1049 SSL.Abort_Undefer.all;
1052 ------------------------
1053 -- Suspend_Until_True --
1054 ------------------------
1056 procedure Suspend_Until_True (S : in out Suspension_Object) is
1057 Result : Interfaces.C.int;
1060 SSL.Abort_Defer.all;
1062 Result := pthread_mutex_lock (S.L'Access);
1063 pragma Assert (Result = 0);
1066 -- Program_Error must be raised upon calling Suspend_Until_True
1067 -- if another task is already waiting on that suspension object
1068 -- (ARM D.10 par. 10).
1070 Result := pthread_mutex_unlock (S.L'Access);
1071 pragma Assert (Result = 0);
1073 SSL.Abort_Undefer.all;
1075 raise Program_Error;
1077 -- Suspend the task if the state is False. Otherwise, the task
1078 -- continues its execution, and the state of the suspension object
1079 -- is set to False (ARM D.10 par. 9).
1085 Result := pthread_cond_wait (S.CV'Access, S.L'Access);
1088 Result := pthread_mutex_unlock (S.L'Access);
1089 pragma Assert (Result = 0);
1091 SSL.Abort_Undefer.all;
1093 end Suspend_Until_True;
1101 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1102 pragma Unreferenced (Self_ID);
1107 --------------------
1108 -- Check_No_Locks --
1109 --------------------
1111 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1112 pragma Unreferenced (Self_ID);
1117 ----------------------
1118 -- Environment_Task --
1119 ----------------------
1121 function Environment_Task return Task_Id is
1123 return Environment_Task_Id;
1124 end Environment_Task;
1130 procedure Lock_RTS is
1132 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1139 procedure Unlock_RTS is
1141 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1148 function Suspend_Task
1150 Thread_Self : Thread_Id) return Boolean
1152 pragma Unreferenced (T);
1153 pragma Unreferenced (Thread_Self);
1162 function Resume_Task
1164 Thread_Self : Thread_Id) return Boolean
1166 pragma Unreferenced (T);
1167 pragma Unreferenced (Thread_Self);
1172 --------------------
1173 -- Stop_All_Tasks --
1174 --------------------
1176 procedure Stop_All_Tasks is
1185 function Stop_Task (T : ST.Task_Id) return Boolean is
1186 pragma Unreferenced (T);
1195 function Continue_Task (T : ST.Task_Id) return Boolean is
1196 pragma Unreferenced (T);
1205 procedure Initialize (Environment_Task : Task_Id) is
1206 act : aliased struct_sigaction;
1207 old_act : aliased struct_sigaction;
1208 Tmp_Set : aliased sigset_t;
1209 Result : Interfaces.C.int;
1212 (Int : System.Interrupt_Management.Interrupt_ID) return Character;
1213 pragma Import (C, State, "__gnat_get_interrupt_state");
1214 -- Get interrupt state. Defined in a-init.c. The input argument is
1215 -- the interrupt number, and the result is one of the following:
1217 Default : constant Character := 's';
1218 -- 'n' this interrupt not set by any Interrupt_State pragma
1219 -- 'u' Interrupt_State pragma set state to User
1220 -- 'r' Interrupt_State pragma set state to Runtime
1221 -- 's' Interrupt_State pragma set state to System (use "default"
1225 Environment_Task_Id := Environment_Task;
1227 Interrupt_Management.Initialize;
1229 -- Initialize the lock used to synchronize chain of all ATCBs
1231 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1233 Specific.Initialize (Environment_Task);
1235 Enter_Task (Environment_Task);
1237 -- Install the abort-signal handler
1239 if State (System.Interrupt_Management.Abort_Task_Interrupt)
1243 act.sa_handler := Abort_Handler'Address;
1245 Result := sigemptyset (Tmp_Set'Access);
1246 pragma Assert (Result = 0);
1247 act.sa_mask := Tmp_Set;
1251 Signal (System.Interrupt_Management.Abort_Task_Interrupt),
1252 act'Unchecked_Access,
1253 old_act'Unchecked_Access);
1254 pragma Assert (Result = 0);
1258 -- NOTE: Unlike other pthread implementations, we do *not* mask all
1259 -- signals here since we handle signals using the process-wide primitive
1260 -- signal, rather than using sigthreadmask and sigwait. The reason of
1261 -- this difference is that sigwait doesn't work when some critical
1262 -- signals (SIGABRT, SIGPIPE) are masked.
1264 end System.Task_Primitives.Operations;