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 a OpenVMS/Alpha 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.OS_Primitives;
47 -- used for Delay_Modes
53 with System.Soft_Links;
54 -- used for Get_Exc_Stack_Addr
55 -- Abort_Defer/Undefer
57 with Unchecked_Conversion;
58 with Unchecked_Deallocation;
60 package body System.Task_Primitives.Operations is
62 use System.Tasking.Debug;
65 use System.OS_Interface;
66 use System.Parameters;
67 use System.OS_Primitives;
68 use type System.OS_Primitives.OS_Time;
70 package SSL renames System.Soft_Links;
76 -- The followings are logically constants, but need to be initialized
79 Single_RTS_Lock : aliased RTS_Lock;
80 -- This is a lock to allow only one thread of control in the RTS at
81 -- a 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 ATCB_Key : aliased pthread_key_t;
85 -- Key used to find the Ada Task_Id associated with a thread
87 Environment_Task_Id : Task_Id;
88 -- A variable to hold Task_Id for the environment task.
90 Time_Slice_Val : Integer;
91 pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
93 Dispatching_Policy : Character;
94 pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
96 Foreign_Task_Elaborated : aliased Boolean := True;
97 -- Used to identified fake tasks (i.e., non-Ada Threads).
105 procedure Initialize (Environment_Task : Task_Id);
106 pragma Inline (Initialize);
107 -- Initialize various data needed by this package.
109 function Is_Valid_Task return Boolean;
110 pragma Inline (Is_Valid_Task);
111 -- Does executing thread have a TCB?
113 procedure Set (Self_Id : Task_Id);
115 -- Set the self id for the current task
117 function Self return Task_Id;
118 pragma Inline (Self);
119 -- Return a pointer to the Ada Task Control Block of the calling task
123 package body Specific is separate;
124 -- The body of this package is target specific.
126 ---------------------------------
127 -- Support for foreign threads --
128 ---------------------------------
130 function Register_Foreign_Thread (Thread : Thread_Id) return Task_Id;
131 -- Allocate and Initialize a new ATCB for the current Thread
133 function Register_Foreign_Thread
134 (Thread : Thread_Id) return Task_Id is separate;
136 -----------------------
137 -- Local Subprograms --
138 -----------------------
140 function To_Task_Id is new Unchecked_Conversion (System.Address, Task_Id);
142 function To_Address is new Unchecked_Conversion (Task_Id, System.Address);
144 function Get_Exc_Stack_Addr return Address;
145 -- Replace System.Soft_Links.Get_Exc_Stack_Addr_NT
147 procedure Timer_Sleep_AST (ID : Address);
148 -- Signal the condition variable when AST fires.
150 procedure Timer_Sleep_AST (ID : Address) is
151 Result : Interfaces.C.int;
152 Self_ID : constant Task_Id := To_Task_Id (ID);
154 Self_ID.Common.LL.AST_Pending := False;
155 Result := pthread_cond_signal_int_np (Self_ID.Common.LL.CV'Access);
156 pragma Assert (Result = 0);
163 -- The underlying thread system sets a guard page at the
164 -- bottom of a thread stack, so nothing is needed.
165 -- ??? Check the comment above
167 procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
168 pragma Unreferenced (T);
169 pragma Unreferenced (On);
178 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
180 return T.Common.LL.Thread;
187 function Self return Task_Id renames Specific.Self;
189 ---------------------
190 -- Initialize_Lock --
191 ---------------------
193 -- Note: mutexes and cond_variables needed per-task basis are
194 -- initialized in Initialize_TCB and the Storage_Error is
195 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
196 -- used in RTS is initialized before any status change of RTS.
197 -- Therefore rasing Storage_Error in the following routines
198 -- should be able to be handled safely.
200 procedure Initialize_Lock (Prio : System.Any_Priority; L : access Lock) is
201 Attributes : aliased pthread_mutexattr_t;
202 Result : Interfaces.C.int;
205 Result := pthread_mutexattr_init (Attributes'Access);
206 pragma Assert (Result = 0 or else Result = ENOMEM);
208 if Result = ENOMEM then
213 L.Prio := Interfaces.C.int (Prio);
215 Result := pthread_mutex_init (L.L'Access, Attributes'Access);
216 pragma Assert (Result = 0 or else Result = ENOMEM);
218 if Result = ENOMEM then
222 Result := pthread_mutexattr_destroy (Attributes'Access);
223 pragma Assert (Result = 0);
226 procedure Initialize_Lock (L : access RTS_Lock; Level : Lock_Level) is
227 pragma Unreferenced (Level);
229 Attributes : aliased pthread_mutexattr_t;
230 Result : Interfaces.C.int;
233 Result := pthread_mutexattr_init (Attributes'Access);
234 pragma Assert (Result = 0 or else Result = ENOMEM);
236 if Result = ENOMEM then
240 -- Don't use, see comment in s-osinte.ads about ERRORCHECK mutexes???
241 -- Result := pthread_mutexattr_settype_np
242 -- (Attributes'Access, PTHREAD_MUTEX_ERRORCHECK_NP);
243 -- pragma Assert (Result = 0);
245 -- Result := pthread_mutexattr_setprotocol
246 -- (Attributes'Access, PTHREAD_PRIO_PROTECT);
247 -- pragma Assert (Result = 0);
249 -- Result := pthread_mutexattr_setprioceiling
250 -- (Attributes'Access, Interfaces.C.int (System.Any_Priority'Last));
251 -- pragma Assert (Result = 0);
253 Result := pthread_mutex_init (L, Attributes'Access);
255 pragma Assert (Result = 0 or else Result = ENOMEM);
257 if Result = ENOMEM then
261 Result := pthread_mutexattr_destroy (Attributes'Access);
262 pragma Assert (Result = 0);
269 procedure Finalize_Lock (L : access Lock) is
270 Result : Interfaces.C.int;
272 Result := pthread_mutex_destroy (L.L'Access);
273 pragma Assert (Result = 0);
276 procedure Finalize_Lock (L : access RTS_Lock) is
277 Result : Interfaces.C.int;
279 Result := pthread_mutex_destroy (L);
280 pragma Assert (Result = 0);
287 procedure Write_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
288 Self_ID : constant Task_Id := Self;
289 All_Tasks_Link : constant Task_Id := Self.Common.All_Tasks_Link;
290 Current_Prio : System.Any_Priority;
291 Result : Interfaces.C.int;
294 Current_Prio := Get_Priority (Self_ID);
296 -- If there is no other tasks, no need to check priorities
298 if All_Tasks_Link /= Null_Task
299 and then L.Prio < Interfaces.C.int (Current_Prio)
301 Ceiling_Violation := True;
305 Result := pthread_mutex_lock (L.L'Access);
306 pragma Assert (Result = 0);
308 Ceiling_Violation := False;
309 -- Why is this commented out ???
310 -- L.Prio_Save := Interfaces.C.int (Current_Prio);
311 -- Set_Priority (Self_ID, System.Any_Priority (L.Prio));
315 (L : access RTS_Lock;
316 Global_Lock : Boolean := False)
318 Result : Interfaces.C.int;
320 if not Single_Lock or else Global_Lock then
321 Result := pthread_mutex_lock (L);
322 pragma Assert (Result = 0);
326 procedure Write_Lock (T : Task_Id) is
327 Result : Interfaces.C.int;
329 if not Single_Lock then
330 Result := pthread_mutex_lock (T.Common.LL.L'Access);
331 pragma Assert (Result = 0);
339 procedure Read_Lock (L : access Lock; Ceiling_Violation : out Boolean) is
341 Write_Lock (L, Ceiling_Violation);
348 procedure Unlock (L : access Lock) is
349 Result : Interfaces.C.int;
351 Result := pthread_mutex_unlock (L.L'Access);
352 pragma Assert (Result = 0);
355 procedure Unlock (L : access RTS_Lock; Global_Lock : Boolean := False) is
356 Result : Interfaces.C.int;
358 if not Single_Lock or else Global_Lock then
359 Result := pthread_mutex_unlock (L);
360 pragma Assert (Result = 0);
364 procedure Unlock (T : Task_Id) is
365 Result : Interfaces.C.int;
367 if not Single_Lock then
368 Result := pthread_mutex_unlock (T.Common.LL.L'Access);
369 pragma Assert (Result = 0);
379 Reason : System.Tasking.Task_States)
381 pragma Unreferenced (Reason);
382 Result : Interfaces.C.int;
386 Result := pthread_cond_wait
387 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
389 Result := pthread_cond_wait
390 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
393 -- EINTR is not considered a failure
395 pragma Assert (Result = 0 or else Result = EINTR);
397 if Self_ID.Deferral_Level = 0
398 and then Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
401 raise Standard'Abort_Signal;
409 procedure Timed_Sleep
412 Mode : ST.Delay_Modes;
413 Reason : System.Tasking.Task_States;
414 Timedout : out Boolean;
415 Yielded : out Boolean)
417 pragma Unreferenced (Reason);
419 Sleep_Time : OS_Time;
420 Result : Interfaces.C.int;
421 Status : Cond_Value_Type;
423 -- The body below requires more comments ???
429 Sleep_Time := To_OS_Time (Time, Mode);
431 if Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
432 or else Self_ID.Pending_Priority_Change
437 Self_ID.Common.LL.AST_Pending := True;
440 (Status, 0, Sleep_Time,
441 Timer_Sleep_AST'Access, To_Address (Self_ID), 0);
443 if (Status and 1) /= 1 then
448 Result := pthread_cond_wait
449 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
450 pragma Assert (Result = 0);
453 Result := pthread_cond_wait
454 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
455 pragma Assert (Result = 0);
460 if not Self_ID.Common.LL.AST_Pending then
463 Sys_Cantim (Status, To_Address (Self_ID), 0);
464 pragma Assert ((Status and 1) = 1);
472 procedure Timed_Delay
475 Mode : ST.Delay_Modes)
477 Sleep_Time : OS_Time;
478 Result : Interfaces.C.int;
479 Status : Cond_Value_Type;
480 Yielded : Boolean := False;
487 -- More comments required in body below ???
489 Write_Lock (Self_ID);
491 if Time /= 0.0 or else Mode /= Relative then
492 Sleep_Time := To_OS_Time (Time, Mode);
494 if Mode = Relative or else OS_Clock < Sleep_Time then
495 Self_ID.Common.State := Delay_Sleep;
496 Self_ID.Common.LL.AST_Pending := True;
499 (Status, 0, Sleep_Time,
500 Timer_Sleep_AST'Access, To_Address (Self_ID), 0);
502 if (Status and 1) /= 1 then
507 if Self_ID.Pending_Priority_Change then
508 Self_ID.Pending_Priority_Change := False;
509 Self_ID.Common.Base_Priority := Self_ID.New_Base_Priority;
510 Set_Priority (Self_ID, Self_ID.Common.Base_Priority);
513 if Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level then
514 Sys_Cantim (Status, To_Address (Self_ID), 0);
515 pragma Assert ((Status and 1) = 1);
520 Result := pthread_cond_wait
521 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
522 pragma Assert (Result = 0);
524 Result := pthread_cond_wait
525 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
526 pragma Assert (Result = 0);
531 exit when not Self_ID.Common.LL.AST_Pending;
534 Self_ID.Common.State := Runnable;
545 Result := sched_yield;
546 pragma Assert (Result = 0);
550 ---------------------
551 -- Monotonic_Clock --
552 ---------------------
554 function Monotonic_Clock return Duration
555 renames System.OS_Primitives.Monotonic_Clock;
561 function RT_Resolution return Duration is
570 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
571 pragma Unreferenced (Reason);
572 Result : Interfaces.C.int;
574 Result := pthread_cond_signal (T.Common.LL.CV'Access);
575 pragma Assert (Result = 0);
582 procedure Yield (Do_Yield : Boolean := True) is
583 Result : Interfaces.C.int;
584 pragma Unreferenced (Result);
587 Result := sched_yield;
595 procedure Set_Priority
597 Prio : System.Any_Priority;
598 Loss_Of_Inheritance : Boolean := False)
600 pragma Unreferenced (Loss_Of_Inheritance);
602 Result : Interfaces.C.int;
603 Param : aliased struct_sched_param;
606 T.Common.Current_Priority := Prio;
607 Param.sched_priority := Interfaces.C.int (Underlying_Priorities (Prio));
609 if Time_Slice_Val > 0 then
610 Result := pthread_setschedparam
611 (T.Common.LL.Thread, SCHED_RR, Param'Access);
613 elsif Dispatching_Policy = 'F' or else Time_Slice_Val = 0 then
614 Result := pthread_setschedparam
615 (T.Common.LL.Thread, SCHED_FIFO, Param'Access);
618 -- SCHED_OTHER priorities are restricted to the range 8 - 15.
619 -- Since the translation from Underlying priorities results
620 -- in a range of 16 - 31, dividing by 2 gives the correct result.
622 Param.sched_priority := Param.sched_priority / 2;
623 Result := pthread_setschedparam
624 (T.Common.LL.Thread, SCHED_OTHER, Param'Access);
627 pragma Assert (Result = 0);
634 function Get_Priority (T : Task_Id) return System.Any_Priority is
636 return T.Common.Current_Priority;
643 procedure Enter_Task (Self_ID : Task_Id) is
645 Self_ID.Common.LL.Thread := pthread_self;
647 Specific.Set (Self_ID);
651 for J in Known_Tasks'Range loop
652 if Known_Tasks (J) = null then
653 Known_Tasks (J) := Self_ID;
654 Self_ID.Known_Tasks_Index := J;
666 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
668 return new Ada_Task_Control_Block (Entry_Num);
675 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
677 -----------------------------
678 -- Register_Foreign_Thread --
679 -----------------------------
681 function Register_Foreign_Thread return Task_Id is
683 if Is_Valid_Task then
686 return Register_Foreign_Thread (pthread_self);
688 end Register_Foreign_Thread;
694 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
695 Mutex_Attr : aliased pthread_mutexattr_t;
696 Result : Interfaces.C.int;
697 Cond_Attr : aliased pthread_condattr_t;
700 -- More comments required in body below ???
702 if not Single_Lock then
703 Result := pthread_mutexattr_init (Mutex_Attr'Access);
704 pragma Assert (Result = 0 or else Result = ENOMEM);
707 Result := pthread_mutex_init (Self_ID.Common.LL.L'Access,
709 pragma Assert (Result = 0 or else Result = ENOMEM);
717 Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
718 pragma Assert (Result = 0);
721 Result := pthread_condattr_init (Cond_Attr'Access);
722 pragma Assert (Result = 0 or else Result = ENOMEM);
725 Result := pthread_cond_init (Self_ID.Common.LL.CV'Access,
727 pragma Assert (Result = 0 or else Result = ENOMEM);
732 Self_ID.Common.LL.Exc_Stack_Ptr := new Exc_Stack_T;
735 if not Single_Lock then
736 Result := pthread_mutex_destroy (Self_ID.Common.LL.L'Access);
737 pragma Assert (Result = 0);
743 Result := pthread_condattr_destroy (Cond_Attr'Access);
744 pragma Assert (Result = 0);
747 ------------------------
748 -- Get_Exc_Stack_Addr --
749 ------------------------
751 function Get_Exc_Stack_Addr return Address is
753 return Self.Common.LL.Exc_Stack_Ptr (Exc_Stack_T'Last)'Address;
754 end Get_Exc_Stack_Addr;
760 procedure Create_Task
762 Wrapper : System.Address;
763 Stack_Size : System.Parameters.Size_Type;
764 Priority : System.Any_Priority;
765 Succeeded : out Boolean)
767 Attributes : aliased pthread_attr_t;
768 Result : Interfaces.C.int;
770 function Thread_Body_Access is new
771 Unchecked_Conversion (System.Address, Thread_Body);
774 -- Since the initial signal mask of a thread is inherited from the
775 -- creator, we need to set our local signal mask mask all signals
776 -- during the creation operation, to make sure the new thread is
777 -- not disturbed by signals before it has set its own Task_Id.
779 Result := pthread_attr_init (Attributes'Access);
780 pragma Assert (Result = 0 or else Result = ENOMEM);
787 Result := pthread_attr_setdetachstate
788 (Attributes'Access, PTHREAD_CREATE_DETACHED);
789 pragma Assert (Result = 0);
791 Result := pthread_attr_setstacksize
792 (Attributes'Access, Interfaces.C.size_t (Stack_Size));
793 pragma Assert (Result = 0);
795 -- This call may be unnecessary, not sure. ???
798 pthread_attr_setinheritsched
799 (Attributes'Access, PTHREAD_EXPLICIT_SCHED);
800 pragma Assert (Result = 0);
802 Result := pthread_create
803 (T.Common.LL.Thread'Access,
805 Thread_Body_Access (Wrapper),
808 -- ENOMEM is a valid run-time error. Don't shut down.
810 pragma Assert (Result = 0
811 or else Result = EAGAIN or else Result = ENOMEM);
813 Succeeded := Result = 0;
815 Result := pthread_attr_destroy (Attributes'Access);
816 pragma Assert (Result = 0);
819 Set_Priority (T, Priority);
827 procedure Finalize_TCB (T : Task_Id) is
828 Result : Interfaces.C.int;
830 Is_Self : constant Boolean := T = Self;
832 procedure Free is new
833 Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
835 procedure Free is new Unchecked_Deallocation
836 (Exc_Stack_T, Exc_Stack_Ptr_T);
839 if not Single_Lock then
840 Result := pthread_mutex_destroy (T.Common.LL.L'Access);
841 pragma Assert (Result = 0);
844 Result := pthread_cond_destroy (T.Common.LL.CV'Access);
845 pragma Assert (Result = 0);
847 if T.Known_Tasks_Index /= -1 then
848 Known_Tasks (T.Known_Tasks_Index) := null;
851 Free (T.Common.LL.Exc_Stack_Ptr);
864 procedure Exit_Task is
873 procedure Abort_Task (T : Task_Id) is
875 -- Interrupt Server_Tasks may be waiting on an event flag
877 if T.Common.State = Interrupt_Server_Blocked_On_Event_Flag then
878 Wakeup (T, Interrupt_Server_Blocked_On_Event_Flag);
886 procedure Initialize (S : in out Suspension_Object) is
887 Mutex_Attr : aliased pthread_mutexattr_t;
888 Cond_Attr : aliased pthread_condattr_t;
889 Result : Interfaces.C.int;
891 -- Initialize internal state. It is always initialized to False (ARM
897 -- Initialize internal mutex
899 Result := pthread_mutexattr_init (Mutex_Attr'Access);
900 pragma Assert (Result = 0 or else Result = ENOMEM);
902 if Result = ENOMEM then
906 Result := pthread_mutex_init (S.L'Access, Mutex_Attr'Access);
907 pragma Assert (Result = 0 or else Result = ENOMEM);
909 if Result = ENOMEM then
910 Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
911 pragma Assert (Result = 0);
916 Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
917 pragma Assert (Result = 0);
919 -- Initialize internal condition variable
921 Result := pthread_condattr_init (Cond_Attr'Access);
922 pragma Assert (Result = 0 or else Result = ENOMEM);
925 Result := pthread_mutex_destroy (S.L'Access);
926 pragma Assert (Result = 0);
928 if Result = ENOMEM then
933 Result := pthread_cond_init (S.CV'Access, Cond_Attr'Access);
934 pragma Assert (Result = 0 or else Result = ENOMEM);
937 Result := pthread_mutex_destroy (S.L'Access);
938 pragma Assert (Result = 0);
940 if Result = ENOMEM then
941 Result := pthread_condattr_destroy (Cond_Attr'Access);
942 pragma Assert (Result = 0);
948 Result := pthread_condattr_destroy (Cond_Attr'Access);
949 pragma Assert (Result = 0);
956 procedure Finalize (S : in out Suspension_Object) is
957 Result : Interfaces.C.int;
959 -- Destroy internal mutex
961 Result := pthread_mutex_destroy (S.L'Access);
962 pragma Assert (Result = 0);
964 -- Destroy internal condition variable
966 Result := pthread_cond_destroy (S.CV'Access);
967 pragma Assert (Result = 0);
974 function Current_State (S : Suspension_Object) return Boolean is
976 -- We do not want to use lock on this read operation. State is marked
977 -- as Atomic so that we ensure that the value retrieved is correct.
986 procedure Set_False (S : in out Suspension_Object) is
987 Result : Interfaces.C.int;
991 Result := pthread_mutex_lock (S.L'Access);
992 pragma Assert (Result = 0);
996 Result := pthread_mutex_unlock (S.L'Access);
997 pragma Assert (Result = 0);
999 SSL.Abort_Undefer.all;
1006 procedure Set_True (S : in out Suspension_Object) is
1007 Result : Interfaces.C.int;
1009 SSL.Abort_Defer.all;
1011 Result := pthread_mutex_lock (S.L'Access);
1012 pragma Assert (Result = 0);
1014 -- If there is already a task waiting on this suspension object then
1015 -- we resume it, leaving the state of the suspension object to False,
1016 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1017 -- the state to True.
1023 Result := pthread_cond_signal (S.CV'Access);
1024 pragma Assert (Result = 0);
1029 Result := pthread_mutex_unlock (S.L'Access);
1030 pragma Assert (Result = 0);
1032 SSL.Abort_Undefer.all;
1035 ------------------------
1036 -- Suspend_Until_True --
1037 ------------------------
1039 procedure Suspend_Until_True (S : in out Suspension_Object) is
1040 Result : Interfaces.C.int;
1042 SSL.Abort_Defer.all;
1044 Result := pthread_mutex_lock (S.L'Access);
1045 pragma Assert (Result = 0);
1048 -- Program_Error must be raised upon calling Suspend_Until_True
1049 -- if another task is already waiting on that suspension object
1050 -- (ARM D.10 par. 10).
1052 Result := pthread_mutex_unlock (S.L'Access);
1053 pragma Assert (Result = 0);
1055 SSL.Abort_Undefer.all;
1057 raise Program_Error;
1059 -- Suspend the task if the state is False. Otherwise, the task
1060 -- continues its execution, and the state of the suspension object
1061 -- is set to False (ARM D.10 par. 9).
1067 Result := pthread_cond_wait (S.CV'Access, S.L'Access);
1070 Result := pthread_mutex_unlock (S.L'Access);
1071 pragma Assert (Result = 0);
1073 SSL.Abort_Undefer.all;
1075 end Suspend_Until_True;
1083 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1084 pragma Unreferenced (Self_ID);
1089 --------------------
1090 -- Check_No_Locks --
1091 --------------------
1093 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1094 pragma Unreferenced (Self_ID);
1099 ----------------------
1100 -- Environment_Task --
1101 ----------------------
1103 function Environment_Task return Task_Id is
1105 return Environment_Task_Id;
1106 end Environment_Task;
1112 procedure Lock_RTS is
1114 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1121 procedure Unlock_RTS is
1123 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1130 function Suspend_Task
1132 Thread_Self : Thread_Id) return Boolean
1134 pragma Unreferenced (T);
1135 pragma Unreferenced (Thread_Self);
1144 function Resume_Task
1146 Thread_Self : Thread_Id) return Boolean
1148 pragma Unreferenced (T);
1149 pragma Unreferenced (Thread_Self);
1158 procedure Initialize (Environment_Task : Task_Id) is
1160 Environment_Task_Id := Environment_Task;
1162 SSL.Get_Exc_Stack_Addr := Get_Exc_Stack_Addr'Access;
1164 -- Initialize the lock used to synchronize chain of all ATCBs
1166 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1168 Specific.Initialize (Environment_Task);
1170 Enter_Task (Environment_Task);
1173 end System.Task_Primitives.Operations;