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-2011, 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;
45 with System.Tasking.Debug;
46 with System.Interrupt_Management;
47 with System.OS_Primitives;
48 with System.Task_Primitives.Interrupt_Operations;
50 pragma Warnings (Off);
51 with System.Interrupt_Management.Operations;
52 pragma Elaborate_All (System.Interrupt_Management.Operations);
55 with System.Soft_Links;
56 -- We use System.Soft_Links instead of System.Tasking.Initialization
57 -- because the later is a higher level package that we shouldn't depend on.
58 -- For example when using the restricted run time, it is replaced by
59 -- System.Tasking.Restricted.Stages.
61 package body System.Task_Primitives.Operations is
63 package SSL renames System.Soft_Links;
65 use System.Tasking.Debug;
68 use System.OS_Interface;
69 use System.Parameters;
70 use System.OS_Primitives;
72 package PIO renames System.Task_Primitives.Interrupt_Operations;
78 -- The followings are logically constants, but need to be initialized
81 Single_RTS_Lock : aliased RTS_Lock;
82 -- This is a lock to allow only one thread of control in the RTS at
83 -- a time; it is used to execute in mutual exclusion from all other tasks.
84 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
86 Environment_Task_Id : Task_Id;
87 -- A variable to hold Task_Id for the environment task
89 Unblocked_Signal_Mask : aliased sigset_t;
90 -- The set of signals that should unblocked in all tasks
92 Time_Slice_Val : Integer;
93 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
95 Dispatching_Policy : Character;
96 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
98 -- Note: the reason that Locking_Policy is not needed is that this
99 -- is not implemented for DCE threads. The HPUX 10 port is at this
100 -- stage considered dead, and no further work is planned on it.
102 Foreign_Task_Elaborated : aliased Boolean := True;
103 -- Used to identified fake tasks (i.e., non-Ada Threads)
111 procedure Initialize (Environment_Task : Task_Id);
112 pragma Inline (Initialize);
113 -- Initialize various data needed by this package
115 function Is_Valid_Task return Boolean;
116 pragma Inline (Is_Valid_Task);
117 -- Does the executing thread have a TCB?
119 procedure Set (Self_Id : Task_Id);
121 -- Set the self id for the current task
123 function Self return Task_Id;
124 pragma Inline (Self);
125 -- Return a pointer to the Ada Task Control Block of the calling task
129 package body Specific is separate;
130 -- The body of this package is target specific
132 ----------------------------------
133 -- ATCB allocation/deallocation --
134 ----------------------------------
136 package body ATCB_Allocation is separate;
137 -- The body of this package is shared across several targets
139 ---------------------------------
140 -- Support for foreign threads --
141 ---------------------------------
143 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
144 -- Allocate and Initialize a new ATCB for the current Thread
146 function Register_Foreign_Thread
147 (Thread : Thread_Id) return Task_Id is separate;
149 -----------------------
150 -- Local Subprograms --
151 -----------------------
153 procedure Abort_Handler (Sig : Signal);
155 function To_Address is
156 new Ada.Unchecked_Conversion (Task_Id, System.Address);
162 procedure Abort_Handler (Sig : Signal) is
163 pragma Unreferenced (Sig);
165 Self_Id : constant Task_Id := Self;
166 Result : Interfaces.C.int;
167 Old_Set : aliased sigset_t;
170 if Self_Id.Deferral_Level = 0
171 and then Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level
172 and then not Self_Id.Aborting
174 Self_Id.Aborting := True;
176 -- Make sure signals used for RTS internal purpose are unmasked
181 Unblocked_Signal_Mask'Access,
183 pragma Assert (Result = 0);
185 raise Standard'Abort_Signal;
193 -- The underlying thread system sets a guard page at the bottom of a thread
194 -- stack, so nothing is needed.
195 -- ??? Check the comment above
197 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
198 pragma Unreferenced (T, On);
207 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
209 return T.Common.LL.Thread;
216 function Self return Task_Id renames Specific.Self;
218 ---------------------
219 -- Initialize_Lock --
220 ---------------------
222 -- Note: mutexes and cond_variables needed per-task basis are initialized
223 -- in Initialize_TCB and the Storage_Error is handled. Other mutexes (such
224 -- as RTS_Lock, Memory_Lock...) used in RTS is initialized before any
225 -- status change of RTS. Therefore raising Storage_Error in the following
226 -- routines should be able to be handled safely.
228 procedure Initialize_Lock
229 (Prio : System.Any_Priority;
230 L : not null access Lock)
232 Attributes : aliased pthread_mutexattr_t;
233 Result : Interfaces.C.int;
236 Result := pthread_mutexattr_init (Attributes'Access);
237 pragma Assert (Result = 0 or else Result = ENOMEM);
239 if Result = ENOMEM then
245 Result := pthread_mutex_init (L.L'Access, Attributes'Access);
246 pragma Assert (Result = 0 or else Result = ENOMEM);
248 if Result = ENOMEM then
252 Result := pthread_mutexattr_destroy (Attributes'Access);
253 pragma Assert (Result = 0);
256 procedure Initialize_Lock
257 (L : not null access RTS_Lock;
260 pragma Unreferenced (Level);
262 Attributes : aliased pthread_mutexattr_t;
263 Result : Interfaces.C.int;
266 Result := pthread_mutexattr_init (Attributes'Access);
267 pragma Assert (Result = 0 or else Result = ENOMEM);
269 if Result = ENOMEM then
273 Result := pthread_mutex_init (L, Attributes'Access);
275 pragma Assert (Result = 0 or else Result = ENOMEM);
277 if Result = ENOMEM then
281 Result := pthread_mutexattr_destroy (Attributes'Access);
282 pragma Assert (Result = 0);
289 procedure Finalize_Lock (L : not null access Lock) is
290 Result : Interfaces.C.int;
292 Result := pthread_mutex_destroy (L.L'Access);
293 pragma Assert (Result = 0);
296 procedure Finalize_Lock (L : not null access RTS_Lock) is
297 Result : Interfaces.C.int;
299 Result := pthread_mutex_destroy (L);
300 pragma Assert (Result = 0);
308 (L : not null access Lock;
309 Ceiling_Violation : out Boolean)
311 Result : Interfaces.C.int;
314 L.Owner_Priority := Get_Priority (Self);
316 if L.Priority < L.Owner_Priority then
317 Ceiling_Violation := True;
321 Result := pthread_mutex_lock (L.L'Access);
322 pragma Assert (Result = 0);
323 Ceiling_Violation := False;
327 (L : not null access RTS_Lock;
328 Global_Lock : Boolean := False)
330 Result : Interfaces.C.int;
332 if not Single_Lock or else Global_Lock then
333 Result := pthread_mutex_lock (L);
334 pragma Assert (Result = 0);
338 procedure Write_Lock (T : Task_Id) is
339 Result : Interfaces.C.int;
341 if not Single_Lock then
342 Result := pthread_mutex_lock (T.Common.LL.L'Access);
343 pragma Assert (Result = 0);
352 (L : not null access Lock;
353 Ceiling_Violation : out Boolean)
356 Write_Lock (L, Ceiling_Violation);
363 procedure Unlock (L : not null access Lock) is
364 Result : Interfaces.C.int;
366 Result := pthread_mutex_unlock (L.L'Access);
367 pragma Assert (Result = 0);
371 (L : not null access RTS_Lock;
372 Global_Lock : Boolean := False)
374 Result : Interfaces.C.int;
376 if not Single_Lock or else Global_Lock then
377 Result := pthread_mutex_unlock (L);
378 pragma Assert (Result = 0);
382 procedure Unlock (T : Task_Id) is
383 Result : Interfaces.C.int;
385 if not Single_Lock then
386 Result := pthread_mutex_unlock (T.Common.LL.L'Access);
387 pragma Assert (Result = 0);
395 -- Dynamic priority ceilings are not supported by the underlying system
397 procedure Set_Ceiling
398 (L : not null access Lock;
399 Prio : System.Any_Priority)
401 pragma Unreferenced (L, Prio);
412 Reason : System.Tasking.Task_States)
414 pragma Unreferenced (Reason);
416 Result : Interfaces.C.int;
421 (cond => Self_ID.Common.LL.CV'Access,
422 mutex => (if Single_Lock
423 then Single_RTS_Lock'Access
424 else Self_ID.Common.LL.L'Access));
426 -- EINTR is not considered a failure
428 pragma Assert (Result = 0 or else Result = EINTR);
435 procedure Timed_Sleep
438 Mode : ST.Delay_Modes;
439 Reason : System.Tasking.Task_States;
440 Timedout : out Boolean;
441 Yielded : out Boolean)
443 pragma Unreferenced (Reason);
445 Check_Time : constant Duration := Monotonic_Clock;
447 Request : aliased timespec;
448 Result : Interfaces.C.int;
456 then Duration'Min (Time, Max_Sensible_Delay) + Check_Time
457 else 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;
466 pthread_cond_timedwait
467 (cond => Self_ID.Common.LL.CV'Access,
468 mutex => (if Single_Lock
469 then Single_RTS_Lock'Access
470 else Self_ID.Common.LL.L'Access),
471 abstime => Request'Access);
473 exit when Abs_Time <= Monotonic_Clock;
475 if Result = 0 or Result = EINTR then
477 -- Somebody may have called Wakeup for us
483 pragma Assert (Result = ETIMEDOUT);
492 procedure Timed_Delay
495 Mode : ST.Delay_Modes)
497 Check_Time : constant Duration := Monotonic_Clock;
499 Request : aliased timespec;
501 Result : Interfaces.C.int;
502 pragma Warnings (Off, Result);
509 Write_Lock (Self_ID);
513 then Time + Check_Time
514 else Duration'Min (Check_Time + Max_Sensible_Delay, Time));
516 if Abs_Time > Check_Time then
517 Request := To_Timespec (Abs_Time);
518 Self_ID.Common.State := Delay_Sleep;
521 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
524 pthread_cond_timedwait
525 (cond => Self_ID.Common.LL.CV'Access,
526 mutex => (if Single_Lock
527 then Single_RTS_Lock'Access
528 else Self_ID.Common.LL.L'Access),
529 abstime => Request'Access);
531 exit when Abs_Time <= Monotonic_Clock;
533 pragma Assert (Result = 0 or else
534 Result = ETIMEDOUT or else
538 Self_ID.Common.State := Runnable;
547 Result := sched_yield;
550 ---------------------
551 -- Monotonic_Clock --
552 ---------------------
554 function Monotonic_Clock return Duration is
555 TS : aliased timespec;
556 Result : Interfaces.C.int;
558 Result := Clock_Gettime (CLOCK_REALTIME, TS'Unchecked_Access);
559 pragma Assert (Result = 0);
560 return To_Duration (TS);
567 function RT_Resolution return Duration is
576 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
577 pragma Unreferenced (Reason);
578 Result : Interfaces.C.int;
580 Result := pthread_cond_signal (T.Common.LL.CV'Access);
581 pragma Assert (Result = 0);
588 procedure Yield (Do_Yield : Boolean := True) is
589 Result : Interfaces.C.int;
590 pragma Unreferenced (Result);
593 Result := sched_yield;
601 type Prio_Array_Type is array (System.Any_Priority) of Integer;
602 pragma Atomic_Components (Prio_Array_Type);
604 Prio_Array : Prio_Array_Type;
605 -- Global array containing the id of the currently running task for
608 -- Note: assume we are on single processor with run-til-blocked scheduling
610 procedure Set_Priority
612 Prio : System.Any_Priority;
613 Loss_Of_Inheritance : Boolean := False)
615 Result : Interfaces.C.int;
616 Array_Item : Integer;
617 Param : aliased struct_sched_param;
619 function Get_Policy (Prio : System.Any_Priority) return Character;
620 pragma Import (C, Get_Policy, "__gnat_get_specific_dispatching");
621 -- Get priority specific dispatching policy
623 Priority_Specific_Policy : constant Character := Get_Policy (Prio);
624 -- Upper case first character of the policy name corresponding to the
625 -- task as set by a Priority_Specific_Dispatching pragma.
628 Param.sched_priority := Interfaces.C.int (Underlying_Priorities (Prio));
630 if Dispatching_Policy = 'R'
631 or else Priority_Specific_Policy = 'R'
632 or else Time_Slice_Val > 0
635 pthread_setschedparam
636 (T.Common.LL.Thread, SCHED_RR, Param'Access);
638 elsif Dispatching_Policy = 'F'
639 or else Priority_Specific_Policy = 'F'
640 or else Time_Slice_Val = 0
643 pthread_setschedparam
644 (T.Common.LL.Thread, SCHED_FIFO, Param'Access);
648 pthread_setschedparam
649 (T.Common.LL.Thread, SCHED_OTHER, Param'Access);
652 pragma Assert (Result = 0);
654 if Dispatching_Policy = 'F' or else Priority_Specific_Policy = 'F' then
656 -- Annex D requirement [RM D.2.2 par. 9]:
657 -- If the task drops its priority due to the loss of inherited
658 -- priority, it is added at the head of the ready queue for its
659 -- new active priority.
661 if Loss_Of_Inheritance
662 and then Prio < T.Common.Current_Priority
664 Array_Item := Prio_Array (T.Common.Base_Priority) + 1;
665 Prio_Array (T.Common.Base_Priority) := Array_Item;
668 -- Let some processes a chance to arrive
672 -- Then wait for our turn to proceed
674 exit when Array_Item = Prio_Array (T.Common.Base_Priority)
675 or else Prio_Array (T.Common.Base_Priority) = 1;
678 Prio_Array (T.Common.Base_Priority) :=
679 Prio_Array (T.Common.Base_Priority) - 1;
683 T.Common.Current_Priority := Prio;
690 function Get_Priority (T : Task_Id) return System.Any_Priority is
692 return T.Common.Current_Priority;
699 procedure Enter_Task (Self_ID : Task_Id) is
701 Self_ID.Common.LL.Thread := pthread_self;
702 Specific.Set (Self_ID);
709 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
711 -----------------------------
712 -- Register_Foreign_Thread --
713 -----------------------------
715 function Register_Foreign_Thread return Task_Id is
717 if Is_Valid_Task then
720 return Register_Foreign_Thread (pthread_self);
722 end Register_Foreign_Thread;
728 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
729 Mutex_Attr : aliased pthread_mutexattr_t;
730 Result : Interfaces.C.int;
731 Cond_Attr : aliased pthread_condattr_t;
734 if not Single_Lock then
735 Result := pthread_mutexattr_init (Mutex_Attr'Access);
736 pragma Assert (Result = 0 or else Result = ENOMEM);
741 (Self_ID.Common.LL.L'Access, Mutex_Attr'Access);
742 pragma Assert (Result = 0 or else Result = ENOMEM);
750 Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
751 pragma Assert (Result = 0);
754 Result := pthread_condattr_init (Cond_Attr'Access);
755 pragma Assert (Result = 0 or else Result = ENOMEM);
760 (Self_ID.Common.LL.CV'Access,
762 pragma Assert (Result = 0 or else Result = ENOMEM);
768 if not Single_Lock then
769 Result := pthread_mutex_destroy (Self_ID.Common.LL.L'Access);
770 pragma Assert (Result = 0);
776 Result := pthread_condattr_destroy (Cond_Attr'Access);
777 pragma Assert (Result = 0);
784 procedure Create_Task
786 Wrapper : System.Address;
787 Stack_Size : System.Parameters.Size_Type;
788 Priority : System.Any_Priority;
789 Succeeded : out Boolean)
791 Attributes : aliased pthread_attr_t;
792 Result : Interfaces.C.int;
794 function Thread_Body_Access is new
795 Ada.Unchecked_Conversion (System.Address, Thread_Body);
798 Result := pthread_attr_init (Attributes'Access);
799 pragma Assert (Result = 0 or else Result = ENOMEM);
806 Result := pthread_attr_setstacksize
807 (Attributes'Access, Interfaces.C.size_t (Stack_Size));
808 pragma Assert (Result = 0);
810 -- Since the initial signal mask of a thread is inherited from the
811 -- creator, and the Environment task has all its signals masked, we
812 -- do not need to manipulate caller's signal mask at this point.
813 -- All tasks in RTS will have All_Tasks_Mask initially.
815 Result := pthread_create
816 (T.Common.LL.Thread'Access,
818 Thread_Body_Access (Wrapper),
820 pragma Assert (Result = 0 or else Result = EAGAIN);
822 Succeeded := Result = 0;
824 pthread_detach (T.Common.LL.Thread'Access);
825 -- Detach the thread using pthread_detach, since DCE threads do not have
826 -- pthread_attr_set_detachstate.
828 Result := pthread_attr_destroy (Attributes'Access);
829 pragma Assert (Result = 0);
831 Set_Priority (T, Priority);
838 procedure Finalize_TCB (T : Task_Id) is
839 Result : Interfaces.C.int;
842 if not Single_Lock then
843 Result := pthread_mutex_destroy (T.Common.LL.L'Access);
844 pragma Assert (Result = 0);
847 Result := pthread_cond_destroy (T.Common.LL.CV'Access);
848 pragma Assert (Result = 0);
850 if T.Known_Tasks_Index /= -1 then
851 Known_Tasks (T.Known_Tasks_Index) := null;
854 ATCB_Allocation.Free_ATCB (T);
861 procedure Exit_Task is
870 procedure Abort_Task (T : Task_Id) is
872 -- Interrupt Server_Tasks may be waiting on an "event" flag (signal)
874 if T.Common.State = Interrupt_Server_Blocked_On_Event_Flag then
875 System.Interrupt_Management.Operations.Interrupt_Self_Process
876 (PIO.Get_Interrupt_ID (T));
884 procedure Initialize (S : in out Suspension_Object) is
885 Mutex_Attr : aliased pthread_mutexattr_t;
886 Cond_Attr : aliased pthread_condattr_t;
887 Result : Interfaces.C.int;
889 -- Initialize internal state (always to False (ARM D.10(6)))
894 -- Initialize internal mutex
896 Result := pthread_mutex_init (S.L'Access, Mutex_Attr'Access);
897 pragma Assert (Result = 0 or else Result = ENOMEM);
899 if Result = ENOMEM then
903 -- Initialize internal condition variable
905 Result := pthread_cond_init (S.CV'Access, Cond_Attr'Access);
906 pragma Assert (Result = 0 or else Result = ENOMEM);
909 Result := pthread_mutex_destroy (S.L'Access);
910 pragma Assert (Result = 0);
912 if Result = ENOMEM then
922 procedure Finalize (S : in out Suspension_Object) is
923 Result : Interfaces.C.int;
926 -- Destroy internal mutex
928 Result := pthread_mutex_destroy (S.L'Access);
929 pragma Assert (Result = 0);
931 -- Destroy internal condition variable
933 Result := pthread_cond_destroy (S.CV'Access);
934 pragma Assert (Result = 0);
941 function Current_State (S : Suspension_Object) return Boolean is
943 -- We do not want to use lock on this read operation. State is marked
944 -- as Atomic so that we ensure that the value retrieved is correct.
953 procedure Set_False (S : in out Suspension_Object) is
954 Result : Interfaces.C.int;
959 Result := pthread_mutex_lock (S.L'Access);
960 pragma Assert (Result = 0);
964 Result := pthread_mutex_unlock (S.L'Access);
965 pragma Assert (Result = 0);
967 SSL.Abort_Undefer.all;
974 procedure Set_True (S : in out Suspension_Object) is
975 Result : Interfaces.C.int;
980 Result := pthread_mutex_lock (S.L'Access);
981 pragma Assert (Result = 0);
983 -- If there is already a task waiting on this suspension object then
984 -- we resume it, leaving the state of the suspension object to False,
985 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
986 -- the state to True.
992 Result := pthread_cond_signal (S.CV'Access);
993 pragma Assert (Result = 0);
999 Result := pthread_mutex_unlock (S.L'Access);
1000 pragma Assert (Result = 0);
1002 SSL.Abort_Undefer.all;
1005 ------------------------
1006 -- Suspend_Until_True --
1007 ------------------------
1009 procedure Suspend_Until_True (S : in out Suspension_Object) is
1010 Result : Interfaces.C.int;
1013 SSL.Abort_Defer.all;
1015 Result := pthread_mutex_lock (S.L'Access);
1016 pragma Assert (Result = 0);
1019 -- Program_Error must be raised upon calling Suspend_Until_True
1020 -- if another task is already waiting on that suspension object
1021 -- (ARM D.10 par. 10).
1023 Result := pthread_mutex_unlock (S.L'Access);
1024 pragma Assert (Result = 0);
1026 SSL.Abort_Undefer.all;
1028 raise Program_Error;
1030 -- Suspend the task if the state is False. Otherwise, the task
1031 -- continues its execution, and the state of the suspension object
1032 -- is set to False (ARM D.10 par. 9).
1040 -- Loop in case pthread_cond_wait returns earlier than expected
1041 -- (e.g. in case of EINTR caused by a signal).
1043 Result := pthread_cond_wait (S.CV'Access, S.L'Access);
1044 pragma Assert (Result = 0 or else Result = EINTR);
1046 exit when not S.Waiting;
1050 Result := pthread_mutex_unlock (S.L'Access);
1051 pragma Assert (Result = 0);
1053 SSL.Abort_Undefer.all;
1055 end Suspend_Until_True;
1063 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1064 pragma Unreferenced (Self_ID);
1069 --------------------
1070 -- Check_No_Locks --
1071 --------------------
1073 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1074 pragma Unreferenced (Self_ID);
1079 ----------------------
1080 -- Environment_Task --
1081 ----------------------
1083 function Environment_Task return Task_Id is
1085 return Environment_Task_Id;
1086 end Environment_Task;
1092 procedure Lock_RTS is
1094 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1101 procedure Unlock_RTS is
1103 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1110 function Suspend_Task
1112 Thread_Self : Thread_Id) return Boolean
1114 pragma Unreferenced (T);
1115 pragma Unreferenced (Thread_Self);
1124 function Resume_Task
1126 Thread_Self : Thread_Id) return Boolean
1128 pragma Unreferenced (T);
1129 pragma Unreferenced (Thread_Self);
1134 --------------------
1135 -- Stop_All_Tasks --
1136 --------------------
1138 procedure Stop_All_Tasks is
1147 function Stop_Task (T : ST.Task_Id) return Boolean is
1148 pragma Unreferenced (T);
1157 function Continue_Task (T : ST.Task_Id) return Boolean is
1158 pragma Unreferenced (T);
1167 procedure Initialize (Environment_Task : Task_Id) is
1168 act : aliased struct_sigaction;
1169 old_act : aliased struct_sigaction;
1170 Tmp_Set : aliased sigset_t;
1171 Result : Interfaces.C.int;
1174 (Int : System.Interrupt_Management.Interrupt_ID) return Character;
1175 pragma Import (C, State, "__gnat_get_interrupt_state");
1176 -- Get interrupt state. Defined in a-init.c. The input argument is
1177 -- the interrupt number, and the result is one of the following:
1179 Default : constant Character := 's';
1180 -- 'n' this interrupt not set by any Interrupt_State pragma
1181 -- 'u' Interrupt_State pragma set state to User
1182 -- 'r' Interrupt_State pragma set state to Runtime
1183 -- 's' Interrupt_State pragma set state to System (use "default"
1187 Environment_Task_Id := Environment_Task;
1189 Interrupt_Management.Initialize;
1191 -- Initialize the lock used to synchronize chain of all ATCBs
1193 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1195 Specific.Initialize (Environment_Task);
1197 -- Make environment task known here because it doesn't go through
1198 -- Activate_Tasks, which does it for all other tasks.
1200 Known_Tasks (Known_Tasks'First) := Environment_Task;
1201 Environment_Task.Known_Tasks_Index := Known_Tasks'First;
1203 Enter_Task (Environment_Task);
1205 -- Install the abort-signal handler
1207 if State (System.Interrupt_Management.Abort_Task_Interrupt)
1211 act.sa_handler := Abort_Handler'Address;
1213 Result := sigemptyset (Tmp_Set'Access);
1214 pragma Assert (Result = 0);
1215 act.sa_mask := Tmp_Set;
1219 Signal (System.Interrupt_Management.Abort_Task_Interrupt),
1220 act'Unchecked_Access,
1221 old_act'Unchecked_Access);
1222 pragma Assert (Result = 0);
1226 -- NOTE: Unlike other pthread implementations, we do *not* mask all
1227 -- signals here since we handle signals using the process-wide primitive
1228 -- signal, rather than using sigthreadmask and sigwait. The reason of
1229 -- this difference is that sigwait doesn't work when some critical
1230 -- signals (SIGABRT, SIGPIPE) are masked.
1232 -----------------------
1233 -- Set_Task_Affinity --
1234 -----------------------
1236 procedure Set_Task_Affinity (T : ST.Task_Id) is
1237 pragma Unreferenced (T);
1240 -- Setting task affinity is not supported by the underlying system
1243 end Set_Task_Affinity;
1245 end System.Task_Primitives.Operations;