1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . T A S K _ P R I M I T I V E S . O P E R A T I O N S --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 -- This is the VxWorks version of this package
34 -- This package contains all the GNULL primitives that interface directly with
38 -- Turn off polling, we do not want ATC polling to take place during tasking
39 -- operations. It causes infinite loops and other problems.
41 with Ada.Unchecked_Conversion;
42 with Ada.Unchecked_Deallocation;
46 with System.Tasking.Debug;
47 with System.Interrupt_Management;
49 with System.Soft_Links;
50 -- We use System.Soft_Links instead of System.Tasking.Initialization
51 -- because the later is a higher level package that we shouldn't depend
52 -- on. For example when using the restricted run time, it is replaced by
53 -- System.Tasking.Restricted.Stages.
55 with System.VxWorks.Ext;
57 package body System.Task_Primitives.Operations is
59 package SSL renames System.Soft_Links;
61 use System.Tasking.Debug;
63 use System.OS_Interface;
64 use System.Parameters;
65 use type System.VxWorks.Ext.t_id;
66 use type Interfaces.C.int;
68 subtype int is System.OS_Interface.int;
70 Relative : constant := 0;
76 -- The followings are logically constants, but need to be initialized at
79 Single_RTS_Lock : aliased RTS_Lock;
80 -- This is a lock to allow only one thread of control in the RTS at a
81 -- time; it is used to execute in mutual exclusion from all other tasks.
82 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
84 Environment_Task_Id : Task_Id;
85 -- A variable to hold Task_Id for the environment task
87 Unblocked_Signal_Mask : aliased sigset_t;
88 -- The set of signals that should unblocked in all tasks
90 -- The followings are internal configuration constants needed
92 Time_Slice_Val : Integer;
93 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
95 Locking_Policy : Character;
96 pragma Import (C, Locking_Policy, "__gl_locking_policy");
98 Dispatching_Policy : Character;
99 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
101 function Get_Policy (Prio : System.Any_Priority) return Character;
102 pragma Import (C, Get_Policy, "__gnat_get_specific_dispatching");
103 -- Get priority specific dispatching policy
105 Mutex_Protocol : Priority_Type;
107 Foreign_Task_Elaborated : aliased Boolean := True;
108 -- Used to identified fake tasks (i.e., non-Ada Threads)
110 type Set_Stack_Limit_Proc_Acc is access procedure;
111 pragma Convention (C, Set_Stack_Limit_Proc_Acc);
113 Set_Stack_Limit_Hook : Set_Stack_Limit_Proc_Acc;
114 pragma Import (C, Set_Stack_Limit_Hook, "__gnat_set_stack_limit_hook");
115 -- Procedure to be called when a task is created to set stack
124 procedure Initialize;
125 pragma Inline (Initialize);
126 -- Initialize task specific data
128 function Is_Valid_Task return Boolean;
129 pragma Inline (Is_Valid_Task);
130 -- Does executing thread have a TCB?
132 procedure Set (Self_Id : Task_Id);
134 -- Set the self id for the current task
137 pragma Inline (Delete);
138 -- Delete the task specific data associated with the current task
140 function Self return Task_Id;
141 pragma Inline (Self);
142 -- Return a pointer to the Ada Task Control Block of the calling task
146 package body Specific is separate;
147 -- The body of this package is target specific
149 ---------------------------------
150 -- Support for foreign threads --
151 ---------------------------------
153 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
154 -- Allocate and Initialize a new ATCB for the current Thread
156 function Register_Foreign_Thread
157 (Thread : Thread_Id) return Task_Id is separate;
159 -----------------------
160 -- Local Subprograms --
161 -----------------------
163 procedure Abort_Handler (signo : Signal);
164 -- Handler for the abort (SIGABRT) signal to handle asynchronous abort
166 procedure Install_Signal_Handlers;
167 -- Install the default signal handlers for the current task
169 function To_Address is
170 new Ada.Unchecked_Conversion (Task_Id, System.Address);
176 procedure Abort_Handler (signo : Signal) is
177 pragma Unreferenced (signo);
179 Self_ID : constant Task_Id := Self;
180 Old_Set : aliased sigset_t;
183 pragma Warnings (Off, Result);
186 -- It is not safe to raise an exception when using ZCX and the GCC
187 -- exception handling mechanism.
189 if ZCX_By_Default and then GCC_ZCX_Support then
193 if Self_ID.Deferral_Level = 0
194 and then Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
195 and then not Self_ID.Aborting
197 Self_ID.Aborting := True;
199 -- Make sure signals used for RTS internal purpose are unmasked
204 Unblocked_Signal_Mask'Access,
206 pragma Assert (Result = 0);
208 raise Standard'Abort_Signal;
216 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
217 pragma Unreferenced (T);
218 pragma Unreferenced (On);
221 -- Nothing needed (why not???)
230 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
232 return T.Common.LL.Thread;
239 function Self return Task_Id renames Specific.Self;
241 -----------------------------
242 -- Install_Signal_Handlers --
243 -----------------------------
245 procedure Install_Signal_Handlers is
246 act : aliased struct_sigaction;
247 old_act : aliased struct_sigaction;
248 Tmp_Set : aliased sigset_t;
253 act.sa_handler := Abort_Handler'Address;
255 Result := sigemptyset (Tmp_Set'Access);
256 pragma Assert (Result = 0);
257 act.sa_mask := Tmp_Set;
261 (Signal (Interrupt_Management.Abort_Task_Interrupt),
262 act'Unchecked_Access,
263 old_act'Unchecked_Access);
264 pragma Assert (Result = 0);
266 Interrupt_Management.Initialize_Interrupts;
267 end Install_Signal_Handlers;
269 ---------------------
270 -- Initialize_Lock --
271 ---------------------
273 procedure Initialize_Lock
274 (Prio : System.Any_Priority;
275 L : not null access Lock)
278 L.Mutex := semMCreate (SEM_Q_PRIORITY + SEM_INVERSION_SAFE);
279 L.Prio_Ceiling := int (Prio);
280 L.Protocol := Mutex_Protocol;
281 pragma Assert (L.Mutex /= 0);
284 procedure Initialize_Lock
285 (L : not null access RTS_Lock;
288 pragma Unreferenced (Level);
290 L.Mutex := semMCreate (SEM_Q_PRIORITY + SEM_INVERSION_SAFE);
291 L.Prio_Ceiling := int (System.Any_Priority'Last);
292 L.Protocol := Mutex_Protocol;
293 pragma Assert (L.Mutex /= 0);
300 procedure Finalize_Lock (L : not null access Lock) is
303 Result := semDelete (L.Mutex);
304 pragma Assert (Result = 0);
307 procedure Finalize_Lock (L : not null access RTS_Lock) is
310 Result := semDelete (L.Mutex);
311 pragma Assert (Result = 0);
319 (L : not null access Lock;
320 Ceiling_Violation : out Boolean)
325 if L.Protocol = Prio_Protect
326 and then int (Self.Common.Current_Priority) > L.Prio_Ceiling
328 Ceiling_Violation := True;
331 Ceiling_Violation := False;
334 Result := semTake (L.Mutex, WAIT_FOREVER);
335 pragma Assert (Result = 0);
339 (L : not null access RTS_Lock;
340 Global_Lock : Boolean := False)
344 if not Single_Lock or else Global_Lock then
345 Result := semTake (L.Mutex, WAIT_FOREVER);
346 pragma Assert (Result = 0);
350 procedure Write_Lock (T : Task_Id) is
353 if not Single_Lock then
354 Result := semTake (T.Common.LL.L.Mutex, WAIT_FOREVER);
355 pragma Assert (Result = 0);
364 (L : not null access Lock;
365 Ceiling_Violation : out Boolean)
368 Write_Lock (L, Ceiling_Violation);
375 procedure Unlock (L : not null access Lock) is
378 Result := semGive (L.Mutex);
379 pragma Assert (Result = 0);
383 (L : not null access RTS_Lock;
384 Global_Lock : Boolean := False)
388 if not Single_Lock or else Global_Lock then
389 Result := semGive (L.Mutex);
390 pragma Assert (Result = 0);
394 procedure Unlock (T : Task_Id) is
397 if not Single_Lock then
398 Result := semGive (T.Common.LL.L.Mutex);
399 pragma Assert (Result = 0);
407 -- Dynamic priority ceilings are not supported by the underlying system
409 procedure Set_Ceiling
410 (L : not null access Lock;
411 Prio : System.Any_Priority)
413 pragma Unreferenced (L, Prio);
422 procedure Sleep (Self_ID : Task_Id; Reason : System.Tasking.Task_States) is
423 pragma Unreferenced (Reason);
428 pragma Assert (Self_ID = Self);
430 -- Release the mutex before sleeping
433 Result := semGive (Single_RTS_Lock.Mutex);
435 Result := semGive (Self_ID.Common.LL.L.Mutex);
438 pragma Assert (Result = 0);
440 -- Perform a blocking operation to take the CV semaphore. Note that a
441 -- blocking operation in VxWorks will reenable task scheduling. When we
442 -- are no longer blocked and control is returned, task scheduling will
443 -- again be disabled.
445 Result := semTake (Self_ID.Common.LL.CV, WAIT_FOREVER);
446 pragma Assert (Result = 0);
448 -- Take the mutex back
451 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
453 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
456 pragma Assert (Result = 0);
463 -- This is for use within the run-time system, so abort is assumed to be
464 -- already deferred, and the caller should be holding its own ATCB lock.
466 procedure Timed_Sleep
469 Mode : ST.Delay_Modes;
470 Reason : System.Tasking.Task_States;
471 Timedout : out Boolean;
472 Yielded : out Boolean)
474 pragma Unreferenced (Reason);
476 Orig : constant Duration := Monotonic_Clock;
480 Wakeup : Boolean := False;
486 if Mode = Relative then
487 Absolute := Orig + Time;
489 -- Systematically add one since the first tick will delay *at most*
490 -- 1 / Rate_Duration seconds, so we need to add one to be on the
493 Ticks := To_Clock_Ticks (Time);
495 if Ticks > 0 and then Ticks < int'Last then
501 Ticks := To_Clock_Ticks (Time - Monotonic_Clock);
506 -- Release the mutex before sleeping
509 Result := semGive (Single_RTS_Lock.Mutex);
511 Result := semGive (Self_ID.Common.LL.L.Mutex);
514 pragma Assert (Result = 0);
516 -- Perform a blocking operation to take the CV semaphore. Note
517 -- that a blocking operation in VxWorks will reenable task
518 -- scheduling. When we are no longer blocked and control is
519 -- returned, task scheduling will again be disabled.
521 Result := semTake (Self_ID.Common.LL.CV, Ticks);
525 -- Somebody may have called Wakeup for us
530 if errno /= S_objLib_OBJ_TIMEOUT then
534 -- If Ticks = int'last, it was most probably truncated so
535 -- let's make another round after recomputing Ticks from
536 -- the absolute time.
538 if Ticks /= int'Last then
542 Ticks := To_Clock_Ticks (Absolute - Monotonic_Clock);
551 -- Take the mutex back
554 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
556 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
559 pragma Assert (Result = 0);
561 exit when Timedout or Wakeup;
567 -- Should never hold a lock while yielding
570 Result := semGive (Single_RTS_Lock.Mutex);
572 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
575 Result := semGive (Self_ID.Common.LL.L.Mutex);
577 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
586 -- This is for use in implementing delay statements, so we assume the
587 -- caller is holding no locks.
589 procedure Timed_Delay
592 Mode : ST.Delay_Modes)
594 Orig : constant Duration := Monotonic_Clock;
598 Aborted : Boolean := False;
601 pragma Warnings (Off, Result);
604 if Mode = Relative then
605 Absolute := Orig + Time;
606 Ticks := To_Clock_Ticks (Time);
608 if Ticks > 0 and then Ticks < int'Last then
610 -- First tick will delay anytime between 0 and 1 / sysClkRateGet
611 -- seconds, so we need to add one to be on the safe side.
618 Ticks := To_Clock_Ticks (Time - Orig);
623 -- Modifying State, locking the TCB
626 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
628 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
631 pragma Assert (Result = 0);
633 Self_ID.Common.State := Delay_Sleep;
637 Aborted := Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
639 -- Release the TCB before sleeping
642 Result := semGive (Single_RTS_Lock.Mutex);
644 Result := semGive (Self_ID.Common.LL.L.Mutex);
646 pragma Assert (Result = 0);
650 Result := semTake (Self_ID.Common.LL.CV, Ticks);
654 -- If Ticks = int'last, it was most probably truncated
655 -- so let's make another round after recomputing Ticks
656 -- from the absolute time.
658 if errno = S_objLib_OBJ_TIMEOUT and then Ticks /= int'Last then
661 Ticks := To_Clock_Ticks (Absolute - Monotonic_Clock);
669 -- Take back the lock after having slept, to protect further
670 -- access to Self_ID.
673 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
675 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
678 pragma Assert (Result = 0);
683 Self_ID.Common.State := Runnable;
686 Result := semGive (Single_RTS_Lock.Mutex);
688 Result := semGive (Self_ID.Common.LL.L.Mutex);
696 ---------------------
697 -- Monotonic_Clock --
698 ---------------------
700 function Monotonic_Clock return Duration is
701 TS : aliased timespec;
704 Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access);
705 pragma Assert (Result = 0);
706 return To_Duration (TS);
713 function RT_Resolution return Duration is
715 return 1.0 / Duration (sysClkRateGet);
722 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
723 pragma Unreferenced (Reason);
726 Result := semGive (T.Common.LL.CV);
727 pragma Assert (Result = 0);
734 procedure Yield (Do_Yield : Boolean := True) is
735 pragma Unreferenced (Do_Yield);
737 pragma Unreferenced (Result);
739 Result := taskDelay (0);
746 type Prio_Array_Type is array (System.Any_Priority) of Integer;
747 pragma Atomic_Components (Prio_Array_Type);
749 Prio_Array : Prio_Array_Type;
750 -- Global array containing the id of the currently running task for each
751 -- priority. Note that we assume that we are on a single processor with
752 -- run-till-blocked scheduling.
754 procedure Set_Priority
756 Prio : System.Any_Priority;
757 Loss_Of_Inheritance : Boolean := False)
759 Array_Item : Integer;
765 (T.Common.LL.Thread, To_VxWorks_Priority (int (Prio)));
766 pragma Assert (Result = 0);
768 if (Dispatching_Policy = 'F' or else Get_Policy (Prio) = 'F')
769 and then Loss_Of_Inheritance
770 and then Prio < T.Common.Current_Priority
772 -- Annex D requirement (RM D.2.2(9)):
774 -- If the task drops its priority due to the loss of inherited
775 -- priority, it is added at the head of the ready queue for its
776 -- new active priority.
778 Array_Item := Prio_Array (T.Common.Base_Priority) + 1;
779 Prio_Array (T.Common.Base_Priority) := Array_Item;
782 -- Give some processes a chance to arrive
786 -- Then wait for our turn to proceed
788 exit when Array_Item = Prio_Array (T.Common.Base_Priority)
789 or else Prio_Array (T.Common.Base_Priority) = 1;
792 Prio_Array (T.Common.Base_Priority) :=
793 Prio_Array (T.Common.Base_Priority) - 1;
796 T.Common.Current_Priority := Prio;
803 function Get_Priority (T : Task_Id) return System.Any_Priority is
805 return T.Common.Current_Priority;
812 procedure Enter_Task (Self_ID : Task_Id) is
813 procedure Init_Float;
814 pragma Import (C, Init_Float, "__gnat_init_float");
815 -- Properly initializes the FPU for PPC/MIPS systems
818 -- Store the user-level task id in the Thread field (to be used
819 -- internally by the run-time system) and the kernel-level task id in
820 -- the LWP field (to be used by the debugger).
822 Self_ID.Common.LL.Thread := taskIdSelf;
823 Self_ID.Common.LL.LWP := getpid;
825 Specific.Set (Self_ID);
829 -- Install the signal handlers
831 -- This is called for each task since there is no signal inheritance
832 -- between VxWorks tasks.
834 Install_Signal_Handlers;
838 for J in Known_Tasks'Range loop
839 if Known_Tasks (J) = null then
840 Known_Tasks (J) := Self_ID;
841 Self_ID.Known_Tasks_Index := J;
848 -- If stack checking is enabled, set the stack limit for this task
850 if Set_Stack_Limit_Hook /= null then
851 Set_Stack_Limit_Hook.all;
859 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
861 return new Ada_Task_Control_Block (Entry_Num);
868 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
870 -----------------------------
871 -- Register_Foreign_Thread --
872 -----------------------------
874 function Register_Foreign_Thread return Task_Id is
876 if Is_Valid_Task then
879 return Register_Foreign_Thread (taskIdSelf);
881 end Register_Foreign_Thread;
887 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
889 Self_ID.Common.LL.CV := semBCreate (SEM_Q_PRIORITY, SEM_EMPTY);
890 Self_ID.Common.LL.Thread := 0;
892 if Self_ID.Common.LL.CV = 0 then
898 if not Single_Lock then
899 Initialize_Lock (Self_ID.Common.LL.L'Access, ATCB_Level);
908 procedure Create_Task
910 Wrapper : System.Address;
911 Stack_Size : System.Parameters.Size_Type;
912 Priority : System.Any_Priority;
913 Succeeded : out Boolean)
915 Adjusted_Stack_Size : size_t;
917 -- Ask for four extra bytes of stack space so that the ATCB pointer can
918 -- be stored below the stack limit, plus extra space for the frame of
919 -- Task_Wrapper. This is so the user gets the amount of stack requested
920 -- exclusive of the needs.
922 -- We also have to allocate n more bytes for the task name storage and
923 -- enough space for the Wind Task Control Block which is around 0x778
924 -- bytes. VxWorks also seems to carve out additional space, so use 2048
925 -- as a nice round number. We might want to increment to the nearest
926 -- page size in case we ever support VxVMI.
928 -- ??? - we should come back and visit this so we can set the task name
929 -- to something appropriate.
931 Adjusted_Stack_Size := size_t (Stack_Size) + 2048;
933 -- Since the initial signal mask of a thread is inherited from the
934 -- creator, and the Environment task has all its signals masked, we do
935 -- not need to manipulate caller's signal mask at this point. All tasks
936 -- in RTS will have All_Tasks_Mask initially.
938 -- We now compute the VxWorks task name and options, then spawn ...
941 Name : aliased String (1 .. T.Common.Task_Image_Len + 1);
942 Name_Address : System.Address;
943 -- Task name we are going to hand down to VxWorks
945 function Get_Task_Options return int;
946 pragma Import (C, Get_Task_Options, "__gnat_get_task_options");
947 -- Function that returns the options to be set for the task that we
948 -- are creating. We fetch the options assigned to the current task,
949 -- so offering some user level control over the options for a task
950 -- hierarchy, and force VX_FP_TASK because it is almost always
954 -- If there is no Ada task name handy, let VxWorks choose one.
955 -- Otherwise, tell VxWorks what the Ada task name is.
957 if T.Common.Task_Image_Len = 0 then
958 Name_Address := System.Null_Address;
960 Name (1 .. Name'Last - 1) :=
961 T.Common.Task_Image (1 .. T.Common.Task_Image_Len);
962 Name (Name'Last) := ASCII.NUL;
963 Name_Address := Name'Address;
966 -- Now spawn the VxWorks task for real
968 T.Common.LL.Thread :=
971 To_VxWorks_Priority (int (Priority)),
978 if T.Common.LL.Thread = -1 then
982 Task_Creation_Hook (T.Common.LL.Thread);
983 Set_Priority (T, Priority);
991 procedure Finalize_TCB (T : Task_Id) is
994 Is_Self : constant Boolean := (T = Self);
996 procedure Free is new
997 Ada.Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
1000 if not Single_Lock then
1001 Result := semDelete (T.Common.LL.L.Mutex);
1002 pragma Assert (Result = 0);
1005 T.Common.LL.Thread := 0;
1007 Result := semDelete (T.Common.LL.CV);
1008 pragma Assert (Result = 0);
1010 if T.Known_Tasks_Index /= -1 then
1011 Known_Tasks (T.Known_Tasks_Index) := null;
1025 procedure Exit_Task is
1027 Specific.Set (null);
1034 procedure Abort_Task (T : Task_Id) is
1039 (T.Common.LL.Thread,
1040 Signal (Interrupt_Management.Abort_Task_Interrupt));
1041 pragma Assert (Result = 0);
1048 procedure Initialize (S : in out Suspension_Object) is
1050 -- Initialize internal state (always to False (RM D.10(6)))
1055 -- Initialize internal mutex
1057 -- Use simpler binary semaphore instead of VxWorks
1058 -- mutual exclusion semaphore, because we don't need
1059 -- the fancier semantics and their overhead.
1061 S.L := semBCreate (SEM_Q_FIFO, SEM_FULL);
1063 -- Initialize internal condition variable
1065 S.CV := semBCreate (SEM_Q_FIFO, SEM_EMPTY);
1072 procedure Finalize (S : in out Suspension_Object) is
1073 pragma Unmodified (S);
1074 -- S may be modified on other targets, but not on VxWorks
1079 -- Destroy internal mutex
1081 Result := semDelete (S.L);
1082 pragma Assert (Result = OK);
1084 -- Destroy internal condition variable
1086 Result := semDelete (S.CV);
1087 pragma Assert (Result = OK);
1094 function Current_State (S : Suspension_Object) return Boolean is
1096 -- We do not want to use lock on this read operation. State is marked
1097 -- as Atomic so that we ensure that the value retrieved is correct.
1106 procedure Set_False (S : in out Suspension_Object) is
1110 SSL.Abort_Defer.all;
1112 Result := semTake (S.L, WAIT_FOREVER);
1113 pragma Assert (Result = OK);
1117 Result := semGive (S.L);
1118 pragma Assert (Result = OK);
1120 SSL.Abort_Undefer.all;
1127 procedure Set_True (S : in out Suspension_Object) is
1131 SSL.Abort_Defer.all;
1133 Result := semTake (S.L, WAIT_FOREVER);
1134 pragma Assert (Result = OK);
1136 -- If there is already a task waiting on this suspension object then
1137 -- we resume it, leaving the state of the suspension object to False,
1138 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1139 -- the state to True.
1145 Result := semGive (S.CV);
1146 pragma Assert (Result = OK);
1151 Result := semGive (S.L);
1152 pragma Assert (Result = OK);
1154 SSL.Abort_Undefer.all;
1157 ------------------------
1158 -- Suspend_Until_True --
1159 ------------------------
1161 procedure Suspend_Until_True (S : in out Suspension_Object) is
1165 SSL.Abort_Defer.all;
1167 Result := semTake (S.L, WAIT_FOREVER);
1171 -- Program_Error must be raised upon calling Suspend_Until_True
1172 -- if another task is already waiting on that suspension object
1173 -- (ARM D.10 par. 10).
1175 Result := semGive (S.L);
1176 pragma Assert (Result = OK);
1178 SSL.Abort_Undefer.all;
1180 raise Program_Error;
1183 -- Suspend the task if the state is False. Otherwise, the task
1184 -- continues its execution, and the state of the suspension object
1185 -- is set to False (ARM D.10 par. 9).
1190 Result := semGive (S.L);
1191 pragma Assert (Result = 0);
1193 SSL.Abort_Undefer.all;
1198 -- Release the mutex before sleeping
1200 Result := semGive (S.L);
1201 pragma Assert (Result = OK);
1203 SSL.Abort_Undefer.all;
1205 Result := semTake (S.CV, WAIT_FOREVER);
1206 pragma Assert (Result = 0);
1209 end Suspend_Until_True;
1217 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1218 pragma Unreferenced (Self_ID);
1223 --------------------
1224 -- Check_No_Locks --
1225 --------------------
1227 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1228 pragma Unreferenced (Self_ID);
1233 ----------------------
1234 -- Environment_Task --
1235 ----------------------
1237 function Environment_Task return Task_Id is
1239 return Environment_Task_Id;
1240 end Environment_Task;
1246 procedure Lock_RTS is
1248 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1255 procedure Unlock_RTS is
1257 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1264 function Suspend_Task
1266 Thread_Self : Thread_Id) return Boolean
1269 if T.Common.LL.Thread /= 0
1270 and then T.Common.LL.Thread /= Thread_Self
1272 return taskSuspend (T.Common.LL.Thread) = 0;
1282 function Resume_Task
1284 Thread_Self : Thread_Id) return Boolean
1287 if T.Common.LL.Thread /= 0
1288 and then T.Common.LL.Thread /= Thread_Self
1290 return taskResume (T.Common.LL.Thread) = 0;
1296 --------------------
1297 -- Stop_All_Tasks --
1298 --------------------
1300 procedure Stop_All_Tasks
1302 Thread_Self : constant Thread_Id := taskIdSelf;
1306 pragma Unreferenced (Dummy);
1311 C := All_Tasks_List;
1312 while C /= null loop
1313 if C.Common.LL.Thread /= 0
1314 and then C.Common.LL.Thread /= Thread_Self
1316 Dummy := Task_Stop (C.Common.LL.Thread);
1319 C := C.Common.All_Tasks_Link;
1322 Dummy := Int_Unlock;
1329 function Stop_Task (T : ST.Task_Id) return Boolean is
1331 if T.Common.LL.Thread /= 0 then
1332 return Task_Stop (T.Common.LL.Thread) = 0;
1342 function Continue_Task (T : ST.Task_Id) return Boolean
1345 if T.Common.LL.Thread /= 0 then
1346 return Task_Cont (T.Common.LL.Thread) = 0;
1356 procedure Initialize (Environment_Task : Task_Id) is
1360 Environment_Task_Id := Environment_Task;
1362 Interrupt_Management.Initialize;
1363 Specific.Initialize;
1365 if Locking_Policy = 'C' then
1366 Mutex_Protocol := Prio_Protect;
1367 elsif Locking_Policy = 'I' then
1368 Mutex_Protocol := Prio_Inherit;
1370 Mutex_Protocol := Prio_None;
1373 if Time_Slice_Val > 0 then
1377 (Duration (Time_Slice_Val) / Duration (1_000_000.0)));
1379 elsif Dispatching_Policy = 'R' then
1380 Result := Set_Time_Slice (To_Clock_Ticks (0.01));
1384 Result := sigemptyset (Unblocked_Signal_Mask'Access);
1385 pragma Assert (Result = 0);
1387 for J in Interrupt_Management.Signal_ID loop
1388 if System.Interrupt_Management.Keep_Unmasked (J) then
1389 Result := sigaddset (Unblocked_Signal_Mask'Access, Signal (J));
1390 pragma Assert (Result = 0);
1394 -- Initialize the lock used to synchronize chain of all ATCBs
1396 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1398 Enter_Task (Environment_Task);
1401 end System.Task_Primitives.Operations;