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 System.Soft_Links;
55 -- used for Abort_Defer/Undefer
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 with Unchecked_Conversion;
63 with Unchecked_Deallocation;
65 package body System.Task_Primitives.Operations is
67 package SSL renames System.Soft_Links;
69 use System.Tasking.Debug;
71 use System.OS_Interface;
72 use System.Parameters;
73 use type Interfaces.C.int;
75 subtype int is System.OS_Interface.int;
77 Relative : constant := 0;
83 -- The followings are logically constants, but need to be initialized at
86 Single_RTS_Lock : aliased RTS_Lock;
87 -- This is a lock to allow only one thread of control in the RTS at a
88 -- time; it is used to execute in mutual exclusion from all other tasks.
89 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
91 Environment_Task_Id : Task_Id;
92 -- A variable to hold Task_Id for the environment task
94 Unblocked_Signal_Mask : aliased sigset_t;
95 -- The set of signals that should unblocked in all tasks
97 -- The followings are internal configuration constants needed
99 Time_Slice_Val : Integer;
100 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
102 Locking_Policy : Character;
103 pragma Import (C, Locking_Policy, "__gl_locking_policy");
105 Dispatching_Policy : Character;
106 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
108 Mutex_Protocol : Priority_Type;
110 Foreign_Task_Elaborated : aliased Boolean := True;
111 -- Used to identified fake tasks (i.e., non-Ada Threads)
119 procedure Initialize;
120 pragma Inline (Initialize);
121 -- Initialize task specific data
123 function Is_Valid_Task return Boolean;
124 pragma Inline (Is_Valid_Task);
125 -- Does executing thread have a TCB?
127 procedure Set (Self_Id : Task_Id);
129 -- Set the self id for the current task
132 pragma Inline (Delete);
133 -- Delete the task specific data associated with the current task
135 function Self return Task_Id;
136 pragma Inline (Self);
137 -- Return a pointer to the Ada Task Control Block of the calling task
141 package body Specific is separate;
142 -- The body of this package is target specific
144 ---------------------------------
145 -- Support for foreign threads --
146 ---------------------------------
148 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
149 -- Allocate and Initialize a new ATCB for the current Thread
151 function Register_Foreign_Thread
152 (Thread : Thread_Id) return Task_Id is separate;
154 -----------------------
155 -- Local Subprograms --
156 -----------------------
158 procedure Abort_Handler (signo : Signal);
159 -- Handler for the abort (SIGABRT) signal to handle asynchronous abort
161 procedure Install_Signal_Handlers;
162 -- Install the default signal handlers for the current task
164 function To_Address is new Unchecked_Conversion (Task_Id, System.Address);
170 procedure Abort_Handler (signo : Signal) is
171 pragma Unreferenced (signo);
173 Self_ID : constant Task_Id := Self;
175 Old_Set : aliased sigset_t;
178 -- It is not safe to raise an exception when using ZCX and the GCC
179 -- exception handling mechanism.
181 if ZCX_By_Default and then GCC_ZCX_Support then
185 if Self_ID.Deferral_Level = 0
186 and then Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
187 and then not Self_ID.Aborting
189 Self_ID.Aborting := True;
191 -- Make sure signals used for RTS internal purpose are unmasked
193 Result := pthread_sigmask (SIG_UNBLOCK,
194 Unblocked_Signal_Mask'Unchecked_Access, Old_Set'Unchecked_Access);
195 pragma Assert (Result = 0);
197 raise Standard'Abort_Signal;
205 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
206 pragma Unreferenced (T);
207 pragma Unreferenced (On);
210 -- Nothing needed (why not???)
219 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
221 return T.Common.LL.Thread;
228 function Self return Task_Id renames Specific.Self;
230 -----------------------------
231 -- Install_Signal_Handlers --
232 -----------------------------
234 procedure Install_Signal_Handlers is
235 act : aliased struct_sigaction;
236 old_act : aliased struct_sigaction;
237 Tmp_Set : aliased sigset_t;
242 act.sa_handler := Abort_Handler'Address;
244 Result := sigemptyset (Tmp_Set'Access);
245 pragma Assert (Result = 0);
246 act.sa_mask := Tmp_Set;
250 (Signal (Interrupt_Management.Abort_Task_Signal),
251 act'Unchecked_Access,
252 old_act'Unchecked_Access);
253 pragma Assert (Result = 0);
255 Interrupt_Management.Initialize_Interrupts;
256 end Install_Signal_Handlers;
258 ---------------------
259 -- Initialize_Lock --
260 ---------------------
262 procedure Initialize_Lock (Prio : System.Any_Priority; L : access Lock) is
264 L.Mutex := semMCreate (SEM_Q_PRIORITY + SEM_INVERSION_SAFE);
265 L.Prio_Ceiling := int (Prio);
266 L.Protocol := Mutex_Protocol;
267 pragma Assert (L.Mutex /= 0);
270 procedure Initialize_Lock (L : access RTS_Lock; Level : Lock_Level) is
271 pragma Unreferenced (Level);
274 L.Mutex := semMCreate (SEM_Q_PRIORITY + SEM_INVERSION_SAFE);
275 L.Prio_Ceiling := int (System.Any_Priority'Last);
276 L.Protocol := Mutex_Protocol;
277 pragma Assert (L.Mutex /= 0);
284 procedure Finalize_Lock (L : access Lock) is
287 Result := semDelete (L.Mutex);
288 pragma Assert (Result = 0);
291 procedure Finalize_Lock (L : access RTS_Lock) is
294 Result := semDelete (L.Mutex);
295 pragma Assert (Result = 0);
302 procedure Write_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
305 if L.Protocol = Prio_Protect
306 and then int (Self.Common.Current_Priority) > L.Prio_Ceiling
308 Ceiling_Violation := True;
311 Ceiling_Violation := False;
314 Result := semTake (L.Mutex, WAIT_FOREVER);
315 pragma Assert (Result = 0);
319 (L : access RTS_Lock;
320 Global_Lock : Boolean := False)
324 if not Single_Lock or else Global_Lock then
325 Result := semTake (L.Mutex, WAIT_FOREVER);
326 pragma Assert (Result = 0);
330 procedure Write_Lock (T : Task_Id) is
333 if not Single_Lock then
334 Result := semTake (T.Common.LL.L.Mutex, WAIT_FOREVER);
335 pragma Assert (Result = 0);
343 procedure Read_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
345 Write_Lock (L, Ceiling_Violation);
352 procedure Unlock (L : access Lock) is
355 Result := semGive (L.Mutex);
356 pragma Assert (Result = 0);
359 procedure Unlock (L : access RTS_Lock; Global_Lock : Boolean := False) is
362 if not Single_Lock or else Global_Lock then
363 Result := semGive (L.Mutex);
364 pragma Assert (Result = 0);
368 procedure Unlock (T : Task_Id) is
371 if not Single_Lock then
372 Result := semGive (T.Common.LL.L.Mutex);
373 pragma Assert (Result = 0);
381 procedure Sleep (Self_ID : Task_Id; Reason : System.Tasking.Task_States) is
382 pragma Unreferenced (Reason);
387 pragma Assert (Self_ID = Self);
389 -- Release the mutex before sleeping
392 Result := semGive (Single_RTS_Lock.Mutex);
394 Result := semGive (Self_ID.Common.LL.L.Mutex);
397 pragma Assert (Result = 0);
399 -- Perform a blocking operation to take the CV semaphore. Note that a
400 -- blocking operation in VxWorks will reenable task scheduling. When we
401 -- are no longer blocked and control is returned, task scheduling will
402 -- again be disabled.
404 Result := semTake (Self_ID.Common.LL.CV, WAIT_FOREVER);
405 pragma Assert (Result = 0);
407 -- Take the mutex back
410 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
412 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
415 pragma Assert (Result = 0);
422 -- This is for use within the run-time system, so abort is assumed to be
423 -- already deferred, and the caller should be holding its own ATCB lock.
425 procedure Timed_Sleep
428 Mode : ST.Delay_Modes;
429 Reason : System.Tasking.Task_States;
430 Timedout : out Boolean;
431 Yielded : out Boolean)
433 pragma Unreferenced (Reason);
435 Orig : constant Duration := Monotonic_Clock;
439 Wakeup : Boolean := False;
445 if Mode = Relative then
446 Absolute := Orig + Time;
448 -- Systematically add one since the first tick will delay *at most*
449 -- 1 / Rate_Duration seconds, so we need to add one to be on the
452 Ticks := To_Clock_Ticks (Time);
454 if Ticks > 0 and then Ticks < int'Last then
460 Ticks := To_Clock_Ticks (Time - Monotonic_Clock);
465 -- Release the mutex before sleeping
468 Result := semGive (Single_RTS_Lock.Mutex);
470 Result := semGive (Self_ID.Common.LL.L.Mutex);
473 pragma Assert (Result = 0);
475 -- Perform a blocking operation to take the CV semaphore. Note
476 -- that a blocking operation in VxWorks will reenable task
477 -- scheduling. When we are no longer blocked and control is
478 -- returned, task scheduling will again be disabled.
480 Result := semTake (Self_ID.Common.LL.CV, Ticks);
484 -- Somebody may have called Wakeup for us
489 if errno /= S_objLib_OBJ_TIMEOUT then
493 -- If Ticks = int'last, it was most probably truncated so
494 -- let's make another round after recomputing Ticks from
495 -- the the absolute time.
497 if Ticks /= int'Last then
500 Ticks := To_Clock_Ticks (Absolute - Monotonic_Clock);
509 -- Take the mutex back
512 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
514 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
517 pragma Assert (Result = 0);
519 exit when Timedout or Wakeup;
525 -- Should never hold a lock while yielding
528 Result := semGive (Single_RTS_Lock.Mutex);
530 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
533 Result := semGive (Self_ID.Common.LL.L.Mutex);
535 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
544 -- This is for use in implementing delay statements, so we assume the
545 -- caller is holding no locks.
547 procedure Timed_Delay
550 Mode : ST.Delay_Modes)
552 Orig : constant Duration := Monotonic_Clock;
557 Aborted : Boolean := False;
560 if Mode = Relative then
561 Absolute := Orig + Time;
562 Ticks := To_Clock_Ticks (Time);
564 if Ticks > 0 and then Ticks < int'Last then
566 -- First tick will delay anytime between 0 and 1 / sysClkRateGet
567 -- seconds, so we need to add one to be on the safe side.
574 Ticks := To_Clock_Ticks (Time - Orig);
579 -- Modifying State and Pending_Priority_Change, locking the TCB
582 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
584 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
587 pragma Assert (Result = 0);
589 Self_ID.Common.State := Delay_Sleep;
593 if Self_ID.Pending_Priority_Change then
594 Self_ID.Pending_Priority_Change := False;
595 Self_ID.Common.Base_Priority := Self_ID.New_Base_Priority;
596 Set_Priority (Self_ID, Self_ID.Common.Base_Priority);
599 Aborted := Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
601 -- Release the TCB before sleeping
604 Result := semGive (Single_RTS_Lock.Mutex);
606 Result := semGive (Self_ID.Common.LL.L.Mutex);
608 pragma Assert (Result = 0);
612 Result := semTake (Self_ID.Common.LL.CV, Ticks);
616 -- If Ticks = int'last, it was most probably truncated
617 -- so let's make another round after recomputing Ticks
618 -- from the the absolute time.
620 if errno = S_objLib_OBJ_TIMEOUT and then Ticks /= int'Last then
623 Ticks := To_Clock_Ticks (Absolute - Monotonic_Clock);
631 -- Take back the lock after having slept, to protect further
632 -- access to Self_ID.
635 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
637 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
640 pragma Assert (Result = 0);
645 Self_ID.Common.State := Runnable;
648 Result := semGive (Single_RTS_Lock.Mutex);
650 Result := semGive (Self_ID.Common.LL.L.Mutex);
658 ---------------------
659 -- Monotonic_Clock --
660 ---------------------
662 function Monotonic_Clock return Duration is
663 TS : aliased timespec;
666 Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access);
667 pragma Assert (Result = 0);
668 return To_Duration (TS);
675 function RT_Resolution return Duration is
677 return 1.0 / Duration (sysClkRateGet);
684 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
685 pragma Unreferenced (Reason);
688 Result := semGive (T.Common.LL.CV);
689 pragma Assert (Result = 0);
696 procedure Yield (Do_Yield : Boolean := True) is
697 pragma Unreferenced (Do_Yield);
699 pragma Unreferenced (Result);
701 Result := taskDelay (0);
708 type Prio_Array_Type is array (System.Any_Priority) of Integer;
709 pragma Atomic_Components (Prio_Array_Type);
711 Prio_Array : Prio_Array_Type;
712 -- Global array containing the id of the currently running task for
713 -- each priority. Note that we assume that we are on a single processor
714 -- with run-till-blocked scheduling.
716 procedure Set_Priority
718 Prio : System.Any_Priority;
719 Loss_Of_Inheritance : Boolean := False)
721 Array_Item : Integer;
727 (T.Common.LL.Thread, To_VxWorks_Priority (int (Prio)));
728 pragma Assert (Result = 0);
730 if Dispatching_Policy = 'F' then
732 -- Annex D requirement [RM D.2.2 par. 9]:
734 -- If the task drops its priority due to the loss of inherited
735 -- priority, it is added at the head of the ready queue for its
736 -- new active priority.
738 if Loss_Of_Inheritance
739 and then Prio < T.Common.Current_Priority
741 Array_Item := Prio_Array (T.Common.Base_Priority) + 1;
742 Prio_Array (T.Common.Base_Priority) := Array_Item;
745 -- Give some processes a chance to arrive
749 -- Then wait for our turn to proceed
751 exit when Array_Item = Prio_Array (T.Common.Base_Priority)
752 or else Prio_Array (T.Common.Base_Priority) = 1;
755 Prio_Array (T.Common.Base_Priority) :=
756 Prio_Array (T.Common.Base_Priority) - 1;
760 T.Common.Current_Priority := Prio;
767 function Get_Priority (T : Task_Id) return System.Any_Priority is
769 return T.Common.Current_Priority;
776 procedure Enter_Task (Self_ID : Task_Id) is
777 procedure Init_Float;
778 pragma Import (C, Init_Float, "__gnat_init_float");
779 -- Properly initializes the FPU for PPC/MIPS systems
782 Self_ID.Common.LL.Thread := taskIdSelf;
783 Specific.Set (Self_ID);
787 -- Install the signal handlers
789 -- This is called for each task since there is no signal inheritance
790 -- between VxWorks tasks.
792 Install_Signal_Handlers;
796 for J in Known_Tasks'Range loop
797 if Known_Tasks (J) = null then
798 Known_Tasks (J) := Self_ID;
799 Self_ID.Known_Tasks_Index := J;
811 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
813 return new Ada_Task_Control_Block (Entry_Num);
820 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
822 -----------------------------
823 -- Register_Foreign_Thread --
824 -----------------------------
826 function Register_Foreign_Thread return Task_Id is
828 if Is_Valid_Task then
831 return Register_Foreign_Thread (taskIdSelf);
833 end Register_Foreign_Thread;
839 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
841 Self_ID.Common.LL.CV := semBCreate (SEM_Q_PRIORITY, SEM_EMPTY);
842 Self_ID.Common.LL.Thread := 0;
844 if Self_ID.Common.LL.CV = 0 then
849 if not Single_Lock then
850 Initialize_Lock (Self_ID.Common.LL.L'Access, ATCB_Level);
859 procedure Create_Task
861 Wrapper : System.Address;
862 Stack_Size : System.Parameters.Size_Type;
863 Priority : System.Any_Priority;
864 Succeeded : out Boolean)
866 Adjusted_Stack_Size : size_t;
868 -- Ask for four extra bytes of stack space so that the ATCB pointer can
869 -- be stored below the stack limit, plus extra space for the frame of
870 -- Task_Wrapper. This is so the user gets the amount of stack requested
871 -- exclusive of the needs.
873 -- We also have to allocate n more bytes for the task name storage and
874 -- enough space for the Wind Task Control Block which is around 0x778
875 -- bytes. VxWorks also seems to carve out additional space, so use 2048
876 -- as a nice round number. We might want to increment to the nearest
877 -- page size in case we ever support VxVMI.
879 -- ??? - we should come back and visit this so we can set the task name
880 -- to something appropriate.
882 Adjusted_Stack_Size := size_t (Stack_Size) + 2048;
884 -- Since the initial signal mask of a thread is inherited from the
885 -- creator, and the Environment task has all its signals masked, we do
886 -- not need to manipulate caller's signal mask at this point. All tasks
887 -- in RTS will have All_Tasks_Mask initially.
889 if T.Common.Task_Image_Len = 0 then
890 T.Common.LL.Thread := taskSpawn
891 (System.Null_Address,
892 To_VxWorks_Priority (int (Priority)),
899 Name : aliased String (1 .. T.Common.Task_Image_Len + 1);
902 Name (1 .. Name'Last - 1) :=
903 T.Common.Task_Image (1 .. T.Common.Task_Image_Len);
904 Name (Name'Last) := ASCII.NUL;
906 T.Common.LL.Thread := taskSpawn
908 To_VxWorks_Priority (int (Priority)),
916 if T.Common.LL.Thread = -1 then
922 Task_Creation_Hook (T.Common.LL.Thread);
923 Set_Priority (T, Priority);
930 procedure Finalize_TCB (T : Task_Id) is
933 Is_Self : constant Boolean := (T = Self);
935 procedure Free is new
936 Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
939 if not Single_Lock then
940 Result := semDelete (T.Common.LL.L.Mutex);
941 pragma Assert (Result = 0);
944 T.Common.LL.Thread := 0;
946 Result := semDelete (T.Common.LL.CV);
947 pragma Assert (Result = 0);
949 if T.Known_Tasks_Index /= -1 then
950 Known_Tasks (T.Known_Tasks_Index) := null;
964 procedure Exit_Task is
973 procedure Abort_Task (T : Task_Id) is
976 Result := kill (T.Common.LL.Thread,
977 Signal (Interrupt_Management.Abort_Task_Signal));
978 pragma Assert (Result = 0);
985 procedure Initialize (S : in out Suspension_Object) is
987 -- Initialize internal state. It is always initialized to False (ARM
993 -- Initialize internal mutex
995 -- Use simpler binary semaphore instead of VxWorks
996 -- mutual exclusion semaphore, because we don't need
997 -- the fancier semantics and their overhead.
999 S.L := semBCreate (SEM_Q_FIFO, SEM_FULL);
1001 -- Initialize internal condition variable
1003 S.CV := semBCreate (SEM_Q_FIFO, SEM_EMPTY);
1010 procedure Finalize (S : in out Suspension_Object) is
1013 -- Destroy internal mutex
1015 Result := semDelete (S.L);
1016 pragma Assert (Result = OK);
1018 -- Destroy internal condition variable
1020 Result := semDelete (S.CV);
1021 pragma Assert (Result = OK);
1028 function Current_State (S : Suspension_Object) return Boolean is
1030 -- We do not want to use lock on this read operation. State is marked
1031 -- as Atomic so that we ensure that the value retrieved is correct.
1040 procedure Set_False (S : in out Suspension_Object) is
1043 SSL.Abort_Defer.all;
1045 Result := semTake (S.L, WAIT_FOREVER);
1046 pragma Assert (Result = OK);
1050 Result := semGive (S.L);
1051 pragma Assert (Result = OK);
1053 SSL.Abort_Undefer.all;
1060 procedure Set_True (S : in out Suspension_Object) is
1063 SSL.Abort_Defer.all;
1065 Result := semTake (S.L, WAIT_FOREVER);
1066 pragma Assert (Result = OK);
1068 -- If there is already a task waiting on this suspension object then
1069 -- we resume it, leaving the state of the suspension object to False,
1070 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1071 -- the state to True.
1077 Result := semGive (S.CV);
1078 pragma Assert (Result = OK);
1083 Result := semGive (S.L);
1084 pragma Assert (Result = OK);
1086 SSL.Abort_Undefer.all;
1089 ------------------------
1090 -- Suspend_Until_True --
1091 ------------------------
1093 procedure Suspend_Until_True (S : in out Suspension_Object) is
1096 SSL.Abort_Defer.all;
1098 Result := semTake (S.L, WAIT_FOREVER);
1101 -- Program_Error must be raised upon calling Suspend_Until_True
1102 -- if another task is already waiting on that suspension object
1103 -- (ARM D.10 par. 10).
1105 Result := semGive (S.L);
1106 pragma Assert (Result = OK);
1108 SSL.Abort_Undefer.all;
1110 raise Program_Error;
1112 -- Suspend the task if the state is False. Otherwise, the task
1113 -- continues its execution, and the state of the suspension object
1114 -- is set to False (ARM D.10 par. 9).
1119 Result := semGive (S.L);
1120 pragma Assert (Result = 0);
1122 SSL.Abort_Undefer.all;
1126 -- Release the mutex before sleeping
1128 Result := semGive (S.L);
1129 pragma Assert (Result = OK);
1131 SSL.Abort_Undefer.all;
1133 Result := semTake (S.CV, WAIT_FOREVER);
1134 pragma Assert (Result = 0);
1137 end Suspend_Until_True;
1145 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1146 pragma Unreferenced (Self_ID);
1151 --------------------
1152 -- Check_No_Locks --
1153 --------------------
1155 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1156 pragma Unreferenced (Self_ID);
1161 ----------------------
1162 -- Environment_Task --
1163 ----------------------
1165 function Environment_Task return Task_Id is
1167 return Environment_Task_Id;
1168 end Environment_Task;
1174 procedure Lock_RTS is
1176 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1183 procedure Unlock_RTS is
1185 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1192 function Suspend_Task
1194 Thread_Self : Thread_Id) return Boolean
1197 if T.Common.LL.Thread /= 0
1198 and then T.Common.LL.Thread /= Thread_Self
1200 return taskSuspend (T.Common.LL.Thread) = 0;
1210 function Resume_Task
1212 Thread_Self : Thread_Id) return Boolean
1215 if T.Common.LL.Thread /= 0
1216 and then T.Common.LL.Thread /= Thread_Self
1218 return taskResume (T.Common.LL.Thread) = 0;
1228 procedure Initialize (Environment_Task : Task_Id) is
1231 Environment_Task_Id := Environment_Task;
1233 Interrupt_Management.Initialize;
1234 Specific.Initialize;
1236 if Locking_Policy = 'C' then
1237 Mutex_Protocol := Prio_Protect;
1238 elsif Locking_Policy = 'I' then
1239 Mutex_Protocol := Prio_Inherit;
1241 Mutex_Protocol := Prio_None;
1244 if Time_Slice_Val > 0 then
1245 Result := Set_Time_Slice
1247 (Duration (Time_Slice_Val) / Duration (1_000_000.0)));
1250 Result := sigemptyset (Unblocked_Signal_Mask'Access);
1251 pragma Assert (Result = 0);
1253 for J in Interrupt_Management.Signal_ID loop
1254 if System.Interrupt_Management.Keep_Unmasked (J) then
1255 Result := sigaddset (Unblocked_Signal_Mask'Access, Signal (J));
1256 pragma Assert (Result = 0);
1260 -- Initialize the lock used to synchronize chain of all ATCBs
1262 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1264 Enter_Task (Environment_Task);
1267 end System.Task_Primitives.Operations;