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-2006, 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 the VxWorks 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
50 -- Initialize_Interrupts
54 with Unchecked_Conversion;
55 with Unchecked_Deallocation;
57 package body System.Task_Primitives.Operations is
59 use System.Tasking.Debug;
61 use System.OS_Interface;
62 use System.Parameters;
63 use type Interfaces.C.int;
65 subtype int is System.OS_Interface.int;
67 Relative : constant := 0;
73 -- The followings are logically constants, but need to be initialized at
76 Single_RTS_Lock : aliased RTS_Lock;
77 -- This is a lock to allow only one thread of control in the RTS at a
78 -- time; it is used to execute in mutual exclusion from all other tasks.
79 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
81 Environment_Task_Id : Task_Id;
82 -- A variable to hold Task_Id for the environment task
84 Unblocked_Signal_Mask : aliased sigset_t;
85 -- The set of signals that should unblocked in all tasks
87 -- The followings are internal configuration constants needed
89 Time_Slice_Val : Integer;
90 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
92 Locking_Policy : Character;
93 pragma Import (C, Locking_Policy, "__gl_locking_policy");
95 Dispatching_Policy : Character;
96 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
98 Mutex_Protocol : Priority_Type;
100 Foreign_Task_Elaborated : aliased Boolean := True;
101 -- Used to identified fake tasks (i.e., non-Ada Threads)
109 procedure Initialize;
110 pragma Inline (Initialize);
111 -- Initialize task specific data
113 function Is_Valid_Task return Boolean;
114 pragma Inline (Is_Valid_Task);
115 -- Does executing thread have a TCB?
117 procedure Set (Self_Id : Task_Id);
119 -- Set the self id for the current task
122 pragma Inline (Delete);
123 -- Delete the task specific data associated with the current task
125 function Self return Task_Id;
126 pragma Inline (Self);
127 -- Return a pointer to the Ada Task Control Block of the calling task
131 package body Specific is separate;
132 -- The body of this package is target specific
134 ---------------------------------
135 -- Support for foreign threads --
136 ---------------------------------
138 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
139 -- Allocate and Initialize a new ATCB for the current Thread
141 function Register_Foreign_Thread
142 (Thread : Thread_Id) return Task_Id is separate;
144 -----------------------
145 -- Local Subprograms --
146 -----------------------
148 procedure Abort_Handler (signo : Signal);
149 -- Handler for the abort (SIGABRT) signal to handle asynchronous abort
151 procedure Install_Signal_Handlers;
152 -- Install the default signal handlers for the current task
154 function To_Address is new Unchecked_Conversion (Task_Id, System.Address);
160 procedure Abort_Handler (signo : Signal) is
161 pragma Unreferenced (signo);
163 Self_ID : constant Task_Id := Self;
165 Old_Set : aliased sigset_t;
168 -- It is not safe to raise an exception when using ZCX and the GCC
169 -- exception handling mechanism.
171 if ZCX_By_Default and then GCC_ZCX_Support then
175 if Self_ID.Deferral_Level = 0
176 and then Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
177 and then not Self_ID.Aborting
179 Self_ID.Aborting := True;
181 -- Make sure signals used for RTS internal purpose are unmasked
183 Result := pthread_sigmask (SIG_UNBLOCK,
184 Unblocked_Signal_Mask'Unchecked_Access, Old_Set'Unchecked_Access);
185 pragma Assert (Result = 0);
187 raise Standard'Abort_Signal;
195 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
196 pragma Unreferenced (T);
197 pragma Unreferenced (On);
200 -- Nothing needed (why not???)
209 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
211 return T.Common.LL.Thread;
218 function Self return Task_Id renames Specific.Self;
220 -----------------------------
221 -- Install_Signal_Handlers --
222 -----------------------------
224 procedure Install_Signal_Handlers is
225 act : aliased struct_sigaction;
226 old_act : aliased struct_sigaction;
227 Tmp_Set : aliased sigset_t;
232 act.sa_handler := Abort_Handler'Address;
234 Result := sigemptyset (Tmp_Set'Access);
235 pragma Assert (Result = 0);
236 act.sa_mask := Tmp_Set;
240 (Signal (Interrupt_Management.Abort_Task_Signal),
241 act'Unchecked_Access,
242 old_act'Unchecked_Access);
243 pragma Assert (Result = 0);
245 Interrupt_Management.Initialize_Interrupts;
246 end Install_Signal_Handlers;
248 ---------------------
249 -- Initialize_Lock --
250 ---------------------
252 procedure Initialize_Lock (Prio : System.Any_Priority; L : access Lock) is
254 L.Mutex := semMCreate (SEM_Q_PRIORITY + SEM_INVERSION_SAFE);
255 L.Prio_Ceiling := int (Prio);
256 L.Protocol := Mutex_Protocol;
257 pragma Assert (L.Mutex /= 0);
260 procedure Initialize_Lock (L : access RTS_Lock; Level : Lock_Level) is
261 pragma Unreferenced (Level);
264 L.Mutex := semMCreate (SEM_Q_PRIORITY + SEM_INVERSION_SAFE);
265 L.Prio_Ceiling := int (System.Any_Priority'Last);
266 L.Protocol := Mutex_Protocol;
267 pragma Assert (L.Mutex /= 0);
274 procedure Finalize_Lock (L : access Lock) is
277 Result := semDelete (L.Mutex);
278 pragma Assert (Result = 0);
281 procedure Finalize_Lock (L : access RTS_Lock) is
284 Result := semDelete (L.Mutex);
285 pragma Assert (Result = 0);
292 procedure Write_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
295 if L.Protocol = Prio_Protect
296 and then int (Self.Common.Current_Priority) > L.Prio_Ceiling
298 Ceiling_Violation := True;
301 Ceiling_Violation := False;
304 Result := semTake (L.Mutex, WAIT_FOREVER);
305 pragma Assert (Result = 0);
309 (L : access RTS_Lock;
310 Global_Lock : Boolean := False)
314 if not Single_Lock or else Global_Lock then
315 Result := semTake (L.Mutex, WAIT_FOREVER);
316 pragma Assert (Result = 0);
320 procedure Write_Lock (T : Task_Id) is
323 if not Single_Lock then
324 Result := semTake (T.Common.LL.L.Mutex, WAIT_FOREVER);
325 pragma Assert (Result = 0);
333 procedure Read_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
335 Write_Lock (L, Ceiling_Violation);
342 procedure Unlock (L : access Lock) is
345 Result := semGive (L.Mutex);
346 pragma Assert (Result = 0);
349 procedure Unlock (L : access RTS_Lock; Global_Lock : Boolean := False) is
352 if not Single_Lock or else Global_Lock then
353 Result := semGive (L.Mutex);
354 pragma Assert (Result = 0);
358 procedure Unlock (T : Task_Id) is
361 if not Single_Lock then
362 Result := semGive (T.Common.LL.L.Mutex);
363 pragma Assert (Result = 0);
371 procedure Sleep (Self_ID : Task_Id; Reason : System.Tasking.Task_States) is
372 pragma Unreferenced (Reason);
377 pragma Assert (Self_ID = Self);
379 -- Release the mutex before sleeping
382 Result := semGive (Single_RTS_Lock.Mutex);
384 Result := semGive (Self_ID.Common.LL.L.Mutex);
387 pragma Assert (Result = 0);
389 -- Perform a blocking operation to take the CV semaphore. Note that a
390 -- blocking operation in VxWorks will reenable task scheduling. When we
391 -- are no longer blocked and control is returned, task scheduling will
392 -- again be disabled.
394 Result := semTake (Self_ID.Common.LL.CV, WAIT_FOREVER);
395 pragma Assert (Result = 0);
397 -- Take the mutex back
400 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
402 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
405 pragma Assert (Result = 0);
412 -- This is for use within the run-time system, so abort is assumed to be
413 -- already deferred, and the caller should be holding its own ATCB lock.
415 procedure Timed_Sleep
418 Mode : ST.Delay_Modes;
419 Reason : System.Tasking.Task_States;
420 Timedout : out Boolean;
421 Yielded : out Boolean)
423 pragma Unreferenced (Reason);
425 Orig : constant Duration := Monotonic_Clock;
429 Wakeup : Boolean := False;
435 if Mode = Relative then
436 Absolute := Orig + Time;
438 -- Systematically add one since the first tick will delay *at most*
439 -- 1 / Rate_Duration seconds, so we need to add one to be on the
442 Ticks := To_Clock_Ticks (Time);
444 if Ticks > 0 and then Ticks < int'Last then
450 Ticks := To_Clock_Ticks (Time - Monotonic_Clock);
455 -- Release the mutex before sleeping
458 Result := semGive (Single_RTS_Lock.Mutex);
460 Result := semGive (Self_ID.Common.LL.L.Mutex);
463 pragma Assert (Result = 0);
465 -- Perform a blocking operation to take the CV semaphore. Note
466 -- that a blocking operation in VxWorks will reenable task
467 -- scheduling. When we are no longer blocked and control is
468 -- returned, task scheduling will again be disabled.
470 Result := semTake (Self_ID.Common.LL.CV, Ticks);
474 -- Somebody may have called Wakeup for us
479 if errno /= S_objLib_OBJ_TIMEOUT then
483 -- If Ticks = int'last, it was most probably truncated so
484 -- let's make another round after recomputing Ticks from
485 -- the the absolute time.
487 if Ticks /= int'Last then
490 Ticks := To_Clock_Ticks (Absolute - Monotonic_Clock);
499 -- Take the mutex back
502 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
504 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
507 pragma Assert (Result = 0);
509 exit when Timedout or Wakeup;
515 -- Should never hold a lock while yielding
518 Result := semGive (Single_RTS_Lock.Mutex);
520 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
523 Result := semGive (Self_ID.Common.LL.L.Mutex);
525 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
534 -- This is for use in implementing delay statements, so we assume the
535 -- caller is holding no locks.
537 procedure Timed_Delay
540 Mode : ST.Delay_Modes)
542 Orig : constant Duration := Monotonic_Clock;
547 Aborted : Boolean := False;
550 if Mode = Relative then
551 Absolute := Orig + Time;
552 Ticks := To_Clock_Ticks (Time);
554 if Ticks > 0 and then Ticks < int'Last then
556 -- First tick will delay anytime between 0 and 1 / sysClkRateGet
557 -- seconds, so we need to add one to be on the safe side.
564 Ticks := To_Clock_Ticks (Time - Orig);
569 -- Modifying State and Pending_Priority_Change, locking the TCB
572 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
574 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
577 pragma Assert (Result = 0);
579 Self_ID.Common.State := Delay_Sleep;
583 if Self_ID.Pending_Priority_Change then
584 Self_ID.Pending_Priority_Change := False;
585 Self_ID.Common.Base_Priority := Self_ID.New_Base_Priority;
586 Set_Priority (Self_ID, Self_ID.Common.Base_Priority);
589 Aborted := Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
591 -- Release the TCB before sleeping
594 Result := semGive (Single_RTS_Lock.Mutex);
596 Result := semGive (Self_ID.Common.LL.L.Mutex);
598 pragma Assert (Result = 0);
602 Result := semTake (Self_ID.Common.LL.CV, Ticks);
606 -- If Ticks = int'last, it was most probably truncated
607 -- so let's make another round after recomputing Ticks
608 -- from the the absolute time.
610 if errno = S_objLib_OBJ_TIMEOUT and then Ticks /= int'Last then
613 Ticks := To_Clock_Ticks (Absolute - Monotonic_Clock);
621 -- Take back the lock after having slept, to protect further
622 -- access to Self_ID.
625 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
627 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
630 pragma Assert (Result = 0);
635 Self_ID.Common.State := Runnable;
638 Result := semGive (Single_RTS_Lock.Mutex);
640 Result := semGive (Self_ID.Common.LL.L.Mutex);
648 ---------------------
649 -- Monotonic_Clock --
650 ---------------------
652 function Monotonic_Clock return Duration is
653 TS : aliased timespec;
656 Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access);
657 pragma Assert (Result = 0);
658 return To_Duration (TS);
665 function RT_Resolution return Duration is
667 return 1.0 / Duration (sysClkRateGet);
674 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
675 pragma Unreferenced (Reason);
678 Result := semGive (T.Common.LL.CV);
679 pragma Assert (Result = 0);
686 procedure Yield (Do_Yield : Boolean := True) is
687 pragma Unreferenced (Do_Yield);
689 pragma Unreferenced (Result);
691 Result := taskDelay (0);
698 type Prio_Array_Type is array (System.Any_Priority) of Integer;
699 pragma Atomic_Components (Prio_Array_Type);
701 Prio_Array : Prio_Array_Type;
702 -- Global array containing the id of the currently running task for
703 -- each priority. Note that we assume that we are on a single processor
704 -- with run-till-blocked scheduling.
706 procedure Set_Priority
708 Prio : System.Any_Priority;
709 Loss_Of_Inheritance : Boolean := False)
711 Array_Item : Integer;
717 (T.Common.LL.Thread, To_VxWorks_Priority (int (Prio)));
718 pragma Assert (Result = 0);
720 if Dispatching_Policy = 'F' then
722 -- Annex D requirement [RM D.2.2 par. 9]:
724 -- If the task drops its priority due to the loss of inherited
725 -- priority, it is added at the head of the ready queue for its
726 -- new active priority.
728 if Loss_Of_Inheritance
729 and then Prio < T.Common.Current_Priority
731 Array_Item := Prio_Array (T.Common.Base_Priority) + 1;
732 Prio_Array (T.Common.Base_Priority) := Array_Item;
735 -- Give some processes a chance to arrive
739 -- Then wait for our turn to proceed
741 exit when Array_Item = Prio_Array (T.Common.Base_Priority)
742 or else Prio_Array (T.Common.Base_Priority) = 1;
745 Prio_Array (T.Common.Base_Priority) :=
746 Prio_Array (T.Common.Base_Priority) - 1;
750 T.Common.Current_Priority := Prio;
757 function Get_Priority (T : Task_Id) return System.Any_Priority is
759 return T.Common.Current_Priority;
766 procedure Enter_Task (Self_ID : Task_Id) is
767 procedure Init_Float;
768 pragma Import (C, Init_Float, "__gnat_init_float");
769 -- Properly initializes the FPU for PPC/MIPS systems
772 Self_ID.Common.LL.Thread := taskIdSelf;
773 Specific.Set (Self_ID);
777 -- Install the signal handlers
779 -- This is called for each task since there is no signal inheritance
780 -- between VxWorks tasks.
782 Install_Signal_Handlers;
786 for J in Known_Tasks'Range loop
787 if Known_Tasks (J) = null then
788 Known_Tasks (J) := Self_ID;
789 Self_ID.Known_Tasks_Index := J;
801 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
803 return new Ada_Task_Control_Block (Entry_Num);
810 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
812 -----------------------------
813 -- Register_Foreign_Thread --
814 -----------------------------
816 function Register_Foreign_Thread return Task_Id is
818 if Is_Valid_Task then
821 return Register_Foreign_Thread (taskIdSelf);
823 end Register_Foreign_Thread;
829 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
831 Self_ID.Common.LL.CV := semBCreate (SEM_Q_PRIORITY, SEM_EMPTY);
832 Self_ID.Common.LL.Thread := 0;
834 if Self_ID.Common.LL.CV = 0 then
839 if not Single_Lock then
840 Initialize_Lock (Self_ID.Common.LL.L'Access, ATCB_Level);
849 procedure Create_Task
851 Wrapper : System.Address;
852 Stack_Size : System.Parameters.Size_Type;
853 Priority : System.Any_Priority;
854 Succeeded : out Boolean)
856 Adjusted_Stack_Size : size_t;
858 -- Ask for four extra bytes of stack space so that the ATCB pointer can
859 -- be stored below the stack limit, plus extra space for the frame of
860 -- Task_Wrapper. This is so the user gets the amount of stack requested
861 -- exclusive of the needs.
863 -- We also have to allocate n more bytes for the task name storage and
864 -- enough space for the Wind Task Control Block which is around 0x778
865 -- bytes. VxWorks also seems to carve out additional space, so use 2048
866 -- as a nice round number. We might want to increment to the nearest
867 -- page size in case we ever support VxVMI.
869 -- ??? - we should come back and visit this so we can set the task name
870 -- to something appropriate.
872 Adjusted_Stack_Size := size_t (Stack_Size) + 2048;
874 -- Since the initial signal mask of a thread is inherited from the
875 -- creator, and the Environment task has all its signals masked, we do
876 -- not need to manipulate caller's signal mask at this point. All tasks
877 -- in RTS will have All_Tasks_Mask initially.
879 if T.Common.Task_Image_Len = 0 then
880 T.Common.LL.Thread := taskSpawn
881 (System.Null_Address,
882 To_VxWorks_Priority (int (Priority)),
889 Name : aliased String (1 .. T.Common.Task_Image_Len + 1);
892 Name (1 .. Name'Last - 1) :=
893 T.Common.Task_Image (1 .. T.Common.Task_Image_Len);
894 Name (Name'Last) := ASCII.NUL;
896 T.Common.LL.Thread := taskSpawn
898 To_VxWorks_Priority (int (Priority)),
906 if T.Common.LL.Thread = -1 then
912 Task_Creation_Hook (T.Common.LL.Thread);
913 Set_Priority (T, Priority);
920 procedure Finalize_TCB (T : Task_Id) is
923 Is_Self : constant Boolean := (T = Self);
925 procedure Free is new
926 Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
929 if not Single_Lock then
930 Result := semDelete (T.Common.LL.L.Mutex);
931 pragma Assert (Result = 0);
934 T.Common.LL.Thread := 0;
936 Result := semDelete (T.Common.LL.CV);
937 pragma Assert (Result = 0);
939 if T.Known_Tasks_Index /= -1 then
940 Known_Tasks (T.Known_Tasks_Index) := null;
954 procedure Exit_Task is
963 procedure Abort_Task (T : Task_Id) is
966 Result := kill (T.Common.LL.Thread,
967 Signal (Interrupt_Management.Abort_Task_Signal));
968 pragma Assert (Result = 0);
975 procedure Initialize (S : in out Suspension_Object) is
977 -- Initialize internal state. It is always initialized to False (ARM
983 -- Initialize internal mutex
985 -- Use simpler binary semaphore instead of VxWorks
986 -- mutual exclusion semaphore, because we don't need
987 -- the fancier semantics and their overhead.
989 S.L := semBCreate (SEM_Q_FIFO, SEM_FULL);
991 -- Initialize internal condition variable
993 S.CV := semBCreate (SEM_Q_FIFO, SEM_EMPTY);
1000 procedure Finalize (S : in out Suspension_Object) is
1003 -- Destroy internal mutex
1005 Result := semDelete (S.L);
1006 pragma Assert (Result = OK);
1008 -- Destroy internal condition variable
1010 Result := semDelete (S.CV);
1011 pragma Assert (Result = OK);
1018 function Current_State (S : Suspension_Object) return Boolean is
1020 -- We do not want to use lock on this read operation. State is marked
1021 -- as Atomic so that we ensure that the value retrieved is correct.
1030 procedure Set_False (S : in out Suspension_Object) is
1033 Result := semTake (S.L, WAIT_FOREVER);
1034 pragma Assert (Result = OK);
1038 Result := semGive (S.L);
1039 pragma Assert (Result = OK);
1046 procedure Set_True (S : in out Suspension_Object) is
1049 Result := semTake (S.L, WAIT_FOREVER);
1050 pragma Assert (Result = OK);
1052 -- If there is already a task waiting on this suspension object then
1053 -- we resume it, leaving the state of the suspension object to False,
1054 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1055 -- the state to True.
1061 Result := semGive (S.CV);
1062 pragma Assert (Result = OK);
1067 Result := semGive (S.L);
1068 pragma Assert (Result = OK);
1071 ------------------------
1072 -- Suspend_Until_True --
1073 ------------------------
1075 procedure Suspend_Until_True (S : in out Suspension_Object) is
1078 Result := semTake (S.L, WAIT_FOREVER);
1081 -- Program_Error must be raised upon calling Suspend_Until_True
1082 -- if another task is already waiting on that suspension object
1083 -- (ARM D.10 par. 10).
1085 Result := semGive (S.L);
1086 pragma Assert (Result = OK);
1088 raise Program_Error;
1090 -- Suspend the task if the state is False. Otherwise, the task
1091 -- continues its execution, and the state of the suspension object
1092 -- is set to False (ARM D.10 par. 9).
1097 Result := semGive (S.L);
1098 pragma Assert (Result = 0);
1102 -- Release the mutex before sleeping
1104 Result := semGive (S.L);
1105 pragma Assert (Result = OK);
1107 Result := semTake (S.CV, WAIT_FOREVER);
1108 pragma Assert (Result = 0);
1111 end Suspend_Until_True;
1119 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1120 pragma Unreferenced (Self_ID);
1125 --------------------
1126 -- Check_No_Locks --
1127 --------------------
1129 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1130 pragma Unreferenced (Self_ID);
1135 ----------------------
1136 -- Environment_Task --
1137 ----------------------
1139 function Environment_Task return Task_Id is
1141 return Environment_Task_Id;
1142 end Environment_Task;
1148 procedure Lock_RTS is
1150 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1157 procedure Unlock_RTS is
1159 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1166 function Suspend_Task
1168 Thread_Self : Thread_Id) return Boolean
1171 if T.Common.LL.Thread /= 0
1172 and then T.Common.LL.Thread /= Thread_Self
1174 return taskSuspend (T.Common.LL.Thread) = 0;
1184 function Resume_Task
1186 Thread_Self : Thread_Id) return Boolean
1189 if T.Common.LL.Thread /= 0
1190 and then T.Common.LL.Thread /= Thread_Self
1192 return taskResume (T.Common.LL.Thread) = 0;
1202 procedure Initialize (Environment_Task : Task_Id) is
1205 Environment_Task_Id := Environment_Task;
1207 Interrupt_Management.Initialize;
1208 Specific.Initialize;
1210 if Locking_Policy = 'C' then
1211 Mutex_Protocol := Prio_Protect;
1212 elsif Locking_Policy = 'I' then
1213 Mutex_Protocol := Prio_Inherit;
1215 Mutex_Protocol := Prio_None;
1218 if Time_Slice_Val > 0 then
1219 Result := Set_Time_Slice
1221 (Duration (Time_Slice_Val) / Duration (1_000_000.0)));
1224 Result := sigemptyset (Unblocked_Signal_Mask'Access);
1225 pragma Assert (Result = 0);
1227 for J in Interrupt_Management.Signal_ID loop
1228 if System.Interrupt_Management.Keep_Unmasked (J) then
1229 Result := sigaddset (Unblocked_Signal_Mask'Access, Signal (J));
1230 pragma Assert (Result = 0);
1234 -- Initialize the lock used to synchronize chain of all ATCBs
1236 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1238 Enter_Task (Environment_Task);
1241 end System.Task_Primitives.Operations;