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-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, 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
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
46 with System.Interrupt_Management;
47 -- used for Keep_Unmasked
48 -- Abort_Task_Interrupt
51 pragma Warnings (Off);
52 with System.Interrupt_Management.Operations;
53 -- used for Set_Interrupt_Mask
55 pragma Elaborate_All (System.Interrupt_Management.Operations);
59 with System.OS_Primitives;
60 -- used for Delay_Modes
66 with System.Parameters;
69 with System.Task_Primitives.Interrupt_Operations;
70 -- used for Get_Interrupt_ID
72 with Unchecked_Conversion;
73 with Unchecked_Deallocation;
75 package body System.Task_Primitives.Operations is
77 use System.Tasking.Debug;
80 use System.OS_Interface;
81 use System.Parameters;
82 use System.OS_Primitives;
84 package PIO renames System.Task_Primitives.Interrupt_Operations;
90 -- The followings are logically constants, but need to be initialized
93 Single_RTS_Lock : aliased RTS_Lock;
94 -- This is a lock to allow only one thread of control in the RTS at
95 -- a time; it is used to execute in mutual exclusion from all other tasks.
96 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
98 ATCB_Key : aliased pthread_key_t;
99 -- Key used to find the Ada Task_Id associated with a thread
101 Environment_Task_Id : Task_Id;
102 -- A variable to hold Task_Id for the environment task
104 Unblocked_Signal_Mask : aliased sigset_t;
105 -- The set of signals that should unblocked in all tasks
107 Time_Slice_Val : Integer;
108 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
110 Dispatching_Policy : Character;
111 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
113 -- Note: the reason that Locking_Policy is not needed is that this
114 -- is not implemented for DCE threads. The HPUX 10 port is at this
115 -- stage considered dead, and no further work is planned on it.
117 Foreign_Task_Elaborated : aliased Boolean := True;
118 -- Used to identified fake tasks (i.e., non-Ada Threads)
126 procedure Initialize (Environment_Task : Task_Id);
127 pragma Inline (Initialize);
128 -- Initialize various data needed by this package
130 function Is_Valid_Task return Boolean;
131 pragma Inline (Is_Valid_Task);
132 -- Does the executing thread have a TCB?
134 procedure Set (Self_Id : Task_Id);
136 -- Set the self id for the current task
138 function Self return Task_Id;
139 pragma Inline (Self);
140 -- Return a pointer to the Ada Task Control Block of the calling task
144 package body Specific is separate;
145 -- The body of this package is target specific
147 ---------------------------------
148 -- Support for foreign threads --
149 ---------------------------------
151 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
152 -- Allocate and Initialize a new ATCB for the current Thread
154 function Register_Foreign_Thread
155 (Thread : Thread_Id) return Task_Id is separate;
157 -----------------------
158 -- Local Subprograms --
159 -----------------------
161 procedure Abort_Handler (Sig : Signal);
163 function To_Address is new Unchecked_Conversion (Task_Id, System.Address);
169 procedure Abort_Handler (Sig : Signal) is
170 pragma Unreferenced (Sig);
172 Self_Id : constant Task_Id := Self;
173 Result : Interfaces.C.int;
174 Old_Set : aliased sigset_t;
177 if Self_Id.Deferral_Level = 0
178 and then Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level and then
181 Self_Id.Aborting := True;
183 -- Make sure signals used for RTS internal purpose are unmasked
185 Result := pthread_sigmask (SIG_UNBLOCK,
186 Unblocked_Signal_Mask'Unchecked_Access, Old_Set'Unchecked_Access);
187 pragma Assert (Result = 0);
189 raise Standard'Abort_Signal;
197 -- The underlying thread system sets a guard page at the
198 -- bottom of a thread stack, so nothing is needed.
199 -- ??? Check the comment above
201 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
202 pragma Unreferenced (T, On);
211 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
213 return T.Common.LL.Thread;
220 function Self return Task_Id renames Specific.Self;
222 ---------------------
223 -- Initialize_Lock --
224 ---------------------
226 -- Note: mutexes and cond_variables needed per-task basis are
227 -- initialized in Initialize_TCB and the Storage_Error is
228 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
229 -- used in RTS is initialized before any status change of RTS.
230 -- Therefore rasing Storage_Error in the following routines
231 -- should be able to be handled safely.
233 procedure Initialize_Lock
234 (Prio : System.Any_Priority;
237 Attributes : aliased pthread_mutexattr_t;
238 Result : Interfaces.C.int;
241 Result := pthread_mutexattr_init (Attributes'Access);
242 pragma Assert (Result = 0 or else Result = ENOMEM);
244 if Result = ENOMEM then
250 Result := pthread_mutex_init (L.L'Access, Attributes'Access);
251 pragma Assert (Result = 0 or else Result = ENOMEM);
253 if Result = ENOMEM then
257 Result := pthread_mutexattr_destroy (Attributes'Access);
258 pragma Assert (Result = 0);
261 procedure Initialize_Lock (L : access RTS_Lock; Level : Lock_Level) is
262 pragma Unreferenced (Level);
264 Attributes : aliased pthread_mutexattr_t;
265 Result : Interfaces.C.int;
268 Result := pthread_mutexattr_init (Attributes'Access);
269 pragma Assert (Result = 0 or else Result = ENOMEM);
271 if Result = ENOMEM then
275 Result := pthread_mutex_init (L, Attributes'Access);
277 pragma Assert (Result = 0 or else Result = ENOMEM);
279 if Result = ENOMEM then
283 Result := pthread_mutexattr_destroy (Attributes'Access);
284 pragma Assert (Result = 0);
291 procedure Finalize_Lock (L : access Lock) is
292 Result : Interfaces.C.int;
294 Result := pthread_mutex_destroy (L.L'Access);
295 pragma Assert (Result = 0);
298 procedure Finalize_Lock (L : access RTS_Lock) is
299 Result : Interfaces.C.int;
301 Result := pthread_mutex_destroy (L);
302 pragma Assert (Result = 0);
309 procedure Write_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
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 : access RTS_Lock; Global_Lock : Boolean := False)
328 Result : Interfaces.C.int;
330 if not Single_Lock or else Global_Lock then
331 Result := pthread_mutex_lock (L);
332 pragma Assert (Result = 0);
336 procedure Write_Lock (T : Task_Id) is
337 Result : Interfaces.C.int;
339 if not Single_Lock then
340 Result := pthread_mutex_lock (T.Common.LL.L'Access);
341 pragma Assert (Result = 0);
349 procedure Read_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
351 Write_Lock (L, Ceiling_Violation);
358 procedure Unlock (L : access Lock) is
359 Result : Interfaces.C.int;
361 Result := pthread_mutex_unlock (L.L'Access);
362 pragma Assert (Result = 0);
365 procedure Unlock (L : access RTS_Lock; Global_Lock : Boolean := False) is
366 Result : Interfaces.C.int;
368 if not Single_Lock or else Global_Lock then
369 Result := pthread_mutex_unlock (L);
370 pragma Assert (Result = 0);
374 procedure Unlock (T : Task_Id) is
375 Result : Interfaces.C.int;
377 if not Single_Lock then
378 Result := pthread_mutex_unlock (T.Common.LL.L'Access);
379 pragma Assert (Result = 0);
389 Reason : System.Tasking.Task_States)
391 pragma Unreferenced (Reason);
393 Result : Interfaces.C.int;
396 Result := pthread_cond_wait
397 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
399 Result := pthread_cond_wait
400 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
403 -- EINTR is not considered a failure
405 pragma Assert (Result = 0 or else Result = EINTR);
412 procedure Timed_Sleep
415 Mode : ST.Delay_Modes;
416 Reason : System.Tasking.Task_States;
417 Timedout : out Boolean;
418 Yielded : out Boolean)
420 pragma Unreferenced (Reason);
422 Check_Time : constant Duration := Monotonic_Clock;
424 Request : aliased timespec;
425 Result : Interfaces.C.int;
431 if Mode = Relative then
432 Abs_Time := Duration'Min (Time, Max_Sensible_Delay) + Check_Time;
434 Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time);
437 if Abs_Time > Check_Time then
438 Request := To_Timespec (Abs_Time);
441 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
442 or else Self_ID.Pending_Priority_Change;
445 Result := pthread_cond_timedwait
446 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access,
450 Result := pthread_cond_timedwait
451 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access,
455 exit when Abs_Time <= Monotonic_Clock;
457 if Result = 0 or Result = EINTR then
459 -- Somebody may have called Wakeup for us
465 pragma Assert (Result = ETIMEDOUT);
474 procedure Timed_Delay
477 Mode : ST.Delay_Modes)
479 Check_Time : constant Duration := Monotonic_Clock;
481 Request : aliased timespec;
482 Result : Interfaces.C.int;
489 Write_Lock (Self_ID);
491 if Mode = Relative then
492 Abs_Time := Time + Check_Time;
494 Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time);
497 if Abs_Time > Check_Time then
498 Request := To_Timespec (Abs_Time);
499 Self_ID.Common.State := Delay_Sleep;
502 if Self_ID.Pending_Priority_Change then
503 Self_ID.Pending_Priority_Change := False;
504 Self_ID.Common.Base_Priority := Self_ID.New_Base_Priority;
505 Set_Priority (Self_ID, Self_ID.Common.Base_Priority);
508 exit when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
511 Result := pthread_cond_timedwait (Self_ID.Common.LL.CV'Access,
512 Single_RTS_Lock'Access, Request'Access);
514 Result := pthread_cond_timedwait (Self_ID.Common.LL.CV'Access,
515 Self_ID.Common.LL.L'Access, Request'Access);
518 exit when Abs_Time <= Monotonic_Clock;
520 pragma Assert (Result = 0 or else
521 Result = ETIMEDOUT or else
525 Self_ID.Common.State := Runnable;
534 Result := sched_yield;
537 ---------------------
538 -- Monotonic_Clock --
539 ---------------------
541 function Monotonic_Clock return Duration is
542 TS : aliased timespec;
543 Result : Interfaces.C.int;
545 Result := Clock_Gettime (CLOCK_REALTIME, TS'Unchecked_Access);
546 pragma Assert (Result = 0);
547 return To_Duration (TS);
554 function RT_Resolution return Duration is
563 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
564 pragma Unreferenced (Reason);
566 Result : Interfaces.C.int;
569 Result := pthread_cond_signal (T.Common.LL.CV'Access);
570 pragma Assert (Result = 0);
577 procedure Yield (Do_Yield : Boolean := True) is
578 Result : Interfaces.C.int;
579 pragma Unreferenced (Result);
582 Result := sched_yield;
590 type Prio_Array_Type is array (System.Any_Priority) of Integer;
591 pragma Atomic_Components (Prio_Array_Type);
593 Prio_Array : Prio_Array_Type;
594 -- Global array containing the id of the currently running task for
597 -- Note: we assume that we are on a single processor with run-til-blocked
600 procedure Set_Priority
602 Prio : System.Any_Priority;
603 Loss_Of_Inheritance : Boolean := False)
605 Result : Interfaces.C.int;
606 Array_Item : Integer;
607 Param : aliased struct_sched_param;
610 Param.sched_priority := Interfaces.C.int (Underlying_Priorities (Prio));
612 if Time_Slice_Val > 0 then
613 Result := pthread_setschedparam
614 (T.Common.LL.Thread, SCHED_RR, Param'Access);
616 elsif Dispatching_Policy = 'F' or else Time_Slice_Val = 0 then
617 Result := pthread_setschedparam
618 (T.Common.LL.Thread, SCHED_FIFO, Param'Access);
621 Result := pthread_setschedparam
622 (T.Common.LL.Thread, SCHED_OTHER, Param'Access);
625 pragma Assert (Result = 0);
627 if Dispatching_Policy = 'F' then
629 -- Annex D requirement [RM D.2.2 par. 9]:
630 -- If the task drops its priority due to the loss of inherited
631 -- priority, it is added at the head of the ready queue for its
632 -- new active priority.
634 if Loss_Of_Inheritance
635 and then Prio < T.Common.Current_Priority
637 Array_Item := Prio_Array (T.Common.Base_Priority) + 1;
638 Prio_Array (T.Common.Base_Priority) := Array_Item;
641 -- Let some processes a chance to arrive
645 -- Then wait for our turn to proceed
647 exit when Array_Item = Prio_Array (T.Common.Base_Priority)
648 or else Prio_Array (T.Common.Base_Priority) = 1;
651 Prio_Array (T.Common.Base_Priority) :=
652 Prio_Array (T.Common.Base_Priority) - 1;
656 T.Common.Current_Priority := Prio;
663 function Get_Priority (T : Task_Id) return System.Any_Priority is
665 return T.Common.Current_Priority;
672 procedure Enter_Task (Self_ID : Task_Id) is
674 Self_ID.Common.LL.Thread := pthread_self;
675 Specific.Set (Self_ID);
679 for J in Known_Tasks'Range loop
680 if Known_Tasks (J) = null then
681 Known_Tasks (J) := Self_ID;
682 Self_ID.Known_Tasks_Index := J;
694 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
696 return new Ada_Task_Control_Block (Entry_Num);
703 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
705 -----------------------------
706 -- Register_Foreign_Thread --
707 -----------------------------
709 function Register_Foreign_Thread return Task_Id is
711 if Is_Valid_Task then
714 return Register_Foreign_Thread (pthread_self);
716 end Register_Foreign_Thread;
722 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
723 Mutex_Attr : aliased pthread_mutexattr_t;
724 Result : Interfaces.C.int;
725 Cond_Attr : aliased pthread_condattr_t;
728 if not Single_Lock then
729 Result := pthread_mutexattr_init (Mutex_Attr'Access);
730 pragma Assert (Result = 0 or else Result = ENOMEM);
733 Result := pthread_mutex_init (Self_ID.Common.LL.L'Access,
735 pragma Assert (Result = 0 or else Result = ENOMEM);
743 Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
744 pragma Assert (Result = 0);
747 Result := pthread_condattr_init (Cond_Attr'Access);
748 pragma Assert (Result = 0 or else Result = ENOMEM);
751 Result := pthread_cond_init (Self_ID.Common.LL.CV'Access,
753 pragma Assert (Result = 0 or else Result = ENOMEM);
759 if not Single_Lock then
760 Result := pthread_mutex_destroy (Self_ID.Common.LL.L'Access);
761 pragma Assert (Result = 0);
767 Result := pthread_condattr_destroy (Cond_Attr'Access);
768 pragma Assert (Result = 0);
775 procedure Create_Task
777 Wrapper : System.Address;
778 Stack_Size : System.Parameters.Size_Type;
779 Priority : System.Any_Priority;
780 Succeeded : out Boolean)
782 Attributes : aliased pthread_attr_t;
783 Adjusted_Stack_Size : Interfaces.C.size_t;
784 Result : Interfaces.C.int;
786 function Thread_Body_Access is new
787 Unchecked_Conversion (System.Address, Thread_Body);
790 if Stack_Size = Unspecified_Size then
791 Adjusted_Stack_Size := Interfaces.C.size_t (Default_Stack_Size);
793 elsif Stack_Size < Minimum_Stack_Size then
794 Adjusted_Stack_Size := Interfaces.C.size_t (Minimum_Stack_Size);
797 Adjusted_Stack_Size := Interfaces.C.size_t (Stack_Size);
800 Result := pthread_attr_init (Attributes'Access);
801 pragma Assert (Result = 0 or else Result = ENOMEM);
808 Result := pthread_attr_setstacksize
809 (Attributes'Access, Adjusted_Stack_Size);
810 pragma Assert (Result = 0);
812 -- Since the initial signal mask of a thread is inherited from the
813 -- creator, and the Environment task has all its signals masked, we
814 -- do not need to manipulate caller's signal mask at this point.
815 -- All tasks in RTS will have All_Tasks_Mask initially.
817 Result := pthread_create
818 (T.Common.LL.Thread'Access,
820 Thread_Body_Access (Wrapper),
822 pragma Assert (Result = 0 or else Result = EAGAIN);
824 Succeeded := Result = 0;
826 pthread_detach (T.Common.LL.Thread'Access);
827 -- Detach the thread using pthread_detach, sinc DCE threads do not have
828 -- pthread_attr_set_detachstate.
830 Result := pthread_attr_destroy (Attributes'Access);
831 pragma Assert (Result = 0);
833 Set_Priority (T, Priority);
840 procedure Finalize_TCB (T : Task_Id) is
841 Result : Interfaces.C.int;
843 Is_Self : constant Boolean := T = Self;
845 procedure Free is new
846 Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
849 if not Single_Lock then
850 Result := pthread_mutex_destroy (T.Common.LL.L'Access);
851 pragma Assert (Result = 0);
854 Result := pthread_cond_destroy (T.Common.LL.CV'Access);
855 pragma Assert (Result = 0);
857 if T.Known_Tasks_Index /= -1 then
858 Known_Tasks (T.Known_Tasks_Index) := null;
872 procedure Exit_Task is
881 procedure Abort_Task (T : Task_Id) is
884 -- Interrupt Server_Tasks may be waiting on an "event" flag (signal)
886 if T.Common.State = Interrupt_Server_Blocked_On_Event_Flag then
887 System.Interrupt_Management.Operations.Interrupt_Self_Process
888 (System.Interrupt_Management.Interrupt_ID
889 (PIO.Get_Interrupt_ID (T)));
897 procedure Initialize (S : in out Suspension_Object) is
898 Mutex_Attr : aliased pthread_mutexattr_t;
899 Cond_Attr : aliased pthread_condattr_t;
900 Result : Interfaces.C.int;
902 -- Initialize internal state. It is always initialized to False (ARM
908 -- Initialize internal mutex
910 Result := pthread_mutex_init (S.L'Access, Mutex_Attr'Access);
911 pragma Assert (Result = 0 or else Result = ENOMEM);
913 if Result = ENOMEM then
917 -- Initialize internal condition variable
919 Result := pthread_cond_init (S.CV'Access, Cond_Attr'Access);
920 pragma Assert (Result = 0 or else Result = ENOMEM);
923 Result := pthread_mutex_destroy (S.L'Access);
924 pragma Assert (Result = 0);
926 if Result = ENOMEM then
936 procedure Finalize (S : in out Suspension_Object) is
937 Result : Interfaces.C.int;
939 -- Destroy internal mutex
941 Result := pthread_mutex_destroy (S.L'Access);
942 pragma Assert (Result = 0);
944 -- Destroy internal condition variable
946 Result := pthread_cond_destroy (S.CV'Access);
947 pragma Assert (Result = 0);
954 function Current_State (S : Suspension_Object) return Boolean is
956 -- We do not want to use lock on this read operation. State is marked
957 -- as Atomic so that we ensure that the value retrieved is correct.
966 procedure Set_False (S : in out Suspension_Object) is
967 Result : Interfaces.C.int;
969 Result := pthread_mutex_lock (S.L'Access);
970 pragma Assert (Result = 0);
974 Result := pthread_mutex_unlock (S.L'Access);
975 pragma Assert (Result = 0);
982 procedure Set_True (S : in out Suspension_Object) is
983 Result : Interfaces.C.int;
985 Result := pthread_mutex_lock (S.L'Access);
986 pragma Assert (Result = 0);
988 -- If there is already a task waiting on this suspension object then
989 -- we resume it, leaving the state of the suspension object to False,
990 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
991 -- the state to True.
997 Result := pthread_cond_signal (S.CV'Access);
998 pragma Assert (Result = 0);
1003 Result := pthread_mutex_unlock (S.L'Access);
1004 pragma Assert (Result = 0);
1007 ------------------------
1008 -- Suspend_Until_True --
1009 ------------------------
1011 procedure Suspend_Until_True (S : in out Suspension_Object) is
1012 Result : Interfaces.C.int;
1014 Result := pthread_mutex_lock (S.L'Access);
1015 pragma Assert (Result = 0);
1018 -- Program_Error must be raised upon calling Suspend_Until_True
1019 -- if another task is already waiting on that suspension object
1020 -- (ARM D.10 par. 10).
1022 Result := pthread_mutex_unlock (S.L'Access);
1023 pragma Assert (Result = 0);
1025 raise Program_Error;
1027 -- Suspend the task if the state is False. Otherwise, the task
1028 -- continues its execution, and the state of the suspension object
1029 -- is set to False (ARM D.10 par. 9).
1035 Result := pthread_cond_wait (S.CV'Access, S.L'Access);
1039 Result := pthread_mutex_unlock (S.L'Access);
1040 pragma Assert (Result = 0);
1041 end Suspend_Until_True;
1049 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1050 pragma Unreferenced (Self_ID);
1055 --------------------
1056 -- Check_No_Locks --
1057 --------------------
1059 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1060 pragma Unreferenced (Self_ID);
1065 ----------------------
1066 -- Environment_Task --
1067 ----------------------
1069 function Environment_Task return Task_Id is
1071 return Environment_Task_Id;
1072 end Environment_Task;
1078 procedure Lock_RTS is
1080 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1087 procedure Unlock_RTS is
1089 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1096 function Suspend_Task
1098 Thread_Self : Thread_Id) return Boolean
1100 pragma Unreferenced (T);
1101 pragma Unreferenced (Thread_Self);
1110 function Resume_Task
1112 Thread_Self : Thread_Id) return Boolean
1114 pragma Unreferenced (T);
1115 pragma Unreferenced (Thread_Self);
1124 procedure Initialize (Environment_Task : Task_Id) is
1125 act : aliased struct_sigaction;
1126 old_act : aliased struct_sigaction;
1127 Tmp_Set : aliased sigset_t;
1128 Result : Interfaces.C.int;
1131 (Int : System.Interrupt_Management.Interrupt_ID) return Character;
1132 pragma Import (C, State, "__gnat_get_interrupt_state");
1133 -- Get interrupt state. Defined in a-init.c. The input argument is
1134 -- the interrupt number, and the result is one of the following:
1136 Default : constant Character := 's';
1137 -- 'n' this interrupt not set by any Interrupt_State pragma
1138 -- 'u' Interrupt_State pragma set state to User
1139 -- 'r' Interrupt_State pragma set state to Runtime
1140 -- 's' Interrupt_State pragma set state to System (use "default"
1144 Environment_Task_Id := Environment_Task;
1146 Interrupt_Management.Initialize;
1148 -- Initialize the lock used to synchronize chain of all ATCBs
1150 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1152 Specific.Initialize (Environment_Task);
1154 Enter_Task (Environment_Task);
1156 -- Install the abort-signal handler
1158 if State (System.Interrupt_Management.Abort_Task_Interrupt)
1162 act.sa_handler := Abort_Handler'Address;
1164 Result := sigemptyset (Tmp_Set'Access);
1165 pragma Assert (Result = 0);
1166 act.sa_mask := Tmp_Set;
1170 Signal (System.Interrupt_Management.Abort_Task_Interrupt),
1171 act'Unchecked_Access,
1172 old_act'Unchecked_Access);
1173 pragma Assert (Result = 0);
1177 -- NOTE: Unlike other pthread implementations, we do *not* mask all
1178 -- signals here since we handle signals using the process-wide primitive
1179 -- signal, rather than using sigthreadmask and sigwait. The reason of
1180 -- this difference is that sigwait doesn't work when some critical
1181 -- signals (SIGABRT, SIGPIPE) are masked.
1183 end System.Task_Primitives.Operations;