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
201 (Prio : System.Any_Priority; L : not null access Lock)
203 Attributes : aliased pthread_mutexattr_t;
204 Result : Interfaces.C.int;
207 Result := pthread_mutexattr_init (Attributes'Access);
208 pragma Assert (Result = 0 or else Result = ENOMEM);
210 if Result = ENOMEM then
215 L.Prio := Interfaces.C.int (Prio);
217 Result := pthread_mutex_init (L.L'Access, Attributes'Access);
218 pragma Assert (Result = 0 or else Result = ENOMEM);
220 if Result = ENOMEM then
224 Result := pthread_mutexattr_destroy (Attributes'Access);
225 pragma Assert (Result = 0);
228 procedure Initialize_Lock
229 (L : not null access RTS_Lock; Level : Lock_Level)
231 pragma Unreferenced (Level);
233 Attributes : aliased pthread_mutexattr_t;
234 Result : Interfaces.C.int;
237 Result := pthread_mutexattr_init (Attributes'Access);
238 pragma Assert (Result = 0 or else Result = ENOMEM);
240 if Result = ENOMEM then
244 -- Don't use, see comment in s-osinte.ads about ERRORCHECK mutexes???
245 -- Result := pthread_mutexattr_settype_np
246 -- (Attributes'Access, PTHREAD_MUTEX_ERRORCHECK_NP);
247 -- pragma Assert (Result = 0);
249 -- Result := pthread_mutexattr_setprotocol
250 -- (Attributes'Access, PTHREAD_PRIO_PROTECT);
251 -- pragma Assert (Result = 0);
253 -- Result := pthread_mutexattr_setprioceiling
254 -- (Attributes'Access, Interfaces.C.int (System.Any_Priority'Last));
255 -- pragma Assert (Result = 0);
257 Result := pthread_mutex_init (L, Attributes'Access);
259 pragma Assert (Result = 0 or else Result = ENOMEM);
261 if Result = ENOMEM then
265 Result := pthread_mutexattr_destroy (Attributes'Access);
266 pragma Assert (Result = 0);
273 procedure Finalize_Lock (L : not null access Lock) is
274 Result : Interfaces.C.int;
276 Result := pthread_mutex_destroy (L.L'Access);
277 pragma Assert (Result = 0);
280 procedure Finalize_Lock (L : not null access RTS_Lock) is
281 Result : Interfaces.C.int;
283 Result := pthread_mutex_destroy (L);
284 pragma Assert (Result = 0);
292 (L : not null access Lock; Ceiling_Violation : out Boolean)
294 Self_ID : constant Task_Id := Self;
295 All_Tasks_Link : constant Task_Id := Self.Common.All_Tasks_Link;
296 Current_Prio : System.Any_Priority;
297 Result : Interfaces.C.int;
300 Current_Prio := Get_Priority (Self_ID);
302 -- If there is no other tasks, no need to check priorities
304 if All_Tasks_Link /= Null_Task
305 and then L.Prio < Interfaces.C.int (Current_Prio)
307 Ceiling_Violation := True;
311 Result := pthread_mutex_lock (L.L'Access);
312 pragma Assert (Result = 0);
314 Ceiling_Violation := False;
315 -- Why is this commented out ???
316 -- L.Prio_Save := Interfaces.C.int (Current_Prio);
317 -- Set_Priority (Self_ID, System.Any_Priority (L.Prio));
321 (L : not null access RTS_Lock;
322 Global_Lock : Boolean := False)
324 Result : Interfaces.C.int;
326 if not Single_Lock or else Global_Lock then
327 Result := pthread_mutex_lock (L);
328 pragma Assert (Result = 0);
332 procedure Write_Lock (T : Task_Id) is
333 Result : Interfaces.C.int;
335 if not Single_Lock then
336 Result := pthread_mutex_lock (T.Common.LL.L'Access);
337 pragma Assert (Result = 0);
346 (L : not null access Lock; Ceiling_Violation : out Boolean) is
348 Write_Lock (L, Ceiling_Violation);
355 procedure Unlock (L : not null access Lock) is
356 Result : Interfaces.C.int;
358 Result := pthread_mutex_unlock (L.L'Access);
359 pragma Assert (Result = 0);
363 (L : not null access RTS_Lock; Global_Lock : Boolean := False)
365 Result : Interfaces.C.int;
367 if not Single_Lock or else Global_Lock then
368 Result := pthread_mutex_unlock (L);
369 pragma Assert (Result = 0);
373 procedure Unlock (T : Task_Id) is
374 Result : Interfaces.C.int;
376 if not Single_Lock then
377 Result := pthread_mutex_unlock (T.Common.LL.L'Access);
378 pragma Assert (Result = 0);
388 Reason : System.Tasking.Task_States)
390 pragma Unreferenced (Reason);
391 Result : Interfaces.C.int;
395 Result := pthread_cond_wait
396 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
398 Result := pthread_cond_wait
399 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
402 -- EINTR is not considered a failure
404 pragma Assert (Result = 0 or else Result = EINTR);
406 if Self_ID.Deferral_Level = 0
407 and then Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
410 raise Standard'Abort_Signal;
418 procedure Timed_Sleep
421 Mode : ST.Delay_Modes;
422 Reason : System.Tasking.Task_States;
423 Timedout : out Boolean;
424 Yielded : out Boolean)
426 pragma Unreferenced (Reason);
428 Sleep_Time : OS_Time;
429 Result : Interfaces.C.int;
430 Status : Cond_Value_Type;
432 -- The body below requires more comments ???
438 Sleep_Time := To_OS_Time (Time, Mode);
440 if Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
441 or else Self_ID.Pending_Priority_Change
446 Self_ID.Common.LL.AST_Pending := True;
449 (Status, 0, Sleep_Time,
450 Timer_Sleep_AST'Access, To_Address (Self_ID), 0);
452 if (Status and 1) /= 1 then
457 Result := pthread_cond_wait
458 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
459 pragma Assert (Result = 0);
462 Result := pthread_cond_wait
463 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
464 pragma Assert (Result = 0);
469 if not Self_ID.Common.LL.AST_Pending then
472 Sys_Cantim (Status, To_Address (Self_ID), 0);
473 pragma Assert ((Status and 1) = 1);
481 procedure Timed_Delay
484 Mode : ST.Delay_Modes)
486 Sleep_Time : OS_Time;
487 Result : Interfaces.C.int;
488 Status : Cond_Value_Type;
489 Yielded : Boolean := False;
496 -- More comments required in body below ???
498 Write_Lock (Self_ID);
500 if Time /= 0.0 or else Mode /= Relative then
501 Sleep_Time := To_OS_Time (Time, Mode);
503 if Mode = Relative or else OS_Clock < Sleep_Time then
504 Self_ID.Common.State := Delay_Sleep;
505 Self_ID.Common.LL.AST_Pending := True;
508 (Status, 0, Sleep_Time,
509 Timer_Sleep_AST'Access, To_Address (Self_ID), 0);
511 if (Status and 1) /= 1 then
516 if Self_ID.Pending_Priority_Change then
517 Self_ID.Pending_Priority_Change := False;
518 Self_ID.Common.Base_Priority := Self_ID.New_Base_Priority;
519 Set_Priority (Self_ID, Self_ID.Common.Base_Priority);
522 if Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level then
523 Sys_Cantim (Status, To_Address (Self_ID), 0);
524 pragma Assert ((Status and 1) = 1);
529 Result := pthread_cond_wait
530 (Self_ID.Common.LL.CV'Access, Single_RTS_Lock'Access);
531 pragma Assert (Result = 0);
533 Result := pthread_cond_wait
534 (Self_ID.Common.LL.CV'Access, Self_ID.Common.LL.L'Access);
535 pragma Assert (Result = 0);
540 exit when not Self_ID.Common.LL.AST_Pending;
543 Self_ID.Common.State := Runnable;
554 Result := sched_yield;
555 pragma Assert (Result = 0);
559 ---------------------
560 -- Monotonic_Clock --
561 ---------------------
563 function Monotonic_Clock return Duration
564 renames System.OS_Primitives.Monotonic_Clock;
570 function RT_Resolution return Duration is
579 procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
580 pragma Unreferenced (Reason);
581 Result : Interfaces.C.int;
583 Result := pthread_cond_signal (T.Common.LL.CV'Access);
584 pragma Assert (Result = 0);
591 procedure Yield (Do_Yield : Boolean := True) is
592 Result : Interfaces.C.int;
593 pragma Unreferenced (Result);
596 Result := sched_yield;
604 procedure Set_Priority
606 Prio : System.Any_Priority;
607 Loss_Of_Inheritance : Boolean := False)
609 pragma Unreferenced (Loss_Of_Inheritance);
611 Result : Interfaces.C.int;
612 Param : aliased struct_sched_param;
614 function Get_Policy (Prio : System.Any_Priority) return Character;
615 pragma Import (C, Get_Policy, "__gnat_get_specific_dispatching");
616 -- Get priority specific dispatching policy
618 Priority_Specific_Policy : constant Character := Get_Policy (Prio);
619 -- Upper case first character of the policy name corresponding to the
620 -- task as set by a Priority_Specific_Dispatching pragma.
623 T.Common.Current_Priority := Prio;
624 Param.sched_priority := Interfaces.C.int (Underlying_Priorities (Prio));
626 if Dispatching_Policy = 'R'
627 or else Priority_Specific_Policy = 'R'
628 or else Time_Slice_Val > 0
630 Result := pthread_setschedparam
631 (T.Common.LL.Thread, SCHED_RR, Param'Access);
633 elsif Dispatching_Policy = 'F'
634 or else Priority_Specific_Policy = 'F'
635 or else Time_Slice_Val = 0
637 Result := pthread_setschedparam
638 (T.Common.LL.Thread, SCHED_FIFO, Param'Access);
641 -- SCHED_OTHER priorities are restricted to the range 8 - 15.
642 -- Since the translation from Underlying priorities results
643 -- in a range of 16 - 31, dividing by 2 gives the correct result.
645 Param.sched_priority := Param.sched_priority / 2;
646 Result := pthread_setschedparam
647 (T.Common.LL.Thread, SCHED_OTHER, Param'Access);
650 pragma Assert (Result = 0);
657 function Get_Priority (T : Task_Id) return System.Any_Priority is
659 return T.Common.Current_Priority;
666 procedure Enter_Task (Self_ID : Task_Id) is
668 Self_ID.Common.LL.Thread := pthread_self;
670 Specific.Set (Self_ID);
674 for J in Known_Tasks'Range loop
675 if Known_Tasks (J) = null then
676 Known_Tasks (J) := Self_ID;
677 Self_ID.Known_Tasks_Index := J;
689 function New_ATCB (Entry_Num : Task_Entry_Index) return Task_Id is
691 return new Ada_Task_Control_Block (Entry_Num);
698 function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
700 -----------------------------
701 -- Register_Foreign_Thread --
702 -----------------------------
704 function Register_Foreign_Thread return Task_Id is
706 if Is_Valid_Task then
709 return Register_Foreign_Thread (pthread_self);
711 end Register_Foreign_Thread;
717 procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
718 Mutex_Attr : aliased pthread_mutexattr_t;
719 Result : Interfaces.C.int;
720 Cond_Attr : aliased pthread_condattr_t;
723 -- More comments required in body below ???
725 if not Single_Lock then
726 Result := pthread_mutexattr_init (Mutex_Attr'Access);
727 pragma Assert (Result = 0 or else Result = ENOMEM);
730 Result := pthread_mutex_init (Self_ID.Common.LL.L'Access,
732 pragma Assert (Result = 0 or else Result = ENOMEM);
740 Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
741 pragma Assert (Result = 0);
744 Result := pthread_condattr_init (Cond_Attr'Access);
745 pragma Assert (Result = 0 or else Result = ENOMEM);
748 Result := pthread_cond_init (Self_ID.Common.LL.CV'Access,
750 pragma Assert (Result = 0 or else Result = ENOMEM);
755 Self_ID.Common.LL.Exc_Stack_Ptr := new Exc_Stack_T;
758 if not Single_Lock then
759 Result := pthread_mutex_destroy (Self_ID.Common.LL.L'Access);
760 pragma Assert (Result = 0);
766 Result := pthread_condattr_destroy (Cond_Attr'Access);
767 pragma Assert (Result = 0);
770 ------------------------
771 -- Get_Exc_Stack_Addr --
772 ------------------------
774 function Get_Exc_Stack_Addr return Address is
776 return Self.Common.LL.Exc_Stack_Ptr (Exc_Stack_T'Last)'Address;
777 end Get_Exc_Stack_Addr;
783 procedure Create_Task
785 Wrapper : System.Address;
786 Stack_Size : System.Parameters.Size_Type;
787 Priority : System.Any_Priority;
788 Succeeded : out Boolean)
790 Attributes : aliased pthread_attr_t;
791 Result : Interfaces.C.int;
793 function Thread_Body_Access is new
794 Unchecked_Conversion (System.Address, Thread_Body);
797 -- Since the initial signal mask of a thread is inherited from the
798 -- creator, we need to set our local signal mask mask all signals
799 -- during the creation operation, to make sure the new thread is
800 -- not disturbed by signals before it has set its own Task_Id.
802 Result := pthread_attr_init (Attributes'Access);
803 pragma Assert (Result = 0 or else Result = ENOMEM);
810 Result := pthread_attr_setdetachstate
811 (Attributes'Access, PTHREAD_CREATE_DETACHED);
812 pragma Assert (Result = 0);
814 Result := pthread_attr_setstacksize
815 (Attributes'Access, Interfaces.C.size_t (Stack_Size));
816 pragma Assert (Result = 0);
818 -- This call may be unnecessary, not sure. ???
821 pthread_attr_setinheritsched
822 (Attributes'Access, PTHREAD_EXPLICIT_SCHED);
823 pragma Assert (Result = 0);
825 Result := pthread_create
826 (T.Common.LL.Thread'Access,
828 Thread_Body_Access (Wrapper),
831 -- ENOMEM is a valid run-time error. Don't shut down.
833 pragma Assert (Result = 0
834 or else Result = EAGAIN or else Result = ENOMEM);
836 Succeeded := Result = 0;
838 Result := pthread_attr_destroy (Attributes'Access);
839 pragma Assert (Result = 0);
842 Set_Priority (T, Priority);
850 procedure Finalize_TCB (T : Task_Id) is
851 Result : Interfaces.C.int;
853 Is_Self : constant Boolean := T = Self;
855 procedure Free is new
856 Unchecked_Deallocation (Ada_Task_Control_Block, Task_Id);
858 procedure Free is new Unchecked_Deallocation
859 (Exc_Stack_T, Exc_Stack_Ptr_T);
862 if not Single_Lock then
863 Result := pthread_mutex_destroy (T.Common.LL.L'Access);
864 pragma Assert (Result = 0);
867 Result := pthread_cond_destroy (T.Common.LL.CV'Access);
868 pragma Assert (Result = 0);
870 if T.Known_Tasks_Index /= -1 then
871 Known_Tasks (T.Known_Tasks_Index) := null;
874 Free (T.Common.LL.Exc_Stack_Ptr);
887 procedure Exit_Task is
896 procedure Abort_Task (T : Task_Id) is
898 -- Interrupt Server_Tasks may be waiting on an event flag
900 if T.Common.State = Interrupt_Server_Blocked_On_Event_Flag then
901 Wakeup (T, Interrupt_Server_Blocked_On_Event_Flag);
909 procedure Initialize (S : in out Suspension_Object) is
910 Mutex_Attr : aliased pthread_mutexattr_t;
911 Cond_Attr : aliased pthread_condattr_t;
912 Result : Interfaces.C.int;
914 -- Initialize internal state. It is always initialized to False (ARM
920 -- Initialize internal mutex
922 Result := pthread_mutexattr_init (Mutex_Attr'Access);
923 pragma Assert (Result = 0 or else Result = ENOMEM);
925 if Result = ENOMEM then
929 Result := pthread_mutex_init (S.L'Access, Mutex_Attr'Access);
930 pragma Assert (Result = 0 or else Result = ENOMEM);
932 if Result = ENOMEM then
933 Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
934 pragma Assert (Result = 0);
939 Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
940 pragma Assert (Result = 0);
942 -- Initialize internal condition variable
944 Result := pthread_condattr_init (Cond_Attr'Access);
945 pragma Assert (Result = 0 or else Result = ENOMEM);
948 Result := pthread_mutex_destroy (S.L'Access);
949 pragma Assert (Result = 0);
951 if Result = ENOMEM then
956 Result := pthread_cond_init (S.CV'Access, Cond_Attr'Access);
957 pragma Assert (Result = 0 or else Result = ENOMEM);
960 Result := pthread_mutex_destroy (S.L'Access);
961 pragma Assert (Result = 0);
963 if Result = ENOMEM then
964 Result := pthread_condattr_destroy (Cond_Attr'Access);
965 pragma Assert (Result = 0);
971 Result := pthread_condattr_destroy (Cond_Attr'Access);
972 pragma Assert (Result = 0);
979 procedure Finalize (S : in out Suspension_Object) is
980 Result : Interfaces.C.int;
982 -- Destroy internal mutex
984 Result := pthread_mutex_destroy (S.L'Access);
985 pragma Assert (Result = 0);
987 -- Destroy internal condition variable
989 Result := pthread_cond_destroy (S.CV'Access);
990 pragma Assert (Result = 0);
997 function Current_State (S : Suspension_Object) return Boolean is
999 -- We do not want to use lock on this read operation. State is marked
1000 -- as Atomic so that we ensure that the value retrieved is correct.
1009 procedure Set_False (S : in out Suspension_Object) is
1010 Result : Interfaces.C.int;
1012 SSL.Abort_Defer.all;
1014 Result := pthread_mutex_lock (S.L'Access);
1015 pragma Assert (Result = 0);
1019 Result := pthread_mutex_unlock (S.L'Access);
1020 pragma Assert (Result = 0);
1022 SSL.Abort_Undefer.all;
1029 procedure Set_True (S : in out Suspension_Object) is
1030 Result : Interfaces.C.int;
1032 SSL.Abort_Defer.all;
1034 Result := pthread_mutex_lock (S.L'Access);
1035 pragma Assert (Result = 0);
1037 -- If there is already a task waiting on this suspension object then
1038 -- we resume it, leaving the state of the suspension object to False,
1039 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1040 -- the state to True.
1046 Result := pthread_cond_signal (S.CV'Access);
1047 pragma Assert (Result = 0);
1052 Result := pthread_mutex_unlock (S.L'Access);
1053 pragma Assert (Result = 0);
1055 SSL.Abort_Undefer.all;
1058 ------------------------
1059 -- Suspend_Until_True --
1060 ------------------------
1062 procedure Suspend_Until_True (S : in out Suspension_Object) is
1063 Result : Interfaces.C.int;
1065 SSL.Abort_Defer.all;
1067 Result := pthread_mutex_lock (S.L'Access);
1068 pragma Assert (Result = 0);
1071 -- Program_Error must be raised upon calling Suspend_Until_True
1072 -- if another task is already waiting on that suspension object
1073 -- (ARM D.10 par. 10).
1075 Result := pthread_mutex_unlock (S.L'Access);
1076 pragma Assert (Result = 0);
1078 SSL.Abort_Undefer.all;
1080 raise Program_Error;
1082 -- Suspend the task if the state is False. Otherwise, the task
1083 -- continues its execution, and the state of the suspension object
1084 -- is set to False (ARM D.10 par. 9).
1090 Result := pthread_cond_wait (S.CV'Access, S.L'Access);
1093 Result := pthread_mutex_unlock (S.L'Access);
1094 pragma Assert (Result = 0);
1096 SSL.Abort_Undefer.all;
1098 end Suspend_Until_True;
1106 function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
1107 pragma Unreferenced (Self_ID);
1112 --------------------
1113 -- Check_No_Locks --
1114 --------------------
1116 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
1117 pragma Unreferenced (Self_ID);
1122 ----------------------
1123 -- Environment_Task --
1124 ----------------------
1126 function Environment_Task return Task_Id is
1128 return Environment_Task_Id;
1129 end Environment_Task;
1135 procedure Lock_RTS is
1137 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1144 procedure Unlock_RTS is
1146 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1153 function Suspend_Task
1155 Thread_Self : Thread_Id) return Boolean
1157 pragma Unreferenced (T);
1158 pragma Unreferenced (Thread_Self);
1167 function Resume_Task
1169 Thread_Self : Thread_Id) return Boolean
1171 pragma Unreferenced (T);
1172 pragma Unreferenced (Thread_Self);
1181 procedure Initialize (Environment_Task : Task_Id) is
1183 Environment_Task_Id := Environment_Task;
1185 SSL.Get_Exc_Stack_Addr := Get_Exc_Stack_Addr'Access;
1187 -- Initialize the lock used to synchronize chain of all ATCBs
1189 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1191 Specific.Initialize (Environment_Task);
1193 Enter_Task (Environment_Task);
1196 end System.Task_Primitives.Operations;