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-2023, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 -- This is a HP-UX DCE threads (HPUX 10) version of this package
34 -- This package contains all the GNULL primitives that interface directly with
37 with Ada
.Unchecked_Conversion
;
41 with System
.Tasking
.Debug
;
42 with System
.Interrupt_Management
;
43 with System
.OS_Constants
;
44 with System
.OS_Primitives
;
45 with System
.Task_Primitives
.Interrupt_Operations
;
47 pragma Warnings
(Off
);
48 with System
.Interrupt_Management
.Operations
;
49 pragma Elaborate_All
(System
.Interrupt_Management
.Operations
);
52 with System
.Soft_Links
;
53 -- We use System.Soft_Links instead of System.Tasking.Initialization
54 -- because the later is a higher level package that we shouldn't depend on.
55 -- For example when using the restricted run time, it is replaced by
56 -- System.Tasking.Restricted.Stages.
58 package body System
.Task_Primitives
.Operations
is
60 package OSC
renames System
.OS_Constants
;
61 package SSL
renames System
.Soft_Links
;
63 use System
.Tasking
.Debug
;
66 use System
.OS_Interface
;
67 use System
.Parameters
;
68 use System
.OS_Primitives
;
70 package PIO
renames System
.Task_Primitives
.Interrupt_Operations
;
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 to protect All_Tasks_List
84 Environment_Task_Id
: Task_Id
;
85 -- A variable to hold Task_Id for the environment task
87 Unblocked_Signal_Mask
: aliased sigset_t
;
88 -- The set of signals that should unblocked in all tasks
90 Time_Slice_Val
: constant Integer;
91 pragma Import
(C
, Time_Slice_Val
, "__gl_time_slice_val");
93 Dispatching_Policy
: constant Character;
94 pragma Import
(C
, Dispatching_Policy
, "__gl_task_dispatching_policy");
96 -- Note: the reason that Locking_Policy is not needed is that this
97 -- is not implemented for DCE threads. The HPUX 10 port is at this
98 -- stage considered dead, and no further work is planned on it.
100 Foreign_Task_Elaborated
: aliased Boolean := True;
101 -- Used to identified fake tasks (i.e., non-Ada Threads)
109 procedure Initialize
(Environment_Task
: Task_Id
);
110 pragma Inline
(Initialize
);
111 -- Initialize various data needed by this package
113 function Is_Valid_Task
return Boolean;
114 pragma Inline
(Is_Valid_Task
);
115 -- Does the executing thread have a TCB?
117 procedure Set
(Self_Id
: Task_Id
);
119 -- Set the self id for the current task
121 function Self
return Task_Id
;
122 pragma Inline
(Self
);
123 -- Return a pointer to the Ada Task Control Block of the calling task
127 package body Specific
is separate;
128 -- The body of this package is target specific
130 ----------------------------------
131 -- ATCB allocation/deallocation --
132 ----------------------------------
134 package body ATCB_Allocation
is separate;
135 -- The body of this package is shared across several targets
137 ---------------------------------
138 -- Support for foreign threads --
139 ---------------------------------
141 function Register_Foreign_Thread
(Thread
: Thread_Id
) return Task_Id
;
142 -- Allocate and Initialize a new ATCB for the current Thread
144 function Register_Foreign_Thread
145 (Thread
: Thread_Id
) return Task_Id
is separate;
147 -----------------------
148 -- Local Subprograms --
149 -----------------------
151 procedure Abort_Handler
(Sig
: Signal
);
153 function To_Address
is
154 new Ada
.Unchecked_Conversion
(Task_Id
, System
.Address
);
160 procedure Abort_Handler
(Sig
: Signal
) is
161 pragma Unreferenced
(Sig
);
163 Self_Id
: constant Task_Id
:= Self
;
164 Result
: Interfaces
.C
.int
;
165 Old_Set
: aliased sigset_t
;
168 if Self_Id
.Deferral_Level
= 0
169 and then Self_Id
.Pending_ATC_Level
< Self_Id
.ATC_Nesting_Level
170 and then not Self_Id
.Aborting
172 Self_Id
.Aborting
:= True;
174 -- Make sure signals used for RTS internal purpose are unmasked
179 Unblocked_Signal_Mask
'Access,
181 pragma Assert
(Result
= 0);
183 raise Standard
'Abort_Signal;
191 -- The underlying thread system sets a guard page at the bottom of a thread
192 -- stack, so nothing is needed.
193 -- ??? Check the comment above
195 procedure Stack_Guard
(T
: ST
.Task_Id
; On
: Boolean) is
196 pragma Unreferenced
(T
, On
);
205 function Get_Thread_Id
(T
: ST
.Task_Id
) return OSI
.Thread_Id
is
207 return T
.Common
.LL
.Thread
;
214 function Self
return Task_Id
renames Specific
.Self
;
216 ---------------------
217 -- Initialize_Lock --
218 ---------------------
220 -- Note: mutexes and cond_variables needed per-task basis are initialized
221 -- in Initialize_TCB and the Storage_Error is handled. Other mutexes (such
222 -- as RTS_Lock, Memory_Lock...) used in RTS is initialized before any
223 -- status change of RTS. Therefore raising Storage_Error in the following
224 -- routines should be able to be handled safely.
226 procedure Initialize_Lock
227 (Prio
: System
.Any_Priority
;
228 L
: not null access Lock
)
230 Attributes
: aliased pthread_mutexattr_t
;
231 Result
: Interfaces
.C
.int
;
234 Result
:= pthread_mutexattr_init
(Attributes
'Access);
235 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
237 if Result
= ENOMEM
then
243 Result
:= pthread_mutex_init
(L
.L
'Access, Attributes
'Access);
244 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
246 if Result
= ENOMEM
then
250 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
251 pragma Assert
(Result
= 0);
254 procedure Initialize_Lock
255 (L
: not null access RTS_Lock
;
258 pragma Unreferenced
(Level
);
260 Attributes
: aliased pthread_mutexattr_t
;
261 Result
: Interfaces
.C
.int
;
264 Result
:= pthread_mutexattr_init
(Attributes
'Access);
265 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
267 if Result
= ENOMEM
then
271 Result
:= pthread_mutex_init
(L
, Attributes
'Access);
273 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
275 if Result
= ENOMEM
then
279 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
280 pragma Assert
(Result
= 0);
287 procedure Finalize_Lock
(L
: not null access Lock
) is
288 Result
: Interfaces
.C
.int
;
290 Result
:= pthread_mutex_destroy
(L
.L
'Access);
291 pragma Assert
(Result
= 0);
294 procedure Finalize_Lock
(L
: not null access RTS_Lock
) is
295 Result
: Interfaces
.C
.int
;
297 Result
:= pthread_mutex_destroy
(L
);
298 pragma Assert
(Result
= 0);
306 (L
: not null access Lock
;
307 Ceiling_Violation
: out Boolean)
309 Result
: Interfaces
.C
.int
;
312 L
.Owner_Priority
:= Get_Priority
(Self
);
314 if L
.Priority
< L
.Owner_Priority
then
315 Ceiling_Violation
:= True;
319 Result
:= pthread_mutex_lock
(L
.L
'Access);
320 pragma Assert
(Result
= 0);
321 Ceiling_Violation
:= False;
324 procedure Write_Lock
(L
: not null access RTS_Lock
) is
325 Result
: Interfaces
.C
.int
;
327 Result
:= pthread_mutex_lock
(L
);
328 pragma Assert
(Result
= 0);
331 procedure Write_Lock
(T
: Task_Id
) is
332 Result
: Interfaces
.C
.int
;
334 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
335 pragma Assert
(Result
= 0);
343 (L
: not null access Lock
;
344 Ceiling_Violation
: out Boolean)
347 Write_Lock
(L
, Ceiling_Violation
);
354 procedure Unlock
(L
: not null access Lock
) is
355 Result
: Interfaces
.C
.int
;
357 Result
:= pthread_mutex_unlock
(L
.L
'Access);
358 pragma Assert
(Result
= 0);
361 procedure Unlock
(L
: not null access RTS_Lock
) is
362 Result
: Interfaces
.C
.int
;
364 Result
:= pthread_mutex_unlock
(L
);
365 pragma Assert
(Result
= 0);
368 procedure Unlock
(T
: Task_Id
) is
369 Result
: Interfaces
.C
.int
;
371 Result
:= pthread_mutex_unlock
(T
.Common
.LL
.L
'Access);
372 pragma Assert
(Result
= 0);
379 -- Dynamic priority ceilings are not supported by the underlying system
381 procedure Set_Ceiling
382 (L
: not null access Lock
;
383 Prio
: System
.Any_Priority
)
385 pragma Unreferenced
(L
, Prio
);
396 Reason
: System
.Tasking
.Task_States
)
398 pragma Unreferenced
(Reason
);
400 Result
: Interfaces
.C
.int
;
405 (cond
=> Self_ID
.Common
.LL
.CV
'Access,
406 mutex
=> Self_ID
.Common
.LL
.L
'Access);
408 -- EINTR is not considered a failure
410 pragma Assert
(Result
= 0 or else Result
= EINTR
);
417 procedure Timed_Sleep
420 Mode
: ST
.Delay_Modes
;
421 Reason
: System
.Tasking
.Task_States
;
422 Timedout
: out Boolean;
423 Yielded
: out Boolean)
425 pragma Unreferenced
(Reason
);
427 Check_Time
: constant Duration := Monotonic_Clock
;
429 Request
: aliased timespec
;
430 Result
: Interfaces
.C
.int
;
438 then Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
439 else Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
));
441 if Abs_Time
> Check_Time
then
442 Request
:= To_Timespec
(Abs_Time
);
445 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
448 pthread_cond_timedwait
449 (cond
=> Self_ID
.Common
.LL
.CV
'Access,
450 mutex
=> Self_ID
.Common
.LL
.L
'Access,
451 abstime
=> Request
'Access);
453 exit when Abs_Time
<= Monotonic_Clock
;
455 if Result
= 0 or Result
= EINTR
then
457 -- Somebody may have called Wakeup for us
463 pragma Assert
(Result
= ETIMEDOUT
);
472 procedure Timed_Delay
475 Mode
: ST
.Delay_Modes
)
477 Check_Time
: constant Duration := Monotonic_Clock
;
479 Request
: aliased timespec
;
481 Result
: Interfaces
.C
.int
;
482 pragma Warnings
(Off
, Result
);
485 Write_Lock
(Self_ID
);
489 then Time
+ Check_Time
490 else Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
));
492 if Abs_Time
> Check_Time
then
493 Request
:= To_Timespec
(Abs_Time
);
494 Self_ID
.Common
.State
:= Delay_Sleep
;
497 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
500 pthread_cond_timedwait
501 (cond
=> Self_ID
.Common
.LL
.CV
'Access,
502 mutex
=> Self_ID
.Common
.LL
.L
'Access,
503 abstime
=> Request
'Access);
505 exit when Abs_Time
<= Monotonic_Clock
;
507 pragma Assert
(Result
= 0 or else
508 Result
= ETIMEDOUT
or else
512 Self_ID
.Common
.State
:= Runnable
;
516 Result
:= sched_yield
;
519 ---------------------
520 -- Monotonic_Clock --
521 ---------------------
523 function Monotonic_Clock
return Duration is
524 TS
: aliased timespec
;
525 Result
: Interfaces
.C
.int
;
527 Result
:= Clock_Gettime
(OSC
.CLOCK_RT_Ada
, TS
'Unchecked_Access);
528 pragma Assert
(Result
= 0);
529 return To_Duration
(TS
);
536 function RT_Resolution
return Duration is
545 procedure Wakeup
(T
: Task_Id
; Reason
: System
.Tasking
.Task_States
) is
546 pragma Unreferenced
(Reason
);
547 Result
: Interfaces
.C
.int
;
549 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
550 pragma Assert
(Result
= 0);
557 procedure Yield
(Do_Yield
: Boolean := True) is
558 Result
: Interfaces
.C
.int
;
559 pragma Unreferenced
(Result
);
562 Result
:= sched_yield
;
570 type Prio_Array_Type
is array (System
.Any_Priority
) of Integer;
571 pragma Atomic_Components
(Prio_Array_Type
);
573 Prio_Array
: Prio_Array_Type
;
574 -- Global array containing the id of the currently running task for
577 -- Note: assume we are on single processor with run-til-blocked scheduling
579 procedure Set_Priority
581 Prio
: System
.Any_Priority
;
582 Loss_Of_Inheritance
: Boolean := False)
584 Result
: Interfaces
.C
.int
;
585 Array_Item
: Integer;
586 Param
: aliased struct_sched_param
;
588 function Get_Policy
(Prio
: System
.Any_Priority
) return Character;
589 pragma Import
(C
, Get_Policy
, "__gnat_get_specific_dispatching");
590 -- Get priority specific dispatching policy
592 Priority_Specific_Policy
: constant Character := Get_Policy
(Prio
);
593 -- Upper case first character of the policy name corresponding to the
594 -- task as set by a Priority_Specific_Dispatching pragma.
597 Param
.sched_priority
:= Interfaces
.C
.int
(Underlying_Priorities
(Prio
));
599 if Dispatching_Policy
= 'R'
600 or else Priority_Specific_Policy
= 'R'
601 or else Time_Slice_Val
> 0
604 pthread_setschedparam
605 (T
.Common
.LL
.Thread
, SCHED_RR
, Param
'Access);
607 elsif Dispatching_Policy
= 'F'
608 or else Priority_Specific_Policy
= 'F'
609 or else Time_Slice_Val
= 0
612 pthread_setschedparam
613 (T
.Common
.LL
.Thread
, SCHED_FIFO
, Param
'Access);
617 pthread_setschedparam
618 (T
.Common
.LL
.Thread
, SCHED_OTHER
, Param
'Access);
621 pragma Assert
(Result
= 0);
623 if Dispatching_Policy
= 'F' or else Priority_Specific_Policy
= 'F' then
625 -- Annex D requirement [RM D.2.2 par. 9]:
626 -- If the task drops its priority due to the loss of inherited
627 -- priority, it is added at the head of the ready queue for its
628 -- new active priority.
630 if Loss_Of_Inheritance
631 and then Prio
< T
.Common
.Current_Priority
633 Array_Item
:= Prio_Array
(T
.Common
.Base_Priority
) + 1;
634 Prio_Array
(T
.Common
.Base_Priority
) := Array_Item
;
637 -- Let some processes a chance to arrive
641 -- Then wait for our turn to proceed
643 exit when Array_Item
= Prio_Array
(T
.Common
.Base_Priority
)
644 or else Prio_Array
(T
.Common
.Base_Priority
) = 1;
647 Prio_Array
(T
.Common
.Base_Priority
) :=
648 Prio_Array
(T
.Common
.Base_Priority
) - 1;
652 T
.Common
.Current_Priority
:= Prio
;
659 function Get_Priority
(T
: Task_Id
) return System
.Any_Priority
is
661 return T
.Common
.Current_Priority
;
668 procedure Enter_Task
(Self_ID
: Task_Id
) is
670 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
671 Specific
.Set
(Self_ID
);
678 function Is_Valid_Task
return Boolean renames Specific
.Is_Valid_Task
;
680 -----------------------------
681 -- Register_Foreign_Thread --
682 -----------------------------
684 function Register_Foreign_Thread
return Task_Id
is
686 if Is_Valid_Task
then
689 return Register_Foreign_Thread
(pthread_self
);
691 end Register_Foreign_Thread
;
697 procedure Initialize_TCB
(Self_ID
: Task_Id
; Succeeded
: out Boolean) is
698 Mutex_Attr
: aliased pthread_mutexattr_t
;
699 Result
: Interfaces
.C
.int
;
700 Cond_Attr
: aliased pthread_condattr_t
;
703 Result
:= pthread_mutexattr_init
(Mutex_Attr
'Access);
704 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
709 (Self_ID
.Common
.LL
.L
'Access, Mutex_Attr
'Access);
710 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
718 Result
:= pthread_mutexattr_destroy
(Mutex_Attr
'Access);
719 pragma Assert
(Result
= 0);
721 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
722 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
727 (Self_ID
.Common
.LL
.CV
'Access,
729 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
735 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
736 pragma Assert
(Result
= 0);
741 Result
:= pthread_condattr_destroy
(Cond_Attr
'Access);
742 pragma Assert
(Result
= 0);
749 procedure Create_Task
751 Wrapper
: System
.Address
;
752 Stack_Size
: System
.Parameters
.Size_Type
;
753 Priority
: System
.Any_Priority
;
754 Succeeded
: out Boolean)
756 Attributes
: aliased pthread_attr_t
;
757 Result
: Interfaces
.C
.int
;
759 function Thread_Body_Access
is new
760 Ada
.Unchecked_Conversion
(System
.Address
, Thread_Body
);
763 Result
:= pthread_attr_init
(Attributes
'Access);
764 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
771 Result
:= pthread_attr_setstacksize
772 (Attributes
'Access, Interfaces
.C
.size_t
(Stack_Size
));
773 pragma Assert
(Result
= 0);
775 -- Since the initial signal mask of a thread is inherited from the
776 -- creator, and the Environment task has all its signals masked, we
777 -- do not need to manipulate caller's signal mask at this point.
778 -- All tasks in RTS will have All_Tasks_Mask initially.
780 Result
:= pthread_create
781 (T
.Common
.LL
.Thread
'Access,
783 Thread_Body_Access
(Wrapper
),
785 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
787 Succeeded
:= Result
= 0;
789 pthread_detach
(T
.Common
.LL
.Thread
'Access);
790 -- Detach the thread using pthread_detach, since DCE threads do not have
791 -- pthread_attr_set_detachstate.
793 Result
:= pthread_attr_destroy
(Attributes
'Access);
794 pragma Assert
(Result
= 0);
796 Set_Priority
(T
, Priority
);
803 procedure Finalize_TCB
(T
: Task_Id
) is
804 Result
: Interfaces
.C
.int
;
807 Result
:= pthread_mutex_destroy
(T
.Common
.LL
.L
'Access);
808 pragma Assert
(Result
= 0);
810 Result
:= pthread_cond_destroy
(T
.Common
.LL
.CV
'Access);
811 pragma Assert
(Result
= 0);
813 if T
.Known_Tasks_Index
/= -1 then
814 Known_Tasks
(T
.Known_Tasks_Index
) := null;
817 ATCB_Allocation
.Free_ATCB
(T
);
824 procedure Exit_Task
is
833 procedure Abort_Task
(T
: Task_Id
) is
835 -- Interrupt Server_Tasks may be waiting on an "event" flag (signal)
837 if T
.Common
.State
= Interrupt_Server_Blocked_On_Event_Flag
then
838 System
.Interrupt_Management
.Operations
.Interrupt_Self_Process
839 (PIO
.Get_Interrupt_ID
(T
));
847 procedure Initialize
(S
: in out Suspension_Object
) is
848 Mutex_Attr
: aliased pthread_mutexattr_t
;
849 Cond_Attr
: aliased pthread_condattr_t
;
850 Result
: Interfaces
.C
.int
;
852 -- Initialize internal state (always to False (ARM D.10(6)))
857 -- Initialize internal mutex
859 Result
:= pthread_mutex_init
(S
.L
'Access, Mutex_Attr
'Access);
860 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
862 if Result
= ENOMEM
then
866 -- Initialize internal condition variable
868 Result
:= pthread_cond_init
(S
.CV
'Access, Cond_Attr
'Access);
869 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
872 Result
:= pthread_mutex_destroy
(S
.L
'Access);
873 pragma Assert
(Result
= 0);
875 if Result
= ENOMEM
then
885 procedure Finalize
(S
: in out Suspension_Object
) is
886 Result
: Interfaces
.C
.int
;
889 -- Destroy internal mutex
891 Result
:= pthread_mutex_destroy
(S
.L
'Access);
892 pragma Assert
(Result
= 0);
894 -- Destroy internal condition variable
896 Result
:= pthread_cond_destroy
(S
.CV
'Access);
897 pragma Assert
(Result
= 0);
904 function Current_State
(S
: Suspension_Object
) return Boolean is
906 -- We do not want to use lock on this read operation. State is marked
907 -- as Atomic so that we ensure that the value retrieved is correct.
916 procedure Set_False
(S
: in out Suspension_Object
) is
917 Result
: Interfaces
.C
.int
;
922 Result
:= pthread_mutex_lock
(S
.L
'Access);
923 pragma Assert
(Result
= 0);
927 Result
:= pthread_mutex_unlock
(S
.L
'Access);
928 pragma Assert
(Result
= 0);
930 SSL
.Abort_Undefer
.all;
937 procedure Set_True
(S
: in out Suspension_Object
) is
938 Result
: Interfaces
.C
.int
;
943 Result
:= pthread_mutex_lock
(S
.L
'Access);
944 pragma Assert
(Result
= 0);
946 -- If there is already a task waiting on this suspension object then
947 -- we resume it, leaving the state of the suspension object to False,
948 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
949 -- the state to True.
955 Result
:= pthread_cond_signal
(S
.CV
'Access);
956 pragma Assert
(Result
= 0);
962 Result
:= pthread_mutex_unlock
(S
.L
'Access);
963 pragma Assert
(Result
= 0);
965 SSL
.Abort_Undefer
.all;
968 ------------------------
969 -- Suspend_Until_True --
970 ------------------------
972 procedure Suspend_Until_True
(S
: in out Suspension_Object
) is
973 Result
: Interfaces
.C
.int
;
978 Result
:= pthread_mutex_lock
(S
.L
'Access);
979 pragma Assert
(Result
= 0);
982 -- Program_Error must be raised upon calling Suspend_Until_True
983 -- if another task is already waiting on that suspension object
984 -- (ARM D.10 par. 10).
986 Result
:= pthread_mutex_unlock
(S
.L
'Access);
987 pragma Assert
(Result
= 0);
989 SSL
.Abort_Undefer
.all;
993 -- Suspend the task if the state is False. Otherwise, the task
994 -- continues its execution, and the state of the suspension object
995 -- is set to False (ARM D.10 par. 9).
1003 -- Loop in case pthread_cond_wait returns earlier than expected
1004 -- (e.g. in case of EINTR caused by a signal).
1006 Result
:= pthread_cond_wait
(S
.CV
'Access, S
.L
'Access);
1007 pragma Assert
(Result
= 0 or else Result
= EINTR
);
1009 exit when not S
.Waiting
;
1013 Result
:= pthread_mutex_unlock
(S
.L
'Access);
1014 pragma Assert
(Result
= 0);
1016 SSL
.Abort_Undefer
.all;
1018 end Suspend_Until_True
;
1026 function Check_Exit
(Self_ID
: ST
.Task_Id
) return Boolean is
1027 pragma Unreferenced
(Self_ID
);
1032 --------------------
1033 -- Check_No_Locks --
1034 --------------------
1036 function Check_No_Locks
(Self_ID
: ST
.Task_Id
) return Boolean is
1037 pragma Unreferenced
(Self_ID
);
1042 ----------------------
1043 -- Environment_Task --
1044 ----------------------
1046 function Environment_Task
return Task_Id
is
1048 return Environment_Task_Id
;
1049 end Environment_Task
;
1055 procedure Lock_RTS
is
1057 Write_Lock
(Single_RTS_Lock
'Access);
1064 procedure Unlock_RTS
is
1066 Unlock
(Single_RTS_Lock
'Access);
1073 function Suspend_Task
1075 Thread_Self
: Thread_Id
) return Boolean
1077 pragma Unreferenced
(T
);
1078 pragma Unreferenced
(Thread_Self
);
1087 function Resume_Task
1089 Thread_Self
: Thread_Id
) return Boolean
1091 pragma Unreferenced
(T
);
1092 pragma Unreferenced
(Thread_Self
);
1097 --------------------
1098 -- Stop_All_Tasks --
1099 --------------------
1101 procedure Stop_All_Tasks
is
1110 function Stop_Task
(T
: ST
.Task_Id
) return Boolean is
1111 pragma Unreferenced
(T
);
1120 function Continue_Task
(T
: ST
.Task_Id
) return Boolean is
1121 pragma Unreferenced
(T
);
1130 procedure Initialize
(Environment_Task
: Task_Id
) is
1131 act
: aliased struct_sigaction
;
1132 old_act
: aliased struct_sigaction
;
1133 Tmp_Set
: aliased sigset_t
;
1134 Result
: Interfaces
.C
.int
;
1137 (Int
: System
.Interrupt_Management
.Interrupt_ID
) return Character;
1138 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
1139 -- Get interrupt state. Defined in a-init.c. The input argument is
1140 -- the interrupt number, and the result is one of the following:
1142 Default
: constant Character := 's';
1143 -- 'n' this interrupt not set by any Interrupt_State pragma
1144 -- 'u' Interrupt_State pragma set state to User
1145 -- 'r' Interrupt_State pragma set state to Runtime
1146 -- 's' Interrupt_State pragma set state to System (use "default"
1150 Environment_Task_Id
:= Environment_Task
;
1152 Interrupt_Management
.Initialize
;
1154 -- Initialize the lock used to synchronize chain of all ATCBs
1156 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
1158 Specific
.Initialize
(Environment_Task
);
1160 -- Make environment task known here because it doesn't go through
1161 -- Activate_Tasks, which does it for all other tasks.
1163 Known_Tasks
(Known_Tasks
'First) := Environment_Task
;
1164 Environment_Task
.Known_Tasks_Index
:= Known_Tasks
'First;
1166 Enter_Task
(Environment_Task
);
1168 -- Install the abort-signal handler
1170 if State
(System
.Interrupt_Management
.Abort_Task_Interrupt
)
1174 act
.sa_handler
:= Abort_Handler
'Address;
1176 Result
:= sigemptyset
(Tmp_Set
'Access);
1177 pragma Assert
(Result
= 0);
1178 act
.sa_mask
:= Tmp_Set
;
1182 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
),
1183 act
'Unchecked_Access,
1184 old_act
'Unchecked_Access);
1185 pragma Assert
(Result
= 0);
1189 -- NOTE: Unlike other pthread implementations, we do *not* mask all
1190 -- signals here since we handle signals using the process-wide primitive
1191 -- signal, rather than using sigthreadmask and sigwait. The reason of
1192 -- this difference is that sigwait doesn't work when some critical
1193 -- signals (SIGABRT, SIGPIPE) are masked.
1195 -----------------------
1196 -- Set_Task_Affinity --
1197 -----------------------
1199 procedure Set_Task_Affinity
(T
: ST
.Task_Id
) is
1200 pragma Unreferenced
(T
);
1203 -- Setting task affinity is not supported by the underlying system
1206 end Set_Task_Affinity
;
1208 end System
.Task_Primitives
.Operations
;