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-2009, 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 3, or (at your option) any later ver- --
14 -- sion. GNAT 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 -- This is a HP-UX DCE threads (HPUX 10) version of this package
34 -- This package contains all the GNULL primitives that interface directly with
38 -- Turn off polling, we do not want ATC polling to take place during tasking
39 -- operations. It causes infinite loops and other problems.
41 with Ada.Unchecked_Conversion;
42 with Ada.Unchecked_Deallocation;
46 with System.Tasking.Debug;
47 with System.Interrupt_Management;
48 with System.OS_Primitives;
49 with System.Task_Primitives.Interrupt_Operations;
51 pragma Warnings (Off);
52 with System.Interrupt_Management.Operations;
53 pragma Elaborate_All (System.Interrupt_Management.Operations);
56 with System.Soft_Links;
57 -- We use System.Soft_Links instead of System.Tasking.Initialization
58 -- because the later is a higher level package that we shouldn't depend on.
59 -- For example when using the restricted run time, it is replaced by
60 -- System.Tasking.Restricted.Stages.
62 package body System.Task_Primitives.Operations is
64 package SSL renames System.Soft_Links;
66 use System.Tasking.Debug;
69 use System.OS_Interface;
70 use System.Parameters;
71 use System.OS_Primitives;
73 package PIO renames System.Task_Primitives.Interrupt_Operations;
79 -- The followings are logically constants, but need to be initialized
82 Single_RTS_Lock : aliased RTS_Lock;
83 -- This is a lock to allow only one thread of control in the RTS at
84 -- a time; it is used to execute in mutual exclusion from all other tasks.
85 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
87 ATCB_Key : aliased pthread_key_t;
88 -- Key used to find the Ada Task_Id associated with a thread
90 Environment_Task_Id : Task_Id;
91 -- A variable to hold Task_Id for the environment task
93 Unblocked_Signal_Mask : aliased sigset_t;
94 -- The set of signals that should unblocked in all tasks
96 Time_Slice_Val : Integer;
97 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
99 Dispatching_Policy : Character;
100 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
102 -- Note: the reason that Locking_Policy is not needed is that this
103 -- is not implemented for DCE threads. The HPUX 10 port is at this
104 -- stage considered dead, and no further work is planned on it.
106 Foreign_Task_Elaborated : aliased Boolean := True;
107 -- Used to identified fake tasks (i.e., non-Ada Threads)
115 procedure Initialize (Environment_Task : Task_Id);
116 pragma Inline (Initialize);
117 -- Initialize various data needed by this package
119 function Is_Valid_Task return Boolean;
120 pragma Inline (Is_Valid_Task);
121 -- Does the executing thread have a TCB?
123 procedure Set (Self_Id : Task_Id);
125 -- Set the self id for the current task
127 function Self return Task_Id;
128 pragma Inline (Self);
129 -- Return a pointer to the Ada Task Control Block of the calling task
133 package body Specific is separate;
134 -- The body of this package is target specific
136 ---------------------------------
137 -- Support for foreign threads --
138 ---------------------------------
140 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
141 -- Allocate and Initialize a new ATCB for the current Thread
143 function Register_Foreign_Thread
144 (Thread : Thread_Id) return Task_Id is separate;
146 -----------------------
147 -- Local Subprograms --
148 -----------------------
150 procedure Abort_Handler (Sig : Signal);
152 function To_Address is
153 new Ada.Unchecked_Conversion (Task_Id, System.Address);
159 procedure Abort_Handler (Sig : Signal) is
160 pragma Unreferenced (Sig);
162 Self_Id : constant Task_Id := Self;
163 Result : Interfaces.C.int;
164 Old_Set : aliased sigset_t;
167 if Self_Id.Deferral_Level = 0
168 and then Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level
169 and then not Self_Id.Aborting
171 Self_Id.Aborting := True;
173 -- Make sure signals used for RTS internal purpose are unmasked
178 Unblocked_Signal_Mask'Access,
180 pragma Assert (Result = 0);
182 raise Standard'Abort_Signal;
190 -- The underlying thread system sets a guard page at the bottom of a thread
191 -- stack, so nothing is needed.
192 -- ??? Check the comment above
194 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
195 pragma Unreferenced (T, On);
204 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
206 return T.Common.LL.Thread;
213 function Self return Task_Id renames Specific.Self;
215 ---------------------
216 -- Initialize_Lock --
217 ---------------------
219 -- Note: mutexes and cond_variables needed per-task basis are initialized
220 -- in Initialize_TCB and the Storage_Error is handled. Other mutexes (such
221 -- as RTS_Lock, Memory_Lock...) used in RTS is initialized before any
222 -- status change of RTS. Therefore raising Storage_Error in the following
223 -- routines should be able to be handled safely.
225 procedure Initialize_Lock
226 (Prio : System.Any_Priority;
227 L : not null access Lock)
229 Attributes : aliased pthread_mutexattr_t;
230 Result : Interfaces.C.int;
233 Result := pthread_mutexattr_init (Attributes'Access);
234 pragma Assert (Result = 0 or else Result = ENOMEM);
236 if Result = ENOMEM then
242 Result := pthread_mutex_init (L.L'Access, Attributes'Access);
243 pragma Assert (Result = 0 or else Result = ENOMEM);
245 if Result = ENOMEM then
249 Result := pthread_mutexattr_destroy (Attributes'Access);
250 pragma Assert (Result = 0);
253 procedure Initialize_Lock
254 (L : not null access RTS_Lock;
257 pragma Unreferenced (Level);
259 Attributes : aliased pthread_mutexattr_t;
260 Result : Interfaces.C.int;
263 Result := pthread_mutexattr_init (Attributes'Access);
264 pragma Assert (Result = 0 or else Result = ENOMEM);
266 if Result = ENOMEM then
270 Result := pthread_mutex_init (L, Attributes'Access);
272 pragma Assert (Result = 0 or else Result = ENOMEM);
274 if Result = ENOMEM then
278 Result := pthread_mutexattr_destroy (Attributes'Access);
279 pragma Assert (Result = 0);
286 procedure Finalize_Lock (L : not null access Lock) is
287 Result : Interfaces.C.int;
289 Result := pthread_mutex_destroy (L.L'Access);
290 pragma Assert (Result = 0);
293 procedure Finalize_Lock (L : not null access RTS_Lock) is
294 Result : Interfaces.C.int;
296 Result := pthread_mutex_destroy (L);
297 pragma Assert (Result = 0);
305 (L : not null access Lock;
306 Ceiling_Violation : out Boolean)
308 Result : Interfaces.C.int;
311 L.Owner_Priority := Get_Priority (Self);
313 if L.Priority < L.Owner_Priority then
314 Ceiling_Violation := True;
318 Result := pthread_mutex_lock (L.L'Access);
319 pragma Assert (Result = 0);
320 Ceiling_Violation := False;
324 (L : not null access RTS_Lock;
325 Global_Lock : Boolean := False)
327 Result : Interfaces.C.int;
329 if not Single_Lock or else Global_Lock then
330 Result := pthread_mutex_lock (L);
331 pragma Assert (Result = 0);
335 procedure Write_Lock (T : Task_Id) is
336 Result : Interfaces.C.int;
338 if not Single_Lock then
339 Result := pthread_mutex_lock (T.Common.LL.L'Access);
340 pragma Assert (Result = 0);
349 (L : not null access Lock;
350 Ceiling_Violation : out Boolean)
353 Write_Lock (L, Ceiling_Violation);
360 procedure Unlock (L : not null access Lock) is
361 Result : Interfaces.C.int;
363 Result := pthread_mutex_unlock (L.L'Access);
364 pragma Assert (Result = 0);
368 (L : not null access RTS_Lock;
369 Global_Lock : Boolean := False)
371 Result : Interfaces.C.int;
373 if not Single_Lock or else Global_Lock then
374 Result := pthread_mutex_unlock (L);
375 pragma Assert (Result = 0);
379 procedure Unlock (T : Task_Id) is
380 Result : Interfaces.C.int;
382 if not Single_Lock then
383 Result := pthread_mutex_unlock (T.Common.LL.L'Access);
384 pragma Assert (Result = 0);
392 -- Dynamic priority ceilings are not supported by the underlying system
394 procedure Set_Ceiling
395 (L : not null access Lock;
396 Prio : System.Any_Priority)
398 pragma Unreferenced (L, Prio);
409 Reason : System.Tasking.Task_States)
411 pragma Unreferenced (Reason);
413 Result : Interfaces.C.int;
418 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
422 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
425 -- EINTR is not considered a failure
427 pragma Assert (Result = 0 or else Result = EINTR);
434 procedure Timed_Sleep
437 Mode : ST.Delay_Modes;
438 Reason : System.Tasking.Task_States;
439 Timedout : out Boolean;
440 Yielded : out Boolean)
442 pragma Unreferenced (Reason);
444 Check_Time : constant Duration := Monotonic_Clock;
446 Request : aliased timespec;
447 Result : Interfaces.C.int;
453 if Mode = Relative then
454 Abs_Time := Duration'Min (Time, Max_Sensible_Delay) + Check_Time;
456 Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time);
459 if Abs_Time > Check_Time then
460 Request := To_Timespec (Abs_Time);
463 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
467 pthread_cond_timedwait
468 (Self_ID.Common.LL.CV'Access,
469 Single_RTS_Lock'Access,
474 pthread_cond_timedwait
475 (Self_ID.Common.LL.CV'Access,
476 Self_ID.Common.LL.L'Access,
480 exit when Abs_Time <= Monotonic_Clock;
482 if Result = 0 or Result = EINTR then
484 -- Somebody may have called Wakeup for us
490 pragma Assert (Result = ETIMEDOUT);
499 procedure Timed_Delay
502 Mode : ST.Delay_Modes)
504 Check_Time : constant Duration := Monotonic_Clock;
506 Request : aliased timespec;
508 Result : Interfaces.C.int;
509 pragma Warnings (Off, Result);
516 Write_Lock (Self_ID);
518 if Mode = Relative then
519 Abs_Time := Time + Check_Time;
521 Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time);
524 if Abs_Time > Check_Time then
525 Request := To_Timespec (Abs_Time);
526 Self_ID.Common.State := Delay_Sleep;
529 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
533 pthread_cond_timedwait
534 (Self_ID.Common.LL.CV'Access,
535 Single_RTS_Lock'Access,
539 pthread_cond_timedwait
540 (Self_ID.Common.LL.CV'Access,
541 Self_ID.Common.LL.L'Access,
545 exit when Abs_Time <= Monotonic_Clock;
547 pragma Assert (Result = 0 or else
548 Result = ETIMEDOUT or else
552 Self_ID.Common.State := Runnable;
561 Result := sched_yield;
564 ---------------------
565 -- Monotonic_Clock --
566 ---------------------
568 function Monotonic_Clock return Duration is
569 TS : aliased timespec;
570 Result : Interfaces.C.int;
572 Result := Clock_Gettime (CLOCK_REALTIME, TS'Unchecked_Access);
573 pragma Assert (Result = 0);
574 return To_Duration (TS);
581 function RT_Resolution return Duration is
590 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
591 pragma Unreferenced (Reason);
592 Result : Interfaces.C.int;
594 Result := pthread_cond_signal (T.Common.LL.CV'Access);
595 pragma Assert (Result = 0);
602 procedure Yield (Do_Yield : Boolean := True) is
603 Result : Interfaces.C.int;
604 pragma Unreferenced (Result);
607 Result := sched_yield;
615 type Prio_Array_Type is array (System.Any_Priority) of Integer;
616 pragma Atomic_Components (Prio_Array_Type);
618 Prio_Array : Prio_Array_Type;
619 -- Global array containing the id of the currently running task for
622 -- Note: assume we are on single processor with run-til-blocked scheduling
624 procedure Set_Priority
626 Prio : System.Any_Priority;
627 Loss_Of_Inheritance : Boolean := False)
629 Result : Interfaces.C.int;
630 Array_Item : Integer;
631 Param : aliased struct_sched_param;
633 function Get_Policy (Prio : System.Any_Priority) return Character;
634 pragma Import (C, Get_Policy, "__gnat_get_specific_dispatching");
635 -- Get priority specific dispatching policy
637 Priority_Specific_Policy : constant Character := Get_Policy (Prio);
638 -- Upper case first character of the policy name corresponding to the
639 -- task as set by a Priority_Specific_Dispatching pragma.
642 Param.sched_priority := Interfaces.C.int (Underlying_Priorities (Prio));
644 if Dispatching_Policy = 'R'
645 or else Priority_Specific_Policy = 'R'
646 or else Time_Slice_Val > 0
649 pthread_setschedparam
650 (T.Common.LL.Thread, SCHED_RR, Param'Access);
652 elsif Dispatching_Policy = 'F'
653 or else Priority_Specific_Policy = 'F'
654 or else Time_Slice_Val = 0
657 pthread_setschedparam
658 (T.Common.LL.Thread, SCHED_FIFO, Param'Access);
662 pthread_setschedparam
663 (T.Common.LL.Thread, SCHED_OTHER, Param'Access);
666 pragma Assert (Result = 0);
668 if Dispatching_Policy = 'F' or else Priority_Specific_Policy = 'F' then
670 -- Annex D requirement [RM D.2.2 par. 9]:
671 -- If the task drops its priority due to the loss of inherited
672 -- priority, it is added at the head of the ready queue for its
673 -- new active priority.
675 if Loss_Of_Inheritance
676 and then Prio < T.Common.Current_Priority
678 Array_Item := Prio_Array (T.Common.Base_Priority) + 1;
679 Prio_Array (T.Common.Base_Priority) := Array_Item;
682 -- Let some processes a chance to arrive
686 -- Then wait for our turn to proceed
688 exit when Array_Item = Prio_Array (T.Common.Base_Priority)
689 or else Prio_Array (T.Common.Base_Priority) = 1;
692 Prio_Array (T.Common.Base_Priority) :=
693 Prio_Array (T.Common.Base_Priority) - 1;
697 T.Common.Current_Priority := Prio;
704 function Get_Priority (T : Task_Id) return System.Any_Priority is
706 return T.Common.Current_Priority;
713 procedure Enter_Task (Self_ID : Task_Id) is
715 Self_ID.Common.LL.Thread := pthread_self;
716 Specific.Set (Self_ID);
723 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
725 return new Ada_Task_Control_Block (Entry_Num);
732 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
734 -----------------------------
735 -- Register_Foreign_Thread --
736 -----------------------------
738 function Register_Foreign_Thread return Task_Id is
740 if Is_Valid_Task then
743 return Register_Foreign_Thread (pthread_self);
745 end Register_Foreign_Thread;
751 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
752 Mutex_Attr : aliased pthread_mutexattr_t;
753 Result : Interfaces.C.int;
754 Cond_Attr : aliased pthread_condattr_t;
757 if not Single_Lock then
758 Result := pthread_mutexattr_init (Mutex_Attr'Access);
759 pragma Assert (Result = 0 or else Result = ENOMEM);
764 (Self_ID.Common.LL.L'Access, Mutex_Attr'Access);
765 pragma Assert (Result = 0 or else Result = ENOMEM);
773 Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
774 pragma Assert (Result = 0);
777 Result := pthread_condattr_init (Cond_Attr'Access);
778 pragma Assert (Result = 0 or else Result = ENOMEM);
783 (Self_ID.Common.LL.CV'Access,
785 pragma Assert (Result = 0 or else Result = ENOMEM);
791 if not Single_Lock then
792 Result := pthread_mutex_destroy (Self_ID.Common.LL.L'Access);
793 pragma Assert (Result = 0);
799 Result := pthread_condattr_destroy (Cond_Attr'Access);
800 pragma Assert (Result = 0);
807 procedure Create_Task
809 Wrapper : System.Address;
810 Stack_Size : System.Parameters.Size_Type;
811 Priority : System.Any_Priority;
812 Succeeded : out Boolean)
814 Attributes : aliased pthread_attr_t;
815 Result : Interfaces.C.int;
817 function Thread_Body_Access is new
818 Ada.Unchecked_Conversion (System.Address, Thread_Body);
821 Result := pthread_attr_init (Attributes'Access);
822 pragma Assert (Result = 0 or else Result = ENOMEM);
829 Result := pthread_attr_setstacksize
830 (Attributes'Access, Interfaces.C.size_t (Stack_Size));
831 pragma Assert (Result = 0);
833 -- Since the initial signal mask of a thread is inherited from the
834 -- creator, and the Environment task has all its signals masked, we
835 -- do not need to manipulate caller's signal mask at this point.
836 -- All tasks in RTS will have All_Tasks_Mask initially.
838 Result := pthread_create
839 (T.Common.LL.Thread'Access,
841 Thread_Body_Access (Wrapper),
843 pragma Assert (Result = 0 or else Result = EAGAIN);
845 Succeeded := Result = 0;
847 pthread_detach (T.Common.LL.Thread'Access);
848 -- Detach the thread using pthread_detach, since DCE threads do not have
849 -- pthread_attr_set_detachstate.
851 Result := pthread_attr_destroy (Attributes'Access);
852 pragma Assert (Result = 0);
854 Set_Priority (T, Priority);
861 procedure Finalize_TCB (T : Task_Id) is
862 Result : Interfaces.C.int;
864 Is_Self : constant Boolean := T = Self;
866 procedure Free is new
867 Ada.Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
870 if not Single_Lock then
871 Result := pthread_mutex_destroy (T.Common.LL.L'Access);
872 pragma Assert (Result = 0);
875 Result := pthread_cond_destroy (T.Common.LL.CV'Access);
876 pragma Assert (Result = 0);
878 if T.Known_Tasks_Index /= -1 then
879 Known_Tasks (T.Known_Tasks_Index) := null;
893 procedure Exit_Task is
902 procedure Abort_Task (T : Task_Id) is
904 -- Interrupt Server_Tasks may be waiting on an "event" flag (signal)
906 if T.Common.State = Interrupt_Server_Blocked_On_Event_Flag then
907 System.Interrupt_Management.Operations.Interrupt_Self_Process
908 (System.Interrupt_Management.Interrupt_ID
909 (PIO.Get_Interrupt_ID (T)));
917 procedure Initialize (S : in out Suspension_Object) is
918 Mutex_Attr : aliased pthread_mutexattr_t;
919 Cond_Attr : aliased pthread_condattr_t;
920 Result : Interfaces.C.int;
922 -- Initialize internal state (always to False (ARM D.10(6)))
927 -- Initialize internal mutex
929 Result := pthread_mutex_init (S.L'Access, Mutex_Attr'Access);
930 pragma Assert (Result = 0 or else Result = ENOMEM);
932 if Result = ENOMEM then
936 -- Initialize internal condition variable
938 Result := pthread_cond_init (S.CV'Access, Cond_Attr'Access);
939 pragma Assert (Result = 0 or else Result = ENOMEM);
942 Result := pthread_mutex_destroy (S.L'Access);
943 pragma Assert (Result = 0);
945 if Result = ENOMEM then
955 procedure Finalize (S : in out Suspension_Object) is
956 Result : Interfaces.C.int;
959 -- Destroy internal mutex
961 Result := pthread_mutex_destroy (S.L'Access);
962 pragma Assert (Result = 0);
964 -- Destroy internal condition variable
966 Result := pthread_cond_destroy (S.CV'Access);
967 pragma Assert (Result = 0);
974 function Current_State (S : Suspension_Object) return Boolean is
976 -- We do not want to use lock on this read operation. State is marked
977 -- as Atomic so that we ensure that the value retrieved is correct.
986 procedure Set_False (S : in out Suspension_Object) is
987 Result : Interfaces.C.int;
992 Result := pthread_mutex_lock (S.L'Access);
993 pragma Assert (Result = 0);
997 Result := pthread_mutex_unlock (S.L'Access);
998 pragma Assert (Result = 0);
1000 SSL.Abort_Undefer.all;
1007 procedure Set_True (S : in out Suspension_Object) is
1008 Result : Interfaces.C.int;
1011 SSL.Abort_Defer.all;
1013 Result := pthread_mutex_lock (S.L'Access);
1014 pragma Assert (Result = 0);
1016 -- If there is already a task waiting on this suspension object then
1017 -- we resume it, leaving the state of the suspension object to False,
1018 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1019 -- the state to True.
1025 Result := pthread_cond_signal (S.CV'Access);
1026 pragma Assert (Result = 0);
1032 Result := pthread_mutex_unlock (S.L'Access);
1033 pragma Assert (Result = 0);
1035 SSL.Abort_Undefer.all;
1038 ------------------------
1039 -- Suspend_Until_True --
1040 ------------------------
1042 procedure Suspend_Until_True (S : in out Suspension_Object) is
1043 Result : Interfaces.C.int;
1046 SSL.Abort_Defer.all;
1048 Result := pthread_mutex_lock (S.L'Access);
1049 pragma Assert (Result = 0);
1052 -- Program_Error must be raised upon calling Suspend_Until_True
1053 -- if another task is already waiting on that suspension object
1054 -- (ARM D.10 par. 10).
1056 Result := pthread_mutex_unlock (S.L'Access);
1057 pragma Assert (Result = 0);
1059 SSL.Abort_Undefer.all;
1061 raise Program_Error;
1063 -- Suspend the task if the state is False. Otherwise, the task
1064 -- continues its execution, and the state of the suspension object
1065 -- is set to False (ARM D.10 par. 9).
1073 -- Loop in case pthread_cond_wait returns earlier than expected
1074 -- (e.g. in case of EINTR caused by a signal).
1076 Result := pthread_cond_wait (S.CV'Access, S.L'Access);
1077 pragma Assert (Result = 0 or else Result = EINTR);
1079 exit when not S.Waiting;
1083 Result := pthread_mutex_unlock (S.L'Access);
1084 pragma Assert (Result = 0);
1086 SSL.Abort_Undefer.all;
1088 end Suspend_Until_True;
1096 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1097 pragma Unreferenced (Self_ID);
1102 --------------------
1103 -- Check_No_Locks --
1104 --------------------
1106 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1107 pragma Unreferenced (Self_ID);
1112 ----------------------
1113 -- Environment_Task --
1114 ----------------------
1116 function Environment_Task return Task_Id is
1118 return Environment_Task_Id;
1119 end Environment_Task;
1125 procedure Lock_RTS is
1127 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1134 procedure Unlock_RTS is
1136 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1143 function Suspend_Task
1145 Thread_Self : Thread_Id) return Boolean
1147 pragma Unreferenced (T);
1148 pragma Unreferenced (Thread_Self);
1157 function Resume_Task
1159 Thread_Self : Thread_Id) return Boolean
1161 pragma Unreferenced (T);
1162 pragma Unreferenced (Thread_Self);
1167 --------------------
1168 -- Stop_All_Tasks --
1169 --------------------
1171 procedure Stop_All_Tasks is
1180 function Stop_Task (T : ST.Task_Id) return Boolean is
1181 pragma Unreferenced (T);
1190 function Continue_Task (T : ST.Task_Id) return Boolean is
1191 pragma Unreferenced (T);
1200 procedure Initialize (Environment_Task : Task_Id) is
1201 act : aliased struct_sigaction;
1202 old_act : aliased struct_sigaction;
1203 Tmp_Set : aliased sigset_t;
1204 Result : Interfaces.C.int;
1207 (Int : System.Interrupt_Management.Interrupt_ID) return Character;
1208 pragma Import (C, State, "__gnat_get_interrupt_state");
1209 -- Get interrupt state. Defined in a-init.c. The input argument is
1210 -- the interrupt number, and the result is one of the following:
1212 Default : constant Character := 's';
1213 -- 'n' this interrupt not set by any Interrupt_State pragma
1214 -- 'u' Interrupt_State pragma set state to User
1215 -- 'r' Interrupt_State pragma set state to Runtime
1216 -- 's' Interrupt_State pragma set state to System (use "default"
1220 Environment_Task_Id := Environment_Task;
1222 Interrupt_Management.Initialize;
1224 -- Initialize the lock used to synchronize chain of all ATCBs
1226 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1228 Specific.Initialize (Environment_Task);
1230 -- Make environment task known here because it doesn't go through
1231 -- Activate_Tasks, which does it for all other tasks.
1233 Known_Tasks (Known_Tasks'First) := Environment_Task;
1234 Environment_Task.Known_Tasks_Index := Known_Tasks'First;
1236 Enter_Task (Environment_Task);
1238 -- Install the abort-signal handler
1240 if State (System.Interrupt_Management.Abort_Task_Interrupt)
1244 act.sa_handler := Abort_Handler'Address;
1246 Result := sigemptyset (Tmp_Set'Access);
1247 pragma Assert (Result = 0);
1248 act.sa_mask := Tmp_Set;
1252 Signal (System.Interrupt_Management.Abort_Task_Interrupt),
1253 act'Unchecked_Access,
1254 old_act'Unchecked_Access);
1255 pragma Assert (Result = 0);
1259 -- NOTE: Unlike other pthread implementations, we do *not* mask all
1260 -- signals here since we handle signals using the process-wide primitive
1261 -- signal, rather than using sigthreadmask and sigwait. The reason of
1262 -- this difference is that sigwait doesn't work when some critical
1263 -- signals (SIGABRT, SIGPIPE) are masked.
1265 end System.Task_Primitives.Operations;