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-2008, 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 with
40 -- Turn off polling, we do not want ATC polling to take place during tasking
41 -- operations. It causes infinite loops and other problems.
43 with Ada.Unchecked_Conversion;
44 with Ada.Unchecked_Deallocation;
48 with System.Tasking.Debug;
49 with System.Interrupt_Management;
51 with System.Soft_Links;
52 -- We use System.Soft_Links instead of System.Tasking.Initialization
53 -- because the later is a higher level package that we shouldn't depend
54 -- on. For example when using the restricted run time, it is replaced by
55 -- System.Tasking.Restricted.Stages.
57 with System.VxWorks.Ext;
59 package body System.Task_Primitives.Operations is
61 package SSL renames System.Soft_Links;
63 use System.Tasking.Debug;
65 use System.OS_Interface;
66 use System.Parameters;
67 use type System.VxWorks.Ext.t_id;
68 use type Interfaces.C.int;
70 subtype int is System.OS_Interface.int;
72 Relative : constant := 0;
78 -- The followings are logically constants, but need to be initialized at
81 Single_RTS_Lock : aliased RTS_Lock;
82 -- This is a lock to allow only one thread of control in the RTS at a
83 -- time; it is used to execute in mutual exclusion from all other tasks.
84 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
86 Environment_Task_Id : Task_Id;
87 -- A variable to hold Task_Id for the environment task
89 Unblocked_Signal_Mask : aliased sigset_t;
90 -- The set of signals that should unblocked in all tasks
92 -- The followings are internal configuration constants needed
94 Time_Slice_Val : Integer;
95 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
97 Locking_Policy : Character;
98 pragma Import (C, Locking_Policy, "__gl_locking_policy");
100 Dispatching_Policy : Character;
101 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
103 function Get_Policy (Prio : System.Any_Priority) return Character;
104 pragma Import (C, Get_Policy, "__gnat_get_specific_dispatching");
105 -- Get priority specific dispatching policy
107 Mutex_Protocol : Priority_Type;
109 Foreign_Task_Elaborated : aliased Boolean := True;
110 -- Used to identified fake tasks (i.e., non-Ada Threads)
112 type Set_Stack_Limit_Proc_Acc is access procedure;
113 pragma Convention (C, Set_Stack_Limit_Proc_Acc);
115 Set_Stack_Limit_Hook : Set_Stack_Limit_Proc_Acc;
116 pragma Import (C, Set_Stack_Limit_Hook, "__gnat_set_stack_limit_hook");
117 -- Procedure to be called when a task is created to set stack
126 procedure Initialize;
127 pragma Inline (Initialize);
128 -- Initialize task specific data
130 function Is_Valid_Task return Boolean;
131 pragma Inline (Is_Valid_Task);
132 -- Does executing thread have a TCB?
134 procedure Set (Self_Id : Task_Id);
136 -- Set the self id for the current task
139 pragma Inline (Delete);
140 -- Delete the task specific data associated with the current task
142 function Self return Task_Id;
143 pragma Inline (Self);
144 -- Return a pointer to the Ada Task Control Block of the calling task
148 package body Specific is separate;
149 -- The body of this package is target specific
151 ---------------------------------
152 -- Support for foreign threads --
153 ---------------------------------
155 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
156 -- Allocate and Initialize a new ATCB for the current Thread
158 function Register_Foreign_Thread
159 (Thread : Thread_Id) return Task_Id is separate;
161 -----------------------
162 -- Local Subprograms --
163 -----------------------
165 procedure Abort_Handler (signo : Signal);
166 -- Handler for the abort (SIGABRT) signal to handle asynchronous abort
168 procedure Install_Signal_Handlers;
169 -- Install the default signal handlers for the current task
171 function To_Address is
172 new Ada.Unchecked_Conversion (Task_Id, System.Address);
178 procedure Abort_Handler (signo : Signal) is
179 pragma Unreferenced (signo);
181 Self_ID : constant Task_Id := Self;
182 Old_Set : aliased sigset_t;
185 pragma Warnings (Off, Result);
188 -- It is not safe to raise an exception when using ZCX and the GCC
189 -- exception handling mechanism.
191 if ZCX_By_Default and then GCC_ZCX_Support then
195 if Self_ID.Deferral_Level = 0
196 and then Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
197 and then not Self_ID.Aborting
199 Self_ID.Aborting := True;
201 -- Make sure signals used for RTS internal purpose are unmasked
206 Unblocked_Signal_Mask'Access,
208 pragma Assert (Result = 0);
210 raise Standard'Abort_Signal;
218 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
219 pragma Unreferenced (T);
220 pragma Unreferenced (On);
223 -- Nothing needed (why not???)
232 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
234 return T.Common.LL.Thread;
241 function Self return Task_Id renames Specific.Self;
243 -----------------------------
244 -- Install_Signal_Handlers --
245 -----------------------------
247 procedure Install_Signal_Handlers is
248 act : aliased struct_sigaction;
249 old_act : aliased struct_sigaction;
250 Tmp_Set : aliased sigset_t;
255 act.sa_handler := Abort_Handler'Address;
257 Result := sigemptyset (Tmp_Set'Access);
258 pragma Assert (Result = 0);
259 act.sa_mask := Tmp_Set;
263 (Signal (Interrupt_Management.Abort_Task_Interrupt),
264 act'Unchecked_Access,
265 old_act'Unchecked_Access);
266 pragma Assert (Result = 0);
268 Interrupt_Management.Initialize_Interrupts;
269 end Install_Signal_Handlers;
271 ---------------------
272 -- Initialize_Lock --
273 ---------------------
275 procedure Initialize_Lock
276 (Prio : System.Any_Priority;
277 L : not null access Lock)
280 L.Mutex := semMCreate (SEM_Q_PRIORITY + SEM_INVERSION_SAFE);
281 L.Prio_Ceiling := int (Prio);
282 L.Protocol := Mutex_Protocol;
283 pragma Assert (L.Mutex /= 0);
286 procedure Initialize_Lock
287 (L : not null access RTS_Lock;
290 pragma Unreferenced (Level);
292 L.Mutex := semMCreate (SEM_Q_PRIORITY + SEM_INVERSION_SAFE);
293 L.Prio_Ceiling := int (System.Any_Priority'Last);
294 L.Protocol := Mutex_Protocol;
295 pragma Assert (L.Mutex /= 0);
302 procedure Finalize_Lock (L : not null access Lock) is
305 Result := semDelete (L.Mutex);
306 pragma Assert (Result = 0);
309 procedure Finalize_Lock (L : not null access RTS_Lock) is
312 Result := semDelete (L.Mutex);
313 pragma Assert (Result = 0);
321 (L : not null access Lock;
322 Ceiling_Violation : out Boolean)
327 if L.Protocol = Prio_Protect
328 and then int (Self.Common.Current_Priority) > L.Prio_Ceiling
330 Ceiling_Violation := True;
333 Ceiling_Violation := False;
336 Result := semTake (L.Mutex, WAIT_FOREVER);
337 pragma Assert (Result = 0);
341 (L : not null access RTS_Lock;
342 Global_Lock : Boolean := False)
346 if not Single_Lock or else Global_Lock then
347 Result := semTake (L.Mutex, WAIT_FOREVER);
348 pragma Assert (Result = 0);
352 procedure Write_Lock (T : Task_Id) is
355 if not Single_Lock then
356 Result := semTake (T.Common.LL.L.Mutex, WAIT_FOREVER);
357 pragma Assert (Result = 0);
366 (L : not null access Lock;
367 Ceiling_Violation : out Boolean)
370 Write_Lock (L, Ceiling_Violation);
377 procedure Unlock (L : not null access Lock) is
380 Result := semGive (L.Mutex);
381 pragma Assert (Result = 0);
385 (L : not null access RTS_Lock;
386 Global_Lock : Boolean := False)
390 if not Single_Lock or else Global_Lock then
391 Result := semGive (L.Mutex);
392 pragma Assert (Result = 0);
396 procedure Unlock (T : Task_Id) is
399 if not Single_Lock then
400 Result := semGive (T.Common.LL.L.Mutex);
401 pragma Assert (Result = 0);
409 -- Dynamic priority ceilings are not supported by the underlying system
411 procedure Set_Ceiling
412 (L : not null access Lock;
413 Prio : System.Any_Priority)
415 pragma Unreferenced (L, Prio);
424 procedure Sleep (Self_ID : Task_Id; Reason : System.Tasking.Task_States) is
425 pragma Unreferenced (Reason);
430 pragma Assert (Self_ID = Self);
432 -- Release the mutex before sleeping
435 Result := semGive (Single_RTS_Lock.Mutex);
437 Result := semGive (Self_ID.Common.LL.L.Mutex);
440 pragma Assert (Result = 0);
442 -- Perform a blocking operation to take the CV semaphore. Note that a
443 -- blocking operation in VxWorks will reenable task scheduling. When we
444 -- are no longer blocked and control is returned, task scheduling will
445 -- again be disabled.
447 Result := semTake (Self_ID.Common.LL.CV, WAIT_FOREVER);
448 pragma Assert (Result = 0);
450 -- Take the mutex back
453 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
455 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
458 pragma Assert (Result = 0);
465 -- This is for use within the run-time system, so abort is assumed to be
466 -- already deferred, and the caller should be holding its own ATCB lock.
468 procedure Timed_Sleep
471 Mode : ST.Delay_Modes;
472 Reason : System.Tasking.Task_States;
473 Timedout : out Boolean;
474 Yielded : out Boolean)
476 pragma Unreferenced (Reason);
478 Orig : constant Duration := Monotonic_Clock;
482 Wakeup : Boolean := False;
488 if Mode = Relative then
489 Absolute := Orig + Time;
491 -- Systematically add one since the first tick will delay *at most*
492 -- 1 / Rate_Duration seconds, so we need to add one to be on the
495 Ticks := To_Clock_Ticks (Time);
497 if Ticks > 0 and then Ticks < int'Last then
503 Ticks := To_Clock_Ticks (Time - Monotonic_Clock);
508 -- Release the mutex before sleeping
511 Result := semGive (Single_RTS_Lock.Mutex);
513 Result := semGive (Self_ID.Common.LL.L.Mutex);
516 pragma Assert (Result = 0);
518 -- Perform a blocking operation to take the CV semaphore. Note
519 -- that a blocking operation in VxWorks will reenable task
520 -- scheduling. When we are no longer blocked and control is
521 -- returned, task scheduling will again be disabled.
523 Result := semTake (Self_ID.Common.LL.CV, Ticks);
527 -- Somebody may have called Wakeup for us
532 if errno /= S_objLib_OBJ_TIMEOUT then
536 -- If Ticks = int'last, it was most probably truncated so
537 -- let's make another round after recomputing Ticks from
538 -- the absolute time.
540 if Ticks /= int'Last then
544 Ticks := To_Clock_Ticks (Absolute - Monotonic_Clock);
553 -- Take the mutex back
556 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
558 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
561 pragma Assert (Result = 0);
563 exit when Timedout or Wakeup;
569 -- Should never hold a lock while yielding
572 Result := semGive (Single_RTS_Lock.Mutex);
574 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
577 Result := semGive (Self_ID.Common.LL.L.Mutex);
579 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
588 -- This is for use in implementing delay statements, so we assume the
589 -- caller is holding no locks.
591 procedure Timed_Delay
594 Mode : ST.Delay_Modes)
596 Orig : constant Duration := Monotonic_Clock;
600 Aborted : Boolean := False;
603 pragma Warnings (Off, Result);
606 if Mode = Relative then
607 Absolute := Orig + Time;
608 Ticks := To_Clock_Ticks (Time);
610 if Ticks > 0 and then Ticks < int'Last then
612 -- First tick will delay anytime between 0 and 1 / sysClkRateGet
613 -- seconds, so we need to add one to be on the safe side.
620 Ticks := To_Clock_Ticks (Time - Orig);
625 -- Modifying State, locking the TCB
628 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
630 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
633 pragma Assert (Result = 0);
635 Self_ID.Common.State := Delay_Sleep;
639 Aborted := Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level;
641 -- Release the TCB before sleeping
644 Result := semGive (Single_RTS_Lock.Mutex);
646 Result := semGive (Self_ID.Common.LL.L.Mutex);
648 pragma Assert (Result = 0);
652 Result := semTake (Self_ID.Common.LL.CV, Ticks);
656 -- If Ticks = int'last, it was most probably truncated
657 -- so let's make another round after recomputing Ticks
658 -- from the absolute time.
660 if errno = S_objLib_OBJ_TIMEOUT and then Ticks /= int'Last then
663 Ticks := To_Clock_Ticks (Absolute - Monotonic_Clock);
671 -- Take back the lock after having slept, to protect further
672 -- access to Self_ID.
675 Result := semTake (Single_RTS_Lock.Mutex, WAIT_FOREVER);
677 Result := semTake (Self_ID.Common.LL.L.Mutex, WAIT_FOREVER);
680 pragma Assert (Result = 0);
685 Self_ID.Common.State := Runnable;
688 Result := semGive (Single_RTS_Lock.Mutex);
690 Result := semGive (Self_ID.Common.LL.L.Mutex);
698 ---------------------
699 -- Monotonic_Clock --
700 ---------------------
702 function Monotonic_Clock return Duration is
703 TS : aliased timespec;
706 Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access);
707 pragma Assert (Result = 0);
708 return To_Duration (TS);
715 function RT_Resolution return Duration is
717 return 1.0 / Duration (sysClkRateGet);
724 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
725 pragma Unreferenced (Reason);
728 Result := semGive (T.Common.LL.CV);
729 pragma Assert (Result = 0);
736 procedure Yield (Do_Yield : Boolean := True) is
737 pragma Unreferenced (Do_Yield);
739 pragma Unreferenced (Result);
741 Result := taskDelay (0);
748 type Prio_Array_Type is array (System.Any_Priority) of Integer;
749 pragma Atomic_Components (Prio_Array_Type);
751 Prio_Array : Prio_Array_Type;
752 -- Global array containing the id of the currently running task for each
753 -- priority. Note that we assume that we are on a single processor with
754 -- run-till-blocked scheduling.
756 procedure Set_Priority
758 Prio : System.Any_Priority;
759 Loss_Of_Inheritance : Boolean := False)
761 Array_Item : Integer;
767 (T.Common.LL.Thread, To_VxWorks_Priority (int (Prio)));
768 pragma Assert (Result = 0);
770 if (Dispatching_Policy = 'F' or else Get_Policy (Prio) = 'F')
771 and then Loss_Of_Inheritance
772 and then Prio < T.Common.Current_Priority
774 -- Annex D requirement (RM D.2.2(9)):
776 -- If the task drops its priority due to the loss of inherited
777 -- priority, it is added at the head of the ready queue for its
778 -- new active priority.
780 Array_Item := Prio_Array (T.Common.Base_Priority) + 1;
781 Prio_Array (T.Common.Base_Priority) := Array_Item;
784 -- Give some processes a chance to arrive
788 -- Then wait for our turn to proceed
790 exit when Array_Item = Prio_Array (T.Common.Base_Priority)
791 or else Prio_Array (T.Common.Base_Priority) = 1;
794 Prio_Array (T.Common.Base_Priority) :=
795 Prio_Array (T.Common.Base_Priority) - 1;
798 T.Common.Current_Priority := Prio;
805 function Get_Priority (T : Task_Id) return System.Any_Priority is
807 return T.Common.Current_Priority;
814 procedure Enter_Task (Self_ID : Task_Id) is
815 procedure Init_Float;
816 pragma Import (C, Init_Float, "__gnat_init_float");
817 -- Properly initializes the FPU for PPC/MIPS systems
820 -- Store the user-level task id in the Thread field (to be used
821 -- internally by the run-time system) and the kernel-level task id in
822 -- the LWP field (to be used by the debugger).
824 Self_ID.Common.LL.Thread := taskIdSelf;
825 Self_ID.Common.LL.LWP := getpid;
827 Specific.Set (Self_ID);
831 -- Install the signal handlers
833 -- This is called for each task since there is no signal inheritance
834 -- between VxWorks tasks.
836 Install_Signal_Handlers;
840 for J in Known_Tasks'Range loop
841 if Known_Tasks (J) = null then
842 Known_Tasks (J) := Self_ID;
843 Self_ID.Known_Tasks_Index := J;
850 -- If stack checking is enabled, set the stack limit for this task
852 if Set_Stack_Limit_Hook /= null then
853 Set_Stack_Limit_Hook.all;
861 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
863 return new Ada_Task_Control_Block (Entry_Num);
870 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
872 -----------------------------
873 -- Register_Foreign_Thread --
874 -----------------------------
876 function Register_Foreign_Thread return Task_Id is
878 if Is_Valid_Task then
881 return Register_Foreign_Thread (taskIdSelf);
883 end Register_Foreign_Thread;
889 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
891 Self_ID.Common.LL.CV := semBCreate (SEM_Q_PRIORITY, SEM_EMPTY);
892 Self_ID.Common.LL.Thread := 0;
894 if Self_ID.Common.LL.CV = 0 then
900 if not Single_Lock then
901 Initialize_Lock (Self_ID.Common.LL.L'Access, ATCB_Level);
910 procedure Create_Task
912 Wrapper : System.Address;
913 Stack_Size : System.Parameters.Size_Type;
914 Priority : System.Any_Priority;
915 Succeeded : out Boolean)
917 Adjusted_Stack_Size : size_t;
919 -- Ask for four extra bytes of stack space so that the ATCB pointer can
920 -- be stored below the stack limit, plus extra space for the frame of
921 -- Task_Wrapper. This is so the user gets the amount of stack requested
922 -- exclusive of the needs.
924 -- We also have to allocate n more bytes for the task name storage and
925 -- enough space for the Wind Task Control Block which is around 0x778
926 -- bytes. VxWorks also seems to carve out additional space, so use 2048
927 -- as a nice round number. We might want to increment to the nearest
928 -- page size in case we ever support VxVMI.
930 -- ??? - we should come back and visit this so we can set the task name
931 -- to something appropriate.
933 Adjusted_Stack_Size := size_t (Stack_Size) + 2048;
935 -- Since the initial signal mask of a thread is inherited from the
936 -- creator, and the Environment task has all its signals masked, we do
937 -- not need to manipulate caller's signal mask at this point. All tasks
938 -- in RTS will have All_Tasks_Mask initially.
940 -- We now compute the VxWorks task name and options, then spawn ...
943 Name : aliased String (1 .. T.Common.Task_Image_Len + 1);
944 Name_Address : System.Address;
945 -- Task name we are going to hand down to VxWorks
947 function Get_Task_Options return int;
948 pragma Import (C, Get_Task_Options, "__gnat_get_task_options");
949 -- Function that returns the options to be set for the task that we
950 -- are creating. We fetch the options assigned to the current task,
951 -- so offering some user level control over the options for a task
952 -- hierarchy, and force VX_FP_TASK because it is almost always
956 -- If there is no Ada task name handy, let VxWorks choose one.
957 -- Otherwise, tell VxWorks what the Ada task name is.
959 if T.Common.Task_Image_Len = 0 then
960 Name_Address := System.Null_Address;
962 Name (1 .. Name'Last - 1) :=
963 T.Common.Task_Image (1 .. T.Common.Task_Image_Len);
964 Name (Name'Last) := ASCII.NUL;
965 Name_Address := Name'Address;
968 -- Now spawn the VxWorks task for real
970 T.Common.LL.Thread :=
973 To_VxWorks_Priority (int (Priority)),
980 if T.Common.LL.Thread = -1 then
984 Task_Creation_Hook (T.Common.LL.Thread);
985 Set_Priority (T, Priority);
993 procedure Finalize_TCB (T : Task_Id) is
996 Is_Self : constant Boolean := (T = Self);
998 procedure Free is new
999 Ada.Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
1002 if not Single_Lock then
1003 Result := semDelete (T.Common.LL.L.Mutex);
1004 pragma Assert (Result = 0);
1007 T.Common.LL.Thread := 0;
1009 Result := semDelete (T.Common.LL.CV);
1010 pragma Assert (Result = 0);
1012 if T.Known_Tasks_Index /= -1 then
1013 Known_Tasks (T.Known_Tasks_Index) := null;
1027 procedure Exit_Task is
1029 Specific.Set (null);
1036 procedure Abort_Task (T : Task_Id) is
1041 (T.Common.LL.Thread,
1042 Signal (Interrupt_Management.Abort_Task_Interrupt));
1043 pragma Assert (Result = 0);
1050 procedure Initialize (S : in out Suspension_Object) is
1052 -- Initialize internal state (always to False (RM D.10(6)))
1057 -- Initialize internal mutex
1059 -- Use simpler binary semaphore instead of VxWorks
1060 -- mutual exclusion semaphore, because we don't need
1061 -- the fancier semantics and their overhead.
1063 S.L := semBCreate (SEM_Q_FIFO, SEM_FULL);
1065 -- Initialize internal condition variable
1067 S.CV := semBCreate (SEM_Q_FIFO, SEM_EMPTY);
1074 procedure Finalize (S : in out Suspension_Object) is
1075 pragma Unmodified (S);
1076 -- S may be modified on other targets, but not on VxWorks
1081 -- Destroy internal mutex
1083 Result := semDelete (S.L);
1084 pragma Assert (Result = OK);
1086 -- Destroy internal condition variable
1088 Result := semDelete (S.CV);
1089 pragma Assert (Result = OK);
1096 function Current_State (S : Suspension_Object) return Boolean is
1098 -- We do not want to use lock on this read operation. State is marked
1099 -- as Atomic so that we ensure that the value retrieved is correct.
1108 procedure Set_False (S : in out Suspension_Object) is
1112 SSL.Abort_Defer.all;
1114 Result := semTake (S.L, WAIT_FOREVER);
1115 pragma Assert (Result = OK);
1119 Result := semGive (S.L);
1120 pragma Assert (Result = OK);
1122 SSL.Abort_Undefer.all;
1129 procedure Set_True (S : in out Suspension_Object) is
1133 SSL.Abort_Defer.all;
1135 Result := semTake (S.L, WAIT_FOREVER);
1136 pragma Assert (Result = OK);
1138 -- If there is already a task waiting on this suspension object then
1139 -- we resume it, leaving the state of the suspension object to False,
1140 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1141 -- the state to True.
1147 Result := semGive (S.CV);
1148 pragma Assert (Result = OK);
1153 Result := semGive (S.L);
1154 pragma Assert (Result = OK);
1156 SSL.Abort_Undefer.all;
1159 ------------------------
1160 -- Suspend_Until_True --
1161 ------------------------
1163 procedure Suspend_Until_True (S : in out Suspension_Object) is
1167 SSL.Abort_Defer.all;
1169 Result := semTake (S.L, WAIT_FOREVER);
1173 -- Program_Error must be raised upon calling Suspend_Until_True
1174 -- if another task is already waiting on that suspension object
1175 -- (ARM D.10 par. 10).
1177 Result := semGive (S.L);
1178 pragma Assert (Result = OK);
1180 SSL.Abort_Undefer.all;
1182 raise Program_Error;
1185 -- Suspend the task if the state is False. Otherwise, the task
1186 -- continues its execution, and the state of the suspension object
1187 -- is set to False (ARM D.10 par. 9).
1192 Result := semGive (S.L);
1193 pragma Assert (Result = 0);
1195 SSL.Abort_Undefer.all;
1200 -- Release the mutex before sleeping
1202 Result := semGive (S.L);
1203 pragma Assert (Result = OK);
1205 SSL.Abort_Undefer.all;
1207 Result := semTake (S.CV, WAIT_FOREVER);
1208 pragma Assert (Result = 0);
1211 end Suspend_Until_True;
1219 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1220 pragma Unreferenced (Self_ID);
1225 --------------------
1226 -- Check_No_Locks --
1227 --------------------
1229 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1230 pragma Unreferenced (Self_ID);
1235 ----------------------
1236 -- Environment_Task --
1237 ----------------------
1239 function Environment_Task return Task_Id is
1241 return Environment_Task_Id;
1242 end Environment_Task;
1248 procedure Lock_RTS is
1250 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1257 procedure Unlock_RTS is
1259 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1266 function Suspend_Task
1268 Thread_Self : Thread_Id) return Boolean
1271 if T.Common.LL.Thread /= 0
1272 and then T.Common.LL.Thread /= Thread_Self
1274 return taskSuspend (T.Common.LL.Thread) = 0;
1284 function Resume_Task
1286 Thread_Self : Thread_Id) return Boolean
1289 if T.Common.LL.Thread /= 0
1290 and then T.Common.LL.Thread /= Thread_Self
1292 return taskResume (T.Common.LL.Thread) = 0;
1298 --------------------
1299 -- Stop_All_Tasks --
1300 --------------------
1302 procedure Stop_All_Tasks
1304 Thread_Self : constant Thread_Id := taskIdSelf;
1308 pragma Unreferenced (Dummy);
1313 C := All_Tasks_List;
1314 while C /= null loop
1315 if C.Common.LL.Thread /= 0
1316 and then C.Common.LL.Thread /= Thread_Self
1318 Dummy := Task_Stop (C.Common.LL.Thread);
1321 C := C.Common.All_Tasks_Link;
1324 Dummy := Int_Unlock;
1331 function Stop_Task (T : ST.Task_Id) return Boolean is
1333 if T.Common.LL.Thread /= 0 then
1334 return Task_Stop (T.Common.LL.Thread) = 0;
1344 function Continue_Task (T : ST.Task_Id) return Boolean
1347 if T.Common.LL.Thread /= 0 then
1348 return Task_Cont (T.Common.LL.Thread) = 0;
1358 procedure Initialize (Environment_Task : Task_Id) is
1362 Environment_Task_Id := Environment_Task;
1364 Interrupt_Management.Initialize;
1365 Specific.Initialize;
1367 if Locking_Policy = 'C' then
1368 Mutex_Protocol := Prio_Protect;
1369 elsif Locking_Policy = 'I' then
1370 Mutex_Protocol := Prio_Inherit;
1372 Mutex_Protocol := Prio_None;
1375 if Time_Slice_Val > 0 then
1379 (Duration (Time_Slice_Val) / Duration (1_000_000.0)));
1381 elsif Dispatching_Policy = 'R' then
1382 Result := Set_Time_Slice (To_Clock_Ticks (0.01));
1386 Result := sigemptyset (Unblocked_Signal_Mask'Access);
1387 pragma Assert (Result = 0);
1389 for J in Interrupt_Management.Signal_ID loop
1390 if System.Interrupt_Management.Keep_Unmasked (J) then
1391 Result := sigaddset (Unblocked_Signal_Mask'Access, Signal (J));
1392 pragma Assert (Result = 0);
1396 -- Initialize the lock used to synchronize chain of all ATCBs
1398 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1400 Enter_Task (Environment_Task);
1403 end System.Task_Primitives.Operations;