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-2005, 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 an Irix (old athread library) 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.
47 with System
.Tasking
.Debug
;
48 -- used for Known_Tasks
50 with System
.Interrupt_Management
;
51 -- used for Keep_Unmasked
52 -- Abort_Task_Interrupt
55 with System
.OS_Primitives
;
56 -- used for Delay_Modes
58 with System
.Task_Info
;
60 with System
.Parameters
;
63 with System
.Program_Info
;
64 -- used for Default_Task_Stack
67 -- Pthread_Sched_Signal
70 with System
.Storage_Elements
;
71 -- used for To_Address
73 with Unchecked_Conversion
;
74 with Unchecked_Deallocation
;
76 package body System
.Task_Primitives
.Operations
is
78 use System
.Tasking
.Debug
;
81 use System
.OS_Interface
;
82 use System
.Parameters
;
83 use System
.OS_Primitives
;
89 -- The followings are logically constants, but need to be initialized
92 Single_RTS_Lock
: aliased RTS_Lock
;
93 -- This is a lock to allow only one thread of control in the RTS at
94 -- a time; it is used to execute in mutual exclusion from all other tasks.
95 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
97 Environment_Task_Id
: Task_Id
;
98 -- A variable to hold Task_Id for the environment task.
100 Locking_Policy
: Character;
101 pragma Import
(C
, Locking_Policy
, "__gl_locking_policy");
103 Clock_Address
: constant System
.Address
:=
104 System
.Storage_Elements
.To_Address
(16#
200F90#
);
106 RT_Clock_Id
: clockid_t
;
107 for RT_Clock_Id
'Address use Clock_Address
;
109 -----------------------
110 -- Local Subprograms --
111 -----------------------
113 procedure Initialize_Athread_Library
;
115 function To_Task_Id
is new Unchecked_Conversion
(System
.Address
, Task_Id
);
116 function To_Address
is new Unchecked_Conversion
(Task_Id
, System
.Address
);
122 -- The underlying thread system sets a guard page at the
123 -- bottom of a thread stack, so nothing is needed.
124 -- ??? Check the comment above
126 procedure Stack_Guard
(T
: ST
.Task_Id
; On
: Boolean) is
127 pragma Unreferenced
(T
);
128 pragma Unreferenced
(On
);
137 function Get_Thread_Id
(T
: ST
.Task_Id
) return OSI
.Thread_Id
is
139 return T
.Common
.LL
.Thread
;
146 function Self
return Task_Id
is
148 return To_Task_Id
(pthread_get_current_ada_tcb
);
151 ---------------------
152 -- Initialize_Lock --
153 ---------------------
155 -- Note: mutexes and cond_variables needed per-task basis are
156 -- initialized in Initialize_TCB and the Storage_Error is
157 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
158 -- used in RTS is initialized before any status change of RTS.
159 -- Therefore rasing Storage_Error in the following routines
160 -- should be able to be handled safely.
162 procedure Initialize_Lock
163 (Prio
: System
.Any_Priority
;
166 Attributes
: aliased pthread_mutexattr_t
;
167 Result
: Interfaces
.C
.int
;
170 Result
:= pthread_mutexattr_init
(Attributes
'Access);
172 if Result
= FUNC_ERR
then
176 if Locking_Policy
= 'C' then
178 Result
:= pthread_mutexattr_setqueueorder
179 (Attributes
'Access, MUTEX_PRIORITY_CEILING
);
181 pragma Assert
(Result
/= FUNC_ERR
);
183 Result
:= pthread_mutexattr_setceilingprio
184 (Attributes
'Access, Interfaces
.C
.int
(Prio
));
186 pragma Assert
(Result
/= FUNC_ERR
);
189 Result
:= pthread_mutex_init
(L
, Attributes
'Access);
191 if Result
= FUNC_ERR
then
192 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
196 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
199 procedure Initialize_Lock
(L
: access RTS_Lock
; Level
: Lock_Level
) is
200 pragma Unreferenced
(Level
);
202 Attributes
: aliased pthread_mutexattr_t
;
203 Result
: Interfaces
.C
.int
;
206 Result
:= pthread_mutexattr_init
(Attributes
'Access);
208 if Result
= FUNC_ERR
then
212 if Locking_Policy
= 'C' then
213 Result
:= pthread_mutexattr_setqueueorder
214 (Attributes
'Access, MUTEX_PRIORITY_CEILING
);
215 pragma Assert
(Result
/= FUNC_ERR
);
217 Result
:= pthread_mutexattr_setceilingprio
218 (Attributes
'Access, Interfaces
.C
.int
(System
.Any_Priority
'Last));
219 pragma Assert
(Result
/= FUNC_ERR
);
222 Result
:= pthread_mutex_init
(L
, Attributes
'Access);
224 if Result
= FUNC_ERR
then
225 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
229 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
236 procedure Finalize_Lock
(L
: access Lock
) is
237 Result
: Interfaces
.C
.int
;
239 Result
:= pthread_mutex_destroy
(L
);
240 pragma Assert
(Result
= 0);
243 procedure Finalize_Lock
(L
: access RTS_Lock
) is
244 Result
: Interfaces
.C
.int
;
246 Result
:= pthread_mutex_destroy
(L
);
247 pragma Assert
(Result
= 0);
254 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
255 Result
: Interfaces
.C
.int
;
257 Result
:= pthread_mutex_lock
(L
);
258 Ceiling_Violation
:= Result
= FUNC_ERR
and then errno
= EINVAL
;
259 pragma Assert
(Result
/= FUNC_ERR
);
263 (L
: access RTS_Lock
; Global_Lock
: Boolean := False)
265 Result
: Interfaces
.C
.int
;
267 if not Single_Lock
or else Global_Lock
then
268 Result
:= pthread_mutex_lock
(L
);
269 pragma Assert
(Result
= 0);
273 procedure Write_Lock
(T
: Task_Id
) is
274 Result
: Interfaces
.C
.int
;
276 if not Single_Lock
then
277 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
278 pragma Assert
(Result
= 0);
286 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
288 Write_Lock
(L
, Ceiling_Violation
);
295 procedure Unlock
(L
: access Lock
) is
296 Result
: Interfaces
.C
.int
;
298 Result
:= pthread_mutex_unlock
(L
);
299 pragma Assert
(Result
= 0);
302 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
303 Result
: Interfaces
.C
.int
;
305 if not Single_Lock
or else Global_Lock
then
306 Result
:= pthread_mutex_unlock
(L
);
307 pragma Assert
(Result
= 0);
311 procedure Unlock
(T
: Task_Id
) is
312 Result
: Interfaces
.C
.int
;
314 if not Single_Lock
then
315 Result
:= pthread_mutex_unlock
(T
.Common
.LL
.L
'Access);
316 pragma Assert
(Result
= 0);
325 (Self_ID
: ST
.Task_Id
;
326 Reason
: System
.Tasking
.Task_States
)
328 pragma Unreferenced
(Reason
);
330 Result
: Interfaces
.C
.int
;
334 Result
:= pthread_cond_wait
335 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access);
337 Result
:= pthread_cond_wait
338 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access);
341 -- EINTR is not considered a failure.
343 pragma Assert
(Result
= 0 or else Result
= EINTR
);
350 procedure Timed_Sleep
353 Mode
: ST
.Delay_Modes
;
354 Reason
: System
.Tasking
.Task_States
;
355 Timedout
: out Boolean;
356 Yielded
: out Boolean)
358 pragma Unreferenced
(Reason
);
360 Check_Time
: constant Duration := Monotonic_Clock
;
362 Request
: aliased struct_timeval
;
363 Result
: Interfaces
.C
.int
;
369 if Mode
= Relative
then
370 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
372 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
375 if Abs_Time
> Check_Time
then
376 Request
:= To_Timeval
(Abs_Time
);
379 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
380 or else Self_ID
.Pending_Priority_Change
;
383 Result
:= pthread_cond_timedwait
384 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access,
388 Result
:= pthread_cond_timedwait
389 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access,
393 exit when Abs_Time
<= Monotonic_Clock
;
395 if Result
= 0 or Result
= EINTR
then
396 -- somebody may have called Wakeup for us
401 pragma Assert
(Result
= ETIMEDOUT
402 or else (Result
= -1 and then errno
= EAGAIN
));
411 procedure Timed_Delay
414 Mode
: ST
.Delay_Modes
)
416 Check_Time
: constant Duration := Monotonic_Clock
;
418 Request
: aliased struct_timeval
;
419 Result
: Interfaces
.C
.int
;
426 Write_Lock
(Self_ID
);
428 if Mode
= Relative
then
429 Abs_Time
:= Time
+ Check_Time
;
431 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
434 if Abs_Time
> Check_Time
then
435 Request
:= To_Timeval
(Abs_Time
);
436 Self_ID
.Common
.State
:= Delay_Sleep
;
439 if Self_ID
.Pending_Priority_Change
then
440 Self_ID
.Pending_Priority_Change
:= False;
441 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
442 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
445 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
448 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
449 Single_RTS_Lock
'Access, Request
'Access);
451 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
452 Self_ID
.Common
.LL
.L
'Access, Request
'Access);
455 exit when Abs_Time
<= Monotonic_Clock
;
457 pragma Assert
(Result
= 0 or else
458 Result
= ETIMEDOUT
or else
459 (Result
= -1 and then errno
= EAGAIN
) or else
463 Self_ID
.Common
.State
:= Runnable
;
475 ---------------------
476 -- Monotonic_Clock --
477 ---------------------
479 function Monotonic_Clock
return Duration is
480 type timeval
is record
484 pragma Convention
(C
, timeval
);
486 tv
: aliased timeval
;
488 procedure gettimeofday
(tp
: access timeval
);
489 pragma Import
(C
, gettimeofday
, "gettimeofday", "gettimeofday");
492 gettimeofday
(tv
'Access);
493 return Duration (tv
.tv_sec
) + Duration (tv
.tv_usec
) / 1_000_000
.0
;
500 function RT_Resolution
return Duration is
511 Reason
: System
.Tasking
.Task_States
)
513 pragma Unreferenced
(Reason
);
514 Result
: Interfaces
.C
.int
;
516 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
517 pragma Assert
(Result
= 0);
524 procedure Yield
(Do_Yield
: Boolean := True) is
535 procedure Set_Priority
537 Prio
: System
.Any_Priority
;
538 Loss_Of_Inheritance
: Boolean := False)
540 pragma Unreferenced
(Loss_Of_Inheritance
);
542 Result
: Interfaces
.C
.int
;
545 T
.Common
.Current_Priority
:= Prio
;
546 Result
:= pthread_setprio
(T
.Common
.LL
.Thread
, Interfaces
.C
.int
(Prio
));
547 pragma Assert
(Result
/= FUNC_ERR
);
554 function Get_Priority
(T
: Task_Id
) return System
.Any_Priority
is
556 return T
.Common
.Current_Priority
;
563 procedure Enter_Task
(Self_ID
: Task_Id
) is
564 Result
: Interfaces
.C
.int
;
567 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
568 Self_ID
.Common
.LL
.LWP
:= sproc_self
;
571 pthread_set_ada_tcb
(Self_ID
.Common
.LL
.Thread
, To_Address
(Self_ID
));
573 pragma Assert
(Result
= 0);
577 for J
in Known_Tasks
'Range loop
578 if Known_Tasks
(J
) = null then
579 Known_Tasks
(J
) := Self_ID
;
580 Self_ID
.Known_Tasks_Index
:= J
;
592 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_Id
is
594 return new Ada_Task_Control_Block
(Entry_Num
);
601 function Is_Valid_Task
return Boolean is
606 -----------------------------
607 -- Register_Foreign_Thread --
608 -----------------------------
610 function Register_Foreign_Thread
return Task_Id
is
613 end Register_Foreign_Thread
;
619 procedure Initialize_TCB
(Self_ID
: Task_Id
; Succeeded
: out Boolean) is
620 Result
: Interfaces
.C
.int
;
621 Cond_Attr
: aliased pthread_condattr_t
;
624 if not Single_Lock
then
625 Initialize_Lock
(Self_ID
.Common
.LL
.L
'Access, ATCB_Level
);
628 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
629 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
632 Result
:= pthread_cond_init
(Self_ID
.Common
.LL
.CV
'Access,
634 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
640 if not Single_Lock
then
641 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
642 pragma Assert
(Result
= 0);
648 Result
:= pthread_condattr_destroy
(Cond_Attr
'Access);
649 pragma Assert
(Result
= 0);
656 procedure Create_Task
658 Wrapper
: System
.Address
;
659 Stack_Size
: System
.Parameters
.Size_Type
;
660 Priority
: System
.Any_Priority
;
661 Succeeded
: out Boolean)
663 Attributes
: aliased pthread_attr_t
;
664 Adjusted_Stack_Size
: Interfaces
.C
.size_t
;
665 Result
: Interfaces
.C
.int
;
667 function Thread_Body_Access
is new
668 Unchecked_Conversion
(System
.Address
, start_addr
);
670 function To_Resource_T
is new Unchecked_Conversion
671 (System
.Task_Info
.Resource_Vector_T
, System
.OS_Interface
.resource_t
);
673 use System
.Task_Info
;
676 if Stack_Size
= Unspecified_Size
then
677 Adjusted_Stack_Size
:=
678 Interfaces
.C
.size_t
(System
.Program_Info
.Default_Task_Stack
);
680 elsif Stack_Size
< Minimum_Stack_Size
then
681 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Minimum_Stack_Size
);
684 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Stack_Size
);
687 Result
:= pthread_attr_init
(Attributes
'Access);
688 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
695 Result
:= pthread_attr_setdetachstate
(Attributes
'Access, 1);
696 pragma Assert
(Result
= 0);
698 Result
:= pthread_attr_setstacksize
699 (Attributes
'Access, Adjusted_Stack_Size
);
700 pragma Assert
(Result
= 0);
702 if T
.Common
.Task_Info
/= null then
703 Result
:= pthread_attr_setresources
705 To_Resource_T
(T
.Common
.Task_Info
.Thread_Resources
));
706 pragma Assert
(Result
/= FUNC_ERR
);
708 if T
.Common
.Task_Info
.Thread_Timeslice
/= 0.0 then
710 use System
.OS_Interface
;
712 Tv
: aliased struct_timeval
:= To_Timeval
713 (T
.Common
.Task_Info
.Thread_Timeslice
);
715 Result
:= pthread_attr_set_tslice
716 (Attributes
'Access, Tv
'Access);
720 if T
.Common
.Task_Info
.Bound_To_Sproc
then
721 Result
:= pthread_attr_set_boundtosproc
722 (Attributes
'Access, PTHREAD_BOUND
);
723 Result
:= pthread_attr_set_bsproc
724 (Attributes
'Access, T
.Common
.Task_Info
.Sproc
);
729 -- Since the initial signal mask of a thread is inherited from the
730 -- creator, and the Environment task has all its signals masked, we
731 -- do not need to manipulate caller's signal mask at this point.
732 -- All tasks in RTS will have All_Tasks_Mask initially.
734 Result
:= pthread_create
735 (T
.Common
.LL
.Thread
'Access,
737 Thread_Body_Access
(Wrapper
),
739 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
741 Succeeded
:= Result
= 0;
743 Set_Priority
(T
, Priority
);
745 Result
:= pthread_attr_destroy
(Attributes
'Access);
746 pragma Assert
(Result
/= FUNC_ERR
);
753 procedure Finalize_TCB
(T
: Task_Id
) is
754 procedure Free
is new
755 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_Id
);
757 Result
: Interfaces
.C
.int
;
761 if not Single_Lock
then
762 Result
:= pthread_mutex_destroy
(T
.Common
.LL
.L
'Access);
763 pragma Assert
(Result
= 0);
766 Result
:= pthread_cond_destroy
(T
.Common
.LL
.CV
'Access);
767 pragma Assert
(Result
= 0);
769 if T
.Known_Tasks_Index
/= -1 then
770 Known_Tasks
(T
.Known_Tasks_Index
) := null;
780 procedure Exit_Task
is
781 Result
: Interfaces
.C
.int
;
783 Result
:= pthread_set_ada_tcb
(pthread_self
, System
.Null_Address
);
784 pragma Assert
(Result
= 0);
791 procedure Abort_Task
(T
: Task_Id
) is
792 Result
: Interfaces
.C
.int
;
795 pthread_kill
(T
.Common
.LL
.Thread
,
797 (System
.Interrupt_Management
.Abort_Task_Interrupt
));
798 pragma Assert
(Result
= 0);
805 procedure Initialize
(S
: in out Suspension_Object
) is
806 Mutex_Attr
: aliased pthread_mutexattr_t
;
807 Cond_Attr
: aliased pthread_condattr_t
;
808 Result
: Interfaces
.C
.int
;
810 -- Initialize internal state. It is always initialized to False (ARM
816 -- Initialize internal mutex
818 Result
:= pthread_mutexattr_init
(Mutex_Attr
'Access);
819 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
821 if Result
= ENOMEM
then
825 Result
:= pthread_mutex_init
(S
.L
'Access, Mutex_Attr
'Access);
826 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
828 if Result
= ENOMEM
then
829 Result
:= pthread_mutexattr_destroy
(Mutex_Attr
'Access);
830 pragma Assert
(Result
= 0);
835 Result
:= pthread_mutexattr_destroy
(Mutex_Attr
'Access);
836 pragma Assert
(Result
= 0);
838 -- Initialize internal condition variable
840 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
841 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
844 Result
:= pthread_mutex_destroy
(S
.L
'Access);
845 pragma Assert
(Result
= 0);
847 if Result
= ENOMEM
then
852 Result
:= pthread_cond_init
(S
.CV
'Access, Cond_Attr
'Access);
853 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
856 Result
:= pthread_mutex_destroy
(S
.L
'Access);
857 pragma Assert
(Result
= 0);
859 if Result
= ENOMEM
then
860 Result
:= pthread_condattr_destroy
(Cond_Attr
'Access);
861 pragma Assert
(Result
= 0);
867 Result
:= pthread_condattr_destroy
(Cond_Attr
'Access);
868 pragma Assert
(Result
= 0);
875 procedure Finalize
(S
: in out Suspension_Object
) is
876 Result
: Interfaces
.C
.int
;
878 -- Destroy internal mutex
880 Result
:= pthread_mutex_destroy
(S
.L
'Access);
881 pragma Assert
(Result
= 0);
883 -- Destroy internal condition variable
885 Result
:= pthread_cond_destroy
(S
.CV
'Access);
886 pragma Assert
(Result
= 0);
893 function Current_State
(S
: Suspension_Object
) return Boolean is
895 -- We do not want to use lock on this read operation. State is marked
896 -- as Atomic so that we ensure that the value retrieved is correct.
905 procedure Set_False
(S
: in out Suspension_Object
) is
906 Result
: Interfaces
.C
.int
;
908 Result
:= pthread_mutex_lock
(S
.L
'Access);
909 pragma Assert
(Result
= 0);
913 Result
:= pthread_mutex_unlock
(S
.L
'Access);
914 pragma Assert
(Result
= 0);
921 procedure Set_True
(S
: in out Suspension_Object
) is
922 Result
: Interfaces
.C
.int
;
924 Result
:= pthread_mutex_lock
(S
.L
'Access);
925 pragma Assert
(Result
= 0);
927 -- If there is already a task waiting on this suspension object then
928 -- we resume it, leaving the state of the suspension object to False,
929 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
930 -- the state to True.
936 Result
:= pthread_cond_signal
(S
.CV
'Access);
937 pragma Assert
(Result
= 0);
942 Result
:= pthread_mutex_unlock
(S
.L
'Access);
943 pragma Assert
(Result
= 0);
946 ------------------------
947 -- Suspend_Until_True --
948 ------------------------
950 procedure Suspend_Until_True
(S
: in out Suspension_Object
) is
951 Result
: Interfaces
.C
.int
;
953 Result
:= pthread_mutex_lock
(S
.L
'Access);
954 pragma Assert
(Result
= 0);
957 -- Program_Error must be raised upon calling Suspend_Until_True
958 -- if another task is already waiting on that suspension object
959 -- (ARM D.10 par. 10).
961 Result
:= pthread_mutex_unlock
(S
.L
'Access);
962 pragma Assert
(Result
= 0);
966 -- Suspend the task if the state is False. Otherwise, the task
967 -- continues its execution, and the state of the suspension object
968 -- is set to False (ARM D.10 par. 9).
974 Result
:= pthread_cond_wait
(S
.CV
'Access, S
.L
'Access);
978 Result
:= pthread_mutex_unlock
(S
.L
'Access);
979 pragma Assert
(Result
= 0);
980 end Suspend_Until_True
;
988 function Check_Exit
(Self_ID
: ST
.Task_Id
) return Boolean is
989 pragma Unreferenced
(Self_ID
);
998 function Check_No_Locks
(Self_ID
: ST
.Task_Id
) return Boolean is
999 pragma Unreferenced
(Self_ID
);
1004 ----------------------
1005 -- Environment_Task --
1006 ----------------------
1008 function Environment_Task
return Task_Id
is
1010 return Environment_Task_Id
;
1011 end Environment_Task
;
1017 procedure Lock_RTS
is
1019 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1026 procedure Unlock_RTS
is
1028 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1035 function Suspend_Task
1037 Thread_Self
: Thread_Id
) return Boolean
1040 if T
.Common
.LL
.Thread
/= Thread_Self
then
1041 return pthread_suspend
(T
.Common
.LL
.Thread
) = 0;
1051 function Resume_Task
1053 Thread_Self
: Thread_Id
) return Boolean
1056 if T
.Common
.LL
.Thread
/= Thread_Self
then
1057 return pthread_resume
(T
.Common
.LL
.Thread
) = 0;
1067 procedure Initialize
(Environment_Task
: Task_Id
) is
1069 Initialize_Athread_Library
;
1070 Environment_Task_Id
:= Environment_Task
;
1071 Interrupt_Management
.Initialize
;
1073 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
1074 -- Initialize the lock used to synchronize chain of all ATCBs.
1076 Enter_Task
(Environment_Task
);
1078 Set_Priority
(Environment_Task
,
1079 Environment_Task
.Common
.Current_Priority
);
1082 --------------------------------
1083 -- Initialize_Athread_Library --
1084 --------------------------------
1086 procedure Initialize_Athread_Library
is
1087 Result
: Interfaces
.C
.int
;
1088 Init
: aliased pthread_init_struct
;
1090 package PINF
renames System
.Program_Info
;
1091 package C
renames Interfaces
.C
;
1094 Init
.conf_initsize
:= C
.int
(PINF
.Pthread_Arena_Size
);
1095 Init
.max_sproc_count
:= C
.int
(PINF
.Max_Sproc_Count
);
1096 Init
.sproc_stack_size
:= C
.size_t
(PINF
.Sproc_Stack_Size
);
1097 Init
.os_default_priority
:= C
.int
(PINF
.Os_Default_Priority
);
1098 Init
.os_sched_signal
:= C
.int
(PINF
.Pthread_Sched_Signal
);
1099 Init
.guard_pages
:= C
.int
(PINF
.Stack_Guard_Pages
);
1100 Init
.init_sproc_count
:= C
.int
(PINF
.Initial_Sproc_Count
);
1102 Result
:= pthread_exec_begin
(Init
'Access);
1103 pragma Assert
(Result
/= FUNC_ERR
);
1105 if Result
= FUNC_ERR
then
1106 raise Storage_Error
; -- Insufficient resources
1108 end Initialize_Athread_Library
;
1110 end System
.Task_Primitives
.Operations
;