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-2010, 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.Task_Info;
56 with System.VxWorks.Ext;
58 package body System.Task_Primitives.Operations is
60 package SSL renames System.Soft_Links;
62 use System.Tasking.Debug;
64 use System.OS_Interface;
65 use System.Parameters;
66 use type System.VxWorks.Ext.t_id;
67 use type Interfaces.C.int;
69 subtype int is System.OS_Interface.int;
71 Relative : constant := 0;
77 -- The followings are logically constants, but need to be initialized at
80 Single_RTS_Lock : aliased RTS_Lock;
81 -- This is a lock to allow only one thread of control in the RTS at a
82 -- time; it is used to execute in mutual exclusion from all other tasks.
83 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
85 Environment_Task_Id : Task_Id;
86 -- A variable to hold Task_Id for the environment task
88 Unblocked_Signal_Mask : aliased sigset_t;
89 -- The set of signals that should unblocked in all tasks
91 -- The followings are internal configuration constants needed
93 Time_Slice_Val : Integer;
94 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
96 Locking_Policy : Character;
97 pragma Import (C, Locking_Policy, "__gl_locking_policy");
99 Dispatching_Policy : Character;
100 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
102 Mutex_Protocol : Priority_Type;
104 Foreign_Task_Elaborated : aliased Boolean := True;
105 -- Used to identified fake tasks (i.e., non-Ada Threads)
107 type Set_Stack_Limit_Proc_Acc is access procedure;
108 pragma Convention (C, Set_Stack_Limit_Proc_Acc);
110 Set_Stack_Limit_Hook : Set_Stack_Limit_Proc_Acc;
111 pragma Import (C, Set_Stack_Limit_Hook, "__gnat_set_stack_limit_hook");
112 -- Procedure to be called when a task is created to set stack
121 procedure Initialize;
122 pragma Inline (Initialize);
123 -- Initialize task specific data
125 function Is_Valid_Task return Boolean;
126 pragma Inline (Is_Valid_Task);
127 -- Does executing thread have a TCB?
129 procedure Set (Self_Id : Task_Id);
131 -- Set the self id for the current task
134 pragma Inline (Delete);
135 -- Delete the task specific data associated with the current task
137 function Self return Task_Id;
138 pragma Inline (Self);
139 -- Return a pointer to the Ada Task Control Block of the calling task
143 package body Specific is separate;
144 -- The body of this package is target specific
146 ---------------------------------
147 -- Support for foreign threads --
148 ---------------------------------
150 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
151 -- Allocate and Initialize a new ATCB for the current Thread
153 function Register_Foreign_Thread
154 (Thread : Thread_Id) return Task_Id is separate;
156 -----------------------
157 -- Local Subprograms --
158 -----------------------
160 procedure Abort_Handler (signo : Signal);
161 -- Handler for the abort (SIGABRT) signal to handle asynchronous abort
163 procedure Install_Signal_Handlers;
164 -- Install the default signal handlers for the current task
166 function Is_Task_Context return Boolean;
167 -- This function returns True if the current execution is in the context
168 -- of a task, and False if it is an interrupt context.
170 function To_Address is
171 new Ada.Unchecked_Conversion (Task_Id, System.Address);
177 procedure Abort_Handler (signo : Signal) is
178 pragma Unreferenced (signo);
180 Self_ID : constant Task_Id := Self;
181 Old_Set : aliased sigset_t;
184 pragma Warnings (Off, Result);
187 -- It is not safe to raise an exception when using ZCX and the GCC
188 -- exception handling mechanism.
190 if ZCX_By_Default and then GCC_ZCX_Support then
194 if Self_ID.Deferral_Level = 0
195 and then Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
196 and then not Self_ID.Aborting
198 Self_ID.Aborting := True;
200 -- Make sure signals used for RTS internal purpose are unmasked
205 Unblocked_Signal_Mask'Access,
207 pragma Assert (Result = 0);
209 raise Standard'Abort_Signal;
217 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
218 pragma Unreferenced (T);
219 pragma Unreferenced (On);
222 -- Nothing needed (why not???)
231 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
233 return T.Common.LL.Thread;
240 function Self return Task_Id renames Specific.Self;
242 -----------------------------
243 -- Install_Signal_Handlers --
244 -----------------------------
246 procedure Install_Signal_Handlers is
247 act : aliased struct_sigaction;
248 old_act : aliased struct_sigaction;
249 Tmp_Set : aliased sigset_t;
254 act.sa_handler := Abort_Handler'Address;
256 Result := sigemptyset (Tmp_Set'Access);
257 pragma Assert (Result = 0);
258 act.sa_mask := Tmp_Set;
262 (Signal (Interrupt_Management.Abort_Task_Interrupt),
263 act'Unchecked_Access,
264 old_act'Unchecked_Access);
265 pragma Assert (Result = 0);
267 Interrupt_Management.Initialize_Interrupts;
268 end Install_Signal_Handlers;
270 ---------------------
271 -- Initialize_Lock --
272 ---------------------
274 procedure Initialize_Lock
275 (Prio : System.Any_Priority;
276 L : not null access Lock)
279 L.Mutex := semMCreate (SEM_Q_PRIORITY + SEM_INVERSION_SAFE);
280 L.Prio_Ceiling := int (Prio);
281 L.Protocol := Mutex_Protocol;
282 pragma Assert (L.Mutex /= 0);
285 procedure Initialize_Lock
286 (L : not null access RTS_Lock;
289 pragma Unreferenced (Level);
291 L.Mutex := semMCreate (SEM_Q_PRIORITY + SEM_INVERSION_SAFE);
292 L.Prio_Ceiling := int (System.Any_Priority'Last);
293 L.Protocol := Mutex_Protocol;
294 pragma Assert (L.Mutex /= 0);
301 procedure Finalize_Lock (L : not null access Lock) is
304 Result := semDelete (L.Mutex);
305 pragma Assert (Result = 0);
308 procedure Finalize_Lock (L : not null access RTS_Lock) is
311 Result := semDelete (L.Mutex);
312 pragma Assert (Result = 0);
320 (L : not null access Lock;
321 Ceiling_Violation : out Boolean)
326 if L.Protocol = Prio_Protect
327 and then int (Self.Common.Current_Priority) > L.Prio_Ceiling
329 Ceiling_Violation := True;
332 Ceiling_Violation := False;
335 Result := semTake (L.Mutex, WAIT_FOREVER);
336 pragma Assert (Result = 0);
340 (L : not null access RTS_Lock;
341 Global_Lock : Boolean := False)
345 if not Single_Lock or else Global_Lock then
346 Result := semTake (L.Mutex, WAIT_FOREVER);
347 pragma Assert (Result = 0);
351 procedure Write_Lock (T : Task_Id) is
354 if not Single_Lock then
355 Result := semTake (T.Common.LL.L.Mutex, WAIT_FOREVER);
356 pragma Assert (Result = 0);
365 (L : not null access Lock;
366 Ceiling_Violation : out Boolean)
369 Write_Lock (L, Ceiling_Violation);
376 procedure Unlock (L : not null access Lock) is
379 Result := semGive (L.Mutex);
380 pragma Assert (Result = 0);
384 (L : not null access RTS_Lock;
385 Global_Lock : Boolean := False)
389 if not Single_Lock or else Global_Lock then
390 Result := semGive (L.Mutex);
391 pragma Assert (Result = 0);
395 procedure Unlock (T : Task_Id) is
398 if not Single_Lock then
399 Result := semGive (T.Common.LL.L.Mutex);
400 pragma Assert (Result = 0);
408 -- Dynamic priority ceilings are not supported by the underlying system
410 procedure Set_Ceiling
411 (L : not null access Lock;
412 Prio : System.Any_Priority)
414 pragma Unreferenced (L, Prio);
423 procedure Sleep (Self_ID : Task_Id; Reason : System.Tasking.Task_States) is
424 pragma Unreferenced (Reason);
429 pragma Assert (Self_ID = Self);
431 -- Release the mutex before sleeping
434 semGive (if Single_Lock
435 then Single_RTS_Lock.Mutex
436 else Self_ID.Common.LL.L.Mutex);
437 pragma Assert (Result = 0);
439 -- Perform a blocking operation to take the CV semaphore. Note that a
440 -- blocking operation in VxWorks will reenable task scheduling. When we
441 -- are no longer blocked and control is returned, task scheduling will
442 -- again be disabled.
444 Result := semTake (Self_ID.Common.LL.CV, WAIT_FOREVER);
445 pragma Assert (Result = 0);
447 -- Take the mutex back
450 semTake ((if Single_Lock
451 then Single_RTS_Lock.Mutex
452 else Self_ID.Common.LL.L.Mutex), WAIT_FOREVER);
453 pragma Assert (Result = 0);
460 -- This is for use within the run-time system, so abort is assumed to be
461 -- already deferred, and the caller should be holding its own ATCB lock.
463 procedure Timed_Sleep
466 Mode : ST.Delay_Modes;
467 Reason : System.Tasking.Task_States;
468 Timedout : out Boolean;
469 Yielded : out Boolean)
471 pragma Unreferenced (Reason);
473 Orig : constant Duration := Monotonic_Clock;
477 Wakeup : Boolean := False;
483 if Mode = Relative then
484 Absolute := Orig + Time;
486 -- Systematically add one since the first tick will delay *at most*
487 -- 1 / Rate_Duration seconds, so we need to add one to be on the
490 Ticks := To_Clock_Ticks (Time);
492 if Ticks > 0 and then Ticks < int'Last then
498 Ticks := To_Clock_Ticks (Time - Monotonic_Clock);
503 -- Release the mutex before sleeping
506 semGive (if Single_Lock
507 then Single_RTS_Lock.Mutex
508 else Self_ID.Common.LL.L.Mutex);
509 pragma Assert (Result = 0);
511 -- Perform a blocking operation to take the CV semaphore. Note
512 -- that a blocking operation in VxWorks will reenable task
513 -- scheduling. When we are no longer blocked and control is
514 -- returned, task scheduling will again be disabled.
516 Result := semTake (Self_ID.Common.LL.CV, Ticks);
520 -- Somebody may have called Wakeup for us
525 if errno /= S_objLib_OBJ_TIMEOUT then
529 -- If Ticks = int'last, it was most probably truncated so
530 -- let's make another round after recomputing Ticks from
531 -- the absolute time.
533 if Ticks /= int'Last then
537 Ticks := To_Clock_Ticks (Absolute - Monotonic_Clock);
546 -- Take the mutex back
549 semTake ((if Single_Lock
550 then Single_RTS_Lock.Mutex
551 else Self_ID.Common.LL.L.Mutex), WAIT_FOREVER);
552 pragma Assert (Result = 0);
554 exit when Timedout or Wakeup;
560 -- Should never hold a lock while yielding
563 Result := semGive (Single_RTS_Lock.Mutex);
565 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
568 Result := semGive (Self_ID.Common.LL.L.Mutex);
570 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
579 -- This is for use in implementing delay statements, so we assume the
580 -- caller is holding no locks.
582 procedure Timed_Delay
585 Mode : ST.Delay_Modes)
587 Orig : constant Duration := Monotonic_Clock;
591 Aborted : Boolean := False;
594 pragma Warnings (Off, Result);
597 if Mode = Relative then
598 Absolute := Orig + Time;
599 Ticks := To_Clock_Ticks (Time);
601 if Ticks > 0 and then Ticks < int'Last then
603 -- First tick will delay anytime between 0 and 1 / sysClkRateGet
604 -- seconds, so we need to add one to be on the safe side.
611 Ticks := To_Clock_Ticks (Time - Orig);
616 -- Modifying State, locking the TCB
619 semTake ((if Single_Lock
620 then Single_RTS_Lock.Mutex
621 else Self_ID.Common.LL.L.Mutex), WAIT_FOREVER);
623 pragma Assert (Result = 0);
625 Self_ID.Common.State := Delay_Sleep;
629 Aborted := Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
631 -- Release the TCB before sleeping
634 semGive (if Single_Lock
635 then Single_RTS_Lock.Mutex
636 else Self_ID.Common.LL.L.Mutex);
637 pragma Assert (Result = 0);
641 Result := semTake (Self_ID.Common.LL.CV, Ticks);
645 -- If Ticks = int'last, it was most probably truncated
646 -- so let's make another round after recomputing Ticks
647 -- from the absolute time.
649 if errno = S_objLib_OBJ_TIMEOUT and then Ticks /= int'Last then
652 Ticks := To_Clock_Ticks (Absolute - Monotonic_Clock);
660 -- Take back the lock after having slept, to protect further
661 -- access to Self_ID.
666 then Single_RTS_Lock.Mutex
667 else Self_ID.Common.LL.L.Mutex), WAIT_FOREVER);
669 pragma Assert (Result = 0);
674 Self_ID.Common.State := Runnable;
679 then Single_RTS_Lock.Mutex
680 else Self_ID.Common.LL.L.Mutex);
687 ---------------------
688 -- Monotonic_Clock --
689 ---------------------
691 function Monotonic_Clock return Duration is
692 TS : aliased timespec;
695 Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access);
696 pragma Assert (Result = 0);
697 return To_Duration (TS);
704 function RT_Resolution return Duration is
706 return 1.0 / Duration (sysClkRateGet);
713 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
714 pragma Unreferenced (Reason);
717 Result := semGive (T.Common.LL.CV);
718 pragma Assert (Result = 0);
725 procedure Yield (Do_Yield : Boolean := True) is
726 pragma Unreferenced (Do_Yield);
728 pragma Unreferenced (Result);
730 Result := taskDelay (0);
737 procedure Set_Priority
739 Prio : System.Any_Priority;
740 Loss_Of_Inheritance : Boolean := False)
742 pragma Unreferenced (Loss_Of_Inheritance);
749 (T.Common.LL.Thread, To_VxWorks_Priority (int (Prio)));
750 pragma Assert (Result = 0);
752 -- Note: in VxWorks 6.6 (or earlier), the task is placed at the end of
753 -- the priority queue instead of the head. This is not the behavior
754 -- required by Annex D (RM D.2.3(5/2)), but we consider it an acceptable
755 -- variation (RM 1.1.3(6)), given this is the built-in behavior of the
756 -- operating system. VxWorks versions starting from 6.7 implement the
757 -- required Annex D semantics.
759 -- In older versions we attempted to better approximate the Annex D
760 -- required behavior, but this simulation was not entirely accurate,
761 -- and it seems better to live with the standard VxWorks semantics.
763 T.Common.Current_Priority := Prio;
770 function Get_Priority (T : Task_Id) return System.Any_Priority is
772 return T.Common.Current_Priority;
779 procedure Enter_Task (Self_ID : Task_Id) is
780 procedure Init_Float;
781 pragma Import (C, Init_Float, "__gnat_init_float");
782 -- Properly initializes the FPU for PPC/MIPS systems
785 -- Store the user-level task id in the Thread field (to be used
786 -- internally by the run-time system) and the kernel-level task id in
787 -- the LWP field (to be used by the debugger).
789 Self_ID.Common.LL.Thread := taskIdSelf;
790 Self_ID.Common.LL.LWP := getpid;
792 Specific.Set (Self_ID);
796 -- Install the signal handlers
798 -- This is called for each task since there is no signal inheritance
799 -- between VxWorks tasks.
801 Install_Signal_Handlers;
803 -- If stack checking is enabled, set the stack limit for this task
805 if Set_Stack_Limit_Hook /= null then
806 Set_Stack_Limit_Hook.all;
814 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
816 return new Ada_Task_Control_Block (Entry_Num);
823 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
825 -----------------------------
826 -- Register_Foreign_Thread --
827 -----------------------------
829 function Register_Foreign_Thread return Task_Id is
831 if Is_Valid_Task then
834 return Register_Foreign_Thread (taskIdSelf);
836 end Register_Foreign_Thread;
842 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
844 Self_ID.Common.LL.CV := semBCreate (SEM_Q_PRIORITY, SEM_EMPTY);
845 Self_ID.Common.LL.Thread := 0;
847 if Self_ID.Common.LL.CV = 0 then
853 if not Single_Lock then
854 Initialize_Lock (Self_ID.Common.LL.L'Access, ATCB_Level);
863 procedure Create_Task
865 Wrapper : System.Address;
866 Stack_Size : System.Parameters.Size_Type;
867 Priority : System.Any_Priority;
868 Succeeded : out Boolean)
870 Adjusted_Stack_Size : size_t;
873 use System.Task_Info;
876 -- Ask for four extra bytes of stack space so that the ATCB pointer can
877 -- be stored below the stack limit, plus extra space for the frame of
878 -- Task_Wrapper. This is so the user gets the amount of stack requested
879 -- exclusive of the needs.
881 -- We also have to allocate n more bytes for the task name storage and
882 -- enough space for the Wind Task Control Block which is around 0x778
883 -- bytes. VxWorks also seems to carve out additional space, so use 2048
884 -- as a nice round number. We might want to increment to the nearest
885 -- page size in case we ever support VxVMI.
887 -- ??? - we should come back and visit this so we can set the task name
888 -- to something appropriate.
890 Adjusted_Stack_Size := size_t (Stack_Size) + 2048;
892 -- Since the initial signal mask of a thread is inherited from the
893 -- creator, and the Environment task has all its signals masked, we do
894 -- not need to manipulate caller's signal mask at this point. All tasks
895 -- in RTS will have All_Tasks_Mask initially.
897 -- We now compute the VxWorks task name and options, then spawn ...
900 Name : aliased String (1 .. T.Common.Task_Image_Len + 1);
901 Name_Address : System.Address;
902 -- Task name we are going to hand down to VxWorks
904 function Get_Task_Options return int;
905 pragma Import (C, Get_Task_Options, "__gnat_get_task_options");
906 -- Function that returns the options to be set for the task that we
907 -- are creating. We fetch the options assigned to the current task,
908 -- so offering some user level control over the options for a task
909 -- hierarchy, and force VX_FP_TASK because it is almost always
913 -- If there is no Ada task name handy, let VxWorks choose one.
914 -- Otherwise, tell VxWorks what the Ada task name is.
916 if T.Common.Task_Image_Len = 0 then
917 Name_Address := System.Null_Address;
919 Name (1 .. Name'Last - 1) :=
920 T.Common.Task_Image (1 .. T.Common.Task_Image_Len);
921 Name (Name'Last) := ASCII.NUL;
922 Name_Address := Name'Address;
925 -- Now spawn the VxWorks task for real
927 T.Common.LL.Thread :=
930 To_VxWorks_Priority (int (Priority)),
937 -- Set processor affinity
939 if T.Common.Task_Info /= Unspecified_Task_Info then
941 taskCpuAffinitySet (T.Common.LL.Thread, T.Common.Task_Info);
944 taskDelete (T.Common.LL.Thread);
945 T.Common.LL.Thread := -1;
949 if T.Common.LL.Thread = -1 then
953 Task_Creation_Hook (T.Common.LL.Thread);
954 Set_Priority (T, Priority);
962 procedure Finalize_TCB (T : Task_Id) is
965 Is_Self : constant Boolean := (T = Self);
967 procedure Free is new
968 Ada.Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
971 if not Single_Lock then
972 Result := semDelete (T.Common.LL.L.Mutex);
973 pragma Assert (Result = 0);
976 T.Common.LL.Thread := 0;
978 Result := semDelete (T.Common.LL.CV);
979 pragma Assert (Result = 0);
981 if T.Known_Tasks_Index /= -1 then
982 Known_Tasks (T.Known_Tasks_Index) := null;
996 procedure Exit_Task is
1005 procedure Abort_Task (T : Task_Id) is
1010 (T.Common.LL.Thread,
1011 Signal (Interrupt_Management.Abort_Task_Interrupt));
1012 pragma Assert (Result = 0);
1019 procedure Initialize (S : in out Suspension_Object) is
1021 -- Initialize internal state (always to False (RM D.10(6)))
1026 -- Initialize internal mutex
1028 -- Use simpler binary semaphore instead of VxWorks
1029 -- mutual exclusion semaphore, because we don't need
1030 -- the fancier semantics and their overhead.
1032 S.L := semBCreate (SEM_Q_FIFO, SEM_FULL);
1034 -- Initialize internal condition variable
1036 S.CV := semBCreate (SEM_Q_FIFO, SEM_EMPTY);
1043 procedure Finalize (S : in out Suspension_Object) is
1044 pragma Unmodified (S);
1045 -- S may be modified on other targets, but not on VxWorks
1050 -- Destroy internal mutex
1052 Result := semDelete (S.L);
1053 pragma Assert (Result = OK);
1055 -- Destroy internal condition variable
1057 Result := semDelete (S.CV);
1058 pragma Assert (Result = OK);
1065 function Current_State (S : Suspension_Object) return Boolean is
1067 -- We do not want to use lock on this read operation. State is marked
1068 -- as Atomic so that we ensure that the value retrieved is correct.
1077 procedure Set_False (S : in out Suspension_Object) is
1081 SSL.Abort_Defer.all;
1083 Result := semTake (S.L, WAIT_FOREVER);
1084 pragma Assert (Result = OK);
1088 Result := semGive (S.L);
1089 pragma Assert (Result = OK);
1091 SSL.Abort_Undefer.all;
1098 procedure Set_True (S : in out Suspension_Object) is
1103 -- Set_True can be called from an interrupt context, in which case
1104 -- Abort_Defer is undefined.
1105 if Is_Task_Context then
1106 SSL.Abort_Defer.all;
1109 Result := semTake (S.L, WAIT_FOREVER);
1110 pragma Assert (Result = OK);
1112 -- If there is already a task waiting on this suspension object then
1113 -- we resume it, leaving the state of the suspension object to False,
1114 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1115 -- the state to True.
1121 Result := semGive (S.CV);
1122 pragma Assert (Result = OK);
1127 Result := semGive (S.L);
1128 pragma Assert (Result = OK);
1130 -- Set_True can be called from an interrupt context, in which case
1131 -- Abort_Undefer is undefined.
1132 if Is_Task_Context then
1133 SSL.Abort_Undefer.all;
1138 ------------------------
1139 -- Suspend_Until_True --
1140 ------------------------
1142 procedure Suspend_Until_True (S : in out Suspension_Object) is
1146 SSL.Abort_Defer.all;
1148 Result := semTake (S.L, WAIT_FOREVER);
1152 -- Program_Error must be raised upon calling Suspend_Until_True
1153 -- if another task is already waiting on that suspension object
1154 -- (ARM D.10 par. 10).
1156 Result := semGive (S.L);
1157 pragma Assert (Result = OK);
1159 SSL.Abort_Undefer.all;
1161 raise Program_Error;
1164 -- Suspend the task if the state is False. Otherwise, the task
1165 -- continues its execution, and the state of the suspension object
1166 -- is set to False (ARM D.10 par. 9).
1171 Result := semGive (S.L);
1172 pragma Assert (Result = 0);
1174 SSL.Abort_Undefer.all;
1179 -- Release the mutex before sleeping
1181 Result := semGive (S.L);
1182 pragma Assert (Result = OK);
1184 SSL.Abort_Undefer.all;
1186 Result := semTake (S.CV, WAIT_FOREVER);
1187 pragma Assert (Result = 0);
1190 end Suspend_Until_True;
1198 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1199 pragma Unreferenced (Self_ID);
1204 --------------------
1205 -- Check_No_Locks --
1206 --------------------
1208 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1209 pragma Unreferenced (Self_ID);
1214 ----------------------
1215 -- Environment_Task --
1216 ----------------------
1218 function Environment_Task return Task_Id is
1220 return Environment_Task_Id;
1221 end Environment_Task;
1227 procedure Lock_RTS is
1229 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1236 procedure Unlock_RTS is
1238 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1245 function Suspend_Task
1247 Thread_Self : Thread_Id) return Boolean
1250 if T.Common.LL.Thread /= 0
1251 and then T.Common.LL.Thread /= Thread_Self
1253 return taskSuspend (T.Common.LL.Thread) = 0;
1263 function Resume_Task
1265 Thread_Self : Thread_Id) return Boolean
1268 if T.Common.LL.Thread /= 0
1269 and then T.Common.LL.Thread /= Thread_Self
1271 return taskResume (T.Common.LL.Thread) = 0;
1277 --------------------
1278 -- Stop_All_Tasks --
1279 --------------------
1281 procedure Stop_All_Tasks
1283 Thread_Self : constant Thread_Id := taskIdSelf;
1287 pragma Unreferenced (Dummy);
1292 C := All_Tasks_List;
1293 while C /= null loop
1294 if C.Common.LL.Thread /= 0
1295 and then C.Common.LL.Thread /= Thread_Self
1297 Dummy := Task_Stop (C.Common.LL.Thread);
1300 C := C.Common.All_Tasks_Link;
1303 Dummy := Int_Unlock;
1310 function Stop_Task (T : ST.Task_Id) return Boolean is
1312 if T.Common.LL.Thread /= 0 then
1313 return Task_Stop (T.Common.LL.Thread) = 0;
1323 function Continue_Task (T : ST.Task_Id) return Boolean
1326 if T.Common.LL.Thread /= 0 then
1327 return Task_Cont (T.Common.LL.Thread) = 0;
1333 ---------------------
1334 -- Is_Task_Context --
1335 ---------------------
1337 function Is_Task_Context return Boolean is
1338 function intContext return int;
1339 -- Binding to the C routine intContext. This function returns 1 only
1340 -- if the current execution state is an interrupt context.
1341 pragma Import (C, intContext, "intContext");
1343 return intContext /= 1;
1344 end Is_Task_Context;
1350 procedure Initialize (Environment_Task : Task_Id) is
1354 Environment_Task_Id := Environment_Task;
1356 Interrupt_Management.Initialize;
1357 Specific.Initialize;
1359 if Locking_Policy = 'C' then
1360 Mutex_Protocol := Prio_Protect;
1361 elsif Locking_Policy = 'I' then
1362 Mutex_Protocol := Prio_Inherit;
1364 Mutex_Protocol := Prio_None;
1367 if Time_Slice_Val > 0 then
1371 (Duration (Time_Slice_Val) / Duration (1_000_000.0)));
1373 elsif Dispatching_Policy = 'R' then
1374 Result := Set_Time_Slice (To_Clock_Ticks (0.01));
1378 Result := sigemptyset (Unblocked_Signal_Mask'Access);
1379 pragma Assert (Result = 0);
1381 for J in Interrupt_Management.Signal_ID loop
1382 if System.Interrupt_Management.Keep_Unmasked (J) then
1383 Result := sigaddset (Unblocked_Signal_Mask'Access, Signal (J));
1384 pragma Assert (Result = 0);
1388 -- Initialize the lock used to synchronize chain of all ATCBs
1390 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1392 -- Make environment task known here because it doesn't go through
1393 -- Activate_Tasks, which does it for all other tasks.
1395 Known_Tasks (Known_Tasks'First) := Environment_Task;
1396 Environment_Task.Known_Tasks_Index := Known_Tasks'First;
1398 Enter_Task (Environment_Task);
1401 end System.Task_Primitives.Operations;