1 ------------------------------------------------------------------------------
3 -- GNU ADA 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 a GNU/Linux (GNU/LinuxThreads) 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
.Parameters
;
50 with System
.Tasking
.Debug
;
51 -- used for Known_Tasks
53 with System
.Interrupt_Management
;
54 -- used for Keep_Unmasked
55 -- Abort_Task_Interrupt
58 with System
.OS_Primitives
;
59 -- used for Delay_Modes
61 with System
.Soft_Links
;
62 -- used for Abort_Defer/Undefer
65 -- used for Raise_Exception
66 -- Raise_From_Signal_Handler
69 with Unchecked_Conversion
;
70 with Unchecked_Deallocation
;
72 package body System
.Task_Primitives
.Operations
is
74 use System
.Tasking
.Debug
;
77 use System
.OS_Interface
;
78 use System
.Parameters
;
79 use System
.OS_Primitives
;
85 -- The followings are logically constants, but need to be initialized
88 Single_RTS_Lock
: aliased RTS_Lock
;
89 -- This is a lock to allow only one thread of control in the RTS at
90 -- a time; it is used to execute in mutual exclusion from all other tasks.
91 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
93 ATCB_Key
: aliased pthread_key_t
;
94 -- Key used to find the Ada Task_Id associated with a thread
96 Environment_Task_Id
: Task_Id
;
97 -- A variable to hold Task_Id for the environment task
99 Unblocked_Signal_Mask
: aliased sigset_t
;
100 -- The set of signals that should be unblocked in all tasks
102 -- The followings are internal configuration constants needed
104 Next_Serial_Number
: Task_Serial_Number
:= 100;
105 -- We start at 100, to reserve some special values for
106 -- using in error checking.
108 Time_Slice_Val
: Integer;
109 pragma Import
(C
, Time_Slice_Val
, "__gl_time_slice_val");
111 Dispatching_Policy
: Character;
112 pragma Import
(C
, Dispatching_Policy
, "__gl_task_dispatching_policy");
114 -- The following are effectively constants, but they need to
115 -- be initialized by calling a pthread_ function.
117 Mutex_Attr
: aliased pthread_mutexattr_t
;
118 Cond_Attr
: aliased pthread_condattr_t
;
120 Foreign_Task_Elaborated
: aliased Boolean := True;
121 -- Used to identified fake tasks (i.e., non-Ada Threads)
129 procedure Initialize
(Environment_Task
: Task_Id
);
130 pragma Inline
(Initialize
);
131 -- Initialize various data needed by this package
133 function Is_Valid_Task
return Boolean;
134 pragma Inline
(Is_Valid_Task
);
135 -- Does executing thread have a TCB?
137 procedure Set
(Self_Id
: Task_Id
);
139 -- Set the self id for the current task
141 function Self
return Task_Id
;
142 pragma Inline
(Self
);
143 -- Return a pointer to the Ada Task Control Block of the calling task.
147 package body Specific
is separate;
148 -- The body of this package is target specific
150 ---------------------------------
151 -- Support for foreign threads --
152 ---------------------------------
154 function Register_Foreign_Thread
(Thread
: Thread_Id
) return Task_Id
;
155 -- Allocate and Initialize a new ATCB for the current Thread
157 function Register_Foreign_Thread
158 (Thread
: Thread_Id
) return Task_Id
is separate;
160 -----------------------
161 -- Local Subprograms --
162 -----------------------
164 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
166 procedure Abort_Handler
(signo
: Signal
);
168 function To_pthread_t
is new Unchecked_Conversion
169 (unsigned_long
, System
.OS_Interface
.pthread_t
);
175 procedure Abort_Handler
(signo
: Signal
) is
176 pragma Unreferenced
(signo
);
178 Self_Id
: constant Task_Id
:= Self
;
179 Result
: Interfaces
.C
.int
;
180 Old_Set
: aliased sigset_t
;
183 if ZCX_By_Default
and then GCC_ZCX_Support
then
187 if Self_Id
.Deferral_Level
= 0
188 and then Self_Id
.Pending_ATC_Level
< Self_Id
.ATC_Nesting_Level
189 and then not Self_Id
.Aborting
191 Self_Id
.Aborting
:= True;
193 -- Make sure signals used for RTS internal purpose are unmasked
195 Result
:= pthread_sigmask
(SIG_UNBLOCK
,
196 Unblocked_Signal_Mask
'Unchecked_Access, Old_Set
'Unchecked_Access);
197 pragma Assert
(Result
= 0);
199 raise Standard
'Abort_Signal;
207 procedure Lock_RTS
is
209 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
216 procedure Unlock_RTS
is
218 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
225 -- The underlying thread system extends the memory (up to 2MB) when needed
227 procedure Stack_Guard
(T
: ST
.Task_Id
; On
: Boolean) is
228 pragma Unreferenced
(T
);
229 pragma Unreferenced
(On
);
238 function Get_Thread_Id
(T
: ST
.Task_Id
) return OSI
.Thread_Id
is
240 return T
.Common
.LL
.Thread
;
247 function Self
return Task_Id
renames Specific
.Self
;
249 ---------------------
250 -- Initialize_Lock --
251 ---------------------
253 -- Note: mutexes and cond_variables needed per-task basis are
254 -- initialized in Initialize_TCB and the Storage_Error is
255 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
256 -- used in RTS is initialized before any status change of RTS.
257 -- Therefore rasing Storage_Error in the following routines
258 -- should be able to be handled safely.
260 procedure Initialize_Lock
261 (Prio
: System
.Any_Priority
;
264 pragma Unreferenced
(Prio
);
266 Result
: Interfaces
.C
.int
;
268 Result
:= pthread_mutex_init
(L
, Mutex_Attr
'Access);
270 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
272 if Result
= ENOMEM
then
273 Ada
.Exceptions
.Raise_Exception
(Storage_Error
'Identity,
274 "Failed to allocate a lock");
278 procedure Initialize_Lock
(L
: access RTS_Lock
; Level
: Lock_Level
) is
279 pragma Unreferenced
(Level
);
281 Result
: Interfaces
.C
.int
;
284 Result
:= pthread_mutex_init
(L
, Mutex_Attr
'Access);
286 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
288 if Result
= ENOMEM
then
297 procedure Finalize_Lock
(L
: access Lock
) is
298 Result
: Interfaces
.C
.int
;
300 Result
:= pthread_mutex_destroy
(L
);
301 pragma Assert
(Result
= 0);
304 procedure Finalize_Lock
(L
: access RTS_Lock
) is
305 Result
: Interfaces
.C
.int
;
307 Result
:= pthread_mutex_destroy
(L
);
308 pragma Assert
(Result
= 0);
315 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
316 Result
: Interfaces
.C
.int
;
318 Result
:= pthread_mutex_lock
(L
);
319 Ceiling_Violation
:= Result
= EINVAL
;
321 -- Assume the cause of EINVAL is a priority ceiling violation
323 pragma Assert
(Result
= 0 or else Result
= EINVAL
);
327 (L
: access RTS_Lock
;
328 Global_Lock
: Boolean := False)
330 Result
: Interfaces
.C
.int
;
332 if not Single_Lock
or else Global_Lock
then
333 Result
:= pthread_mutex_lock
(L
);
334 pragma Assert
(Result
= 0);
338 procedure Write_Lock
(T
: Task_Id
) is
339 Result
: Interfaces
.C
.int
;
341 if not Single_Lock
then
342 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
343 pragma Assert
(Result
= 0);
351 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
353 Write_Lock
(L
, Ceiling_Violation
);
360 procedure Unlock
(L
: access Lock
) is
361 Result
: Interfaces
.C
.int
;
363 Result
:= pthread_mutex_unlock
(L
);
364 pragma Assert
(Result
= 0);
367 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
368 Result
: Interfaces
.C
.int
;
370 if not Single_Lock
or else Global_Lock
then
371 Result
:= pthread_mutex_unlock
(L
);
372 pragma Assert
(Result
= 0);
376 procedure Unlock
(T
: Task_Id
) is
377 Result
: Interfaces
.C
.int
;
379 if not Single_Lock
then
380 Result
:= pthread_mutex_unlock
(T
.Common
.LL
.L
'Access);
381 pragma Assert
(Result
= 0);
391 Reason
: System
.Tasking
.Task_States
)
393 pragma Unreferenced
(Reason
);
395 Result
: Interfaces
.C
.int
;
398 pragma Assert
(Self_ID
= Self
);
401 Result
:= pthread_cond_wait
402 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access);
404 Result
:= pthread_cond_wait
405 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access);
408 -- EINTR is not considered a failure
410 pragma Assert
(Result
= 0 or else Result
= EINTR
);
417 -- This is for use within the run-time system, so abort is
418 -- assumed to be already deferred, and the caller should be
419 -- holding its own ATCB lock.
421 procedure Timed_Sleep
424 Mode
: ST
.Delay_Modes
;
425 Reason
: System
.Tasking
.Task_States
;
426 Timedout
: out Boolean;
427 Yielded
: out Boolean)
429 pragma Unreferenced
(Reason
);
431 Check_Time
: constant Duration := Monotonic_Clock
;
433 Request
: aliased timespec
;
434 Result
: Interfaces
.C
.int
;
440 if Mode
= Relative
then
441 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
443 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
446 if Abs_Time
> Check_Time
then
447 Request
:= To_Timespec
(Abs_Time
);
450 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
451 or else Self_ID
.Pending_Priority_Change
;
454 Result
:= pthread_cond_timedwait
455 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access,
459 Result
:= pthread_cond_timedwait
460 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access,
464 exit when Abs_Time
<= Monotonic_Clock
;
466 if Result
= 0 or Result
= EINTR
then
467 -- somebody may have called Wakeup for us
472 pragma Assert
(Result
= ETIMEDOUT
);
481 -- This is for use in implementing delay statements, so
482 -- we assume the caller is abort-deferred but is holding
485 procedure Timed_Delay
488 Mode
: ST
.Delay_Modes
)
490 Check_Time
: constant Duration := Monotonic_Clock
;
492 Request
: aliased timespec
;
493 Result
: Interfaces
.C
.int
;
500 Write_Lock
(Self_ID
);
502 if Mode
= Relative
then
503 Abs_Time
:= Time
+ Check_Time
;
505 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
508 if Abs_Time
> Check_Time
then
509 Request
:= To_Timespec
(Abs_Time
);
510 Self_ID
.Common
.State
:= Delay_Sleep
;
513 if Self_ID
.Pending_Priority_Change
then
514 Self_ID
.Pending_Priority_Change
:= False;
515 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
516 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
519 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
522 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
523 Single_RTS_Lock
'Access, Request
'Access);
525 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
526 Self_ID
.Common
.LL
.L
'Access, Request
'Access);
529 exit when Abs_Time
<= Monotonic_Clock
;
531 pragma Assert
(Result
= 0 or else
532 Result
= ETIMEDOUT
or else
536 Self_ID
.Common
.State
:= Runnable
;
545 Result
:= sched_yield
;
548 ---------------------
549 -- Monotonic_Clock --
550 ---------------------
552 function Monotonic_Clock
return Duration is
553 TV
: aliased struct_timeval
;
554 Result
: Interfaces
.C
.int
;
556 Result
:= gettimeofday
(TV
'Access, System
.Null_Address
);
557 pragma Assert
(Result
= 0);
558 return To_Duration
(TV
);
565 function RT_Resolution
return Duration is
574 procedure Wakeup
(T
: Task_Id
; Reason
: System
.Tasking
.Task_States
) is
575 pragma Unreferenced
(Reason
);
576 Result
: Interfaces
.C
.int
;
578 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
579 pragma Assert
(Result
= 0);
586 procedure Yield
(Do_Yield
: Boolean := True) is
587 Result
: Interfaces
.C
.int
;
588 pragma Unreferenced
(Result
);
591 Result
:= sched_yield
;
599 procedure Set_Priority
601 Prio
: System
.Any_Priority
;
602 Loss_Of_Inheritance
: Boolean := False)
604 pragma Unreferenced
(Loss_Of_Inheritance
);
606 Result
: Interfaces
.C
.int
;
607 Param
: aliased struct_sched_param
;
610 T
.Common
.Current_Priority
:= Prio
;
612 -- Priorities are in range 1 .. 99 on GNU/Linux, so we map
613 -- map 0 .. 31 to 1 .. 32
615 Param
.sched_priority
:= Interfaces
.C
.int
(Prio
) + 1;
617 if Time_Slice_Val
> 0 then
618 Result
:= pthread_setschedparam
619 (T
.Common
.LL
.Thread
, SCHED_RR
, Param
'Access);
621 elsif Dispatching_Policy
= 'F' or else Time_Slice_Val
= 0 then
622 Result
:= pthread_setschedparam
623 (T
.Common
.LL
.Thread
, SCHED_FIFO
, Param
'Access);
626 Param
.sched_priority
:= 0;
627 Result
:= pthread_setschedparam
628 (T
.Common
.LL
.Thread
, SCHED_OTHER
, Param
'Access);
631 pragma Assert
(Result
= 0 or else Result
= EPERM
);
638 function Get_Priority
(T
: Task_Id
) return System
.Any_Priority
is
640 return T
.Common
.Current_Priority
;
647 procedure Enter_Task
(Self_ID
: Task_Id
) is
649 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
651 Specific
.Set
(Self_ID
);
655 for J
in Known_Tasks
'Range loop
656 if Known_Tasks
(J
) = null then
657 Known_Tasks
(J
) := Self_ID
;
658 Self_ID
.Known_Tasks_Index
:= J
;
670 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_Id
is
672 return new Ada_Task_Control_Block
(Entry_Num
);
679 function Is_Valid_Task
return Boolean renames Specific
.Is_Valid_Task
;
681 -----------------------------
682 -- Register_Foreign_Thread --
683 -----------------------------
685 function Register_Foreign_Thread
return Task_Id
is
687 if Is_Valid_Task
then
690 return Register_Foreign_Thread
(pthread_self
);
692 end Register_Foreign_Thread
;
698 procedure Initialize_TCB
(Self_ID
: Task_Id
; Succeeded
: out Boolean) is
699 Result
: Interfaces
.C
.int
;
702 -- Give the task a unique serial number
704 Self_ID
.Serial_Number
:= Next_Serial_Number
;
705 Next_Serial_Number
:= Next_Serial_Number
+ 1;
706 pragma Assert
(Next_Serial_Number
/= 0);
708 Self_ID
.Common
.LL
.Thread
:= To_pthread_t
(-1);
710 if not Single_Lock
then
711 Result
:= pthread_mutex_init
(Self_ID
.Common
.LL
.L
'Access,
713 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
721 Result
:= pthread_cond_init
(Self_ID
.Common
.LL
.CV
'Access,
723 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
728 if not Single_Lock
then
729 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
730 pragma Assert
(Result
= 0);
741 procedure Create_Task
743 Wrapper
: System
.Address
;
744 Stack_Size
: System
.Parameters
.Size_Type
;
745 Priority
: System
.Any_Priority
;
746 Succeeded
: out Boolean)
748 Adjusted_Stack_Size
: Interfaces
.C
.size_t
;
750 Attributes
: aliased pthread_attr_t
;
751 Result
: Interfaces
.C
.int
;
754 if Stack_Size
= Unspecified_Size
then
755 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Default_Stack_Size
);
757 elsif Stack_Size
< Minimum_Stack_Size
then
758 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Minimum_Stack_Size
);
761 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Stack_Size
);
764 Result
:= pthread_attr_init
(Attributes
'Access);
765 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
773 pthread_attr_setstacksize
774 (Attributes
'Access, Adjusted_Stack_Size
);
775 pragma Assert
(Result
= 0);
778 pthread_attr_setdetachstate
779 (Attributes
'Access, PTHREAD_CREATE_DETACHED
);
780 pragma Assert
(Result
= 0);
782 -- Since the initial signal mask of a thread is inherited from the
783 -- creator, and the Environment task has all its signals masked, we
784 -- do not need to manipulate caller's signal mask at this point.
785 -- All tasks in RTS will have All_Tasks_Mask initially.
787 Result
:= pthread_create
788 (T
.Common
.LL
.Thread
'Access,
790 Thread_Body_Access
(Wrapper
),
792 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
794 Succeeded
:= Result
= 0;
796 Result
:= pthread_attr_destroy
(Attributes
'Access);
797 pragma Assert
(Result
= 0);
799 Set_Priority
(T
, Priority
);
806 procedure Finalize_TCB
(T
: Task_Id
) is
807 Result
: Interfaces
.C
.int
;
809 Is_Self
: constant Boolean := T
= Self
;
811 procedure Free
is new
812 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_Id
);
815 if not Single_Lock
then
816 Result
:= pthread_mutex_destroy
(T
.Common
.LL
.L
'Access);
817 pragma Assert
(Result
= 0);
820 Result
:= pthread_cond_destroy
(T
.Common
.LL
.CV
'Access);
821 pragma Assert
(Result
= 0);
823 if T
.Known_Tasks_Index
/= -1 then
824 Known_Tasks
(T
.Known_Tasks_Index
) := null;
838 procedure Exit_Task
is
847 procedure Abort_Task
(T
: Task_Id
) is
848 Result
: Interfaces
.C
.int
;
850 Result
:= pthread_kill
(T
.Common
.LL
.Thread
,
851 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
));
852 pragma Assert
(Result
= 0);
859 procedure Initialize
(S
: in out Suspension_Object
) is
860 Result
: Interfaces
.C
.int
;
862 -- Initialize internal state. It is always initialized to False (ARM
868 -- Initialize internal mutex
870 Result
:= pthread_mutex_init
(S
.L
'Access, Mutex_Attr
'Access);
872 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
874 if Result
= ENOMEM
then
878 -- Initialize internal condition variable
880 Result
:= pthread_cond_init
(S
.CV
'Access, Cond_Attr
'Access);
882 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
885 Result
:= pthread_mutex_destroy
(S
.L
'Access);
886 pragma Assert
(Result
= 0);
888 if Result
= ENOMEM
then
898 procedure Finalize
(S
: in out Suspension_Object
) is
899 Result
: Interfaces
.C
.int
;
901 -- Destroy internal mutex
903 Result
:= pthread_mutex_destroy
(S
.L
'Access);
904 pragma Assert
(Result
= 0);
906 -- Destroy internal condition variable
908 Result
:= pthread_cond_destroy
(S
.CV
'Access);
909 pragma Assert
(Result
= 0);
916 function Current_State
(S
: Suspension_Object
) return Boolean is
918 -- We do not want to use lock on this read operation. State is marked
919 -- as Atomic so that we ensure that the value retrieved is correct.
928 procedure Set_False
(S
: in out Suspension_Object
) is
929 Result
: Interfaces
.C
.int
;
931 Result
:= pthread_mutex_lock
(S
.L
'Access);
932 pragma Assert
(Result
= 0);
936 Result
:= pthread_mutex_unlock
(S
.L
'Access);
937 pragma Assert
(Result
= 0);
944 procedure Set_True
(S
: in out Suspension_Object
) is
945 Result
: Interfaces
.C
.int
;
947 Result
:= pthread_mutex_lock
(S
.L
'Access);
948 pragma Assert
(Result
= 0);
950 -- If there is already a task waiting on this suspension object then
951 -- we resume it, leaving the state of the suspension object to False,
952 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
953 -- the state to True.
959 Result
:= pthread_cond_signal
(S
.CV
'Access);
960 pragma Assert
(Result
= 0);
965 Result
:= pthread_mutex_unlock
(S
.L
'Access);
966 pragma Assert
(Result
= 0);
969 ------------------------
970 -- Suspend_Until_True --
971 ------------------------
973 procedure Suspend_Until_True
(S
: in out Suspension_Object
) is
974 Result
: Interfaces
.C
.int
;
976 Result
:= pthread_mutex_lock
(S
.L
'Access);
977 pragma Assert
(Result
= 0);
980 -- Program_Error must be raised upon calling Suspend_Until_True
981 -- if another task is already waiting on that suspension object
982 -- (ARM D.10 par. 10).
984 Result
:= pthread_mutex_unlock
(S
.L
'Access);
985 pragma Assert
(Result
= 0);
989 -- Suspend the task if the state is False. Otherwise, the task
990 -- continues its execution, and the state of the suspension object
991 -- is set to False (ARM D.10 par. 9).
997 Result
:= pthread_cond_wait
(S
.CV
'Access, S
.L
'Access);
1001 Result
:= pthread_mutex_unlock
(S
.L
'Access);
1002 pragma Assert
(Result
= 0);
1003 end Suspend_Until_True
;
1011 function Check_Exit
(Self_ID
: ST
.Task_Id
) return Boolean is
1012 pragma Unreferenced
(Self_ID
);
1017 --------------------
1018 -- Check_No_Locks --
1019 --------------------
1021 function Check_No_Locks
(Self_ID
: ST
.Task_Id
) return Boolean is
1022 pragma Unreferenced
(Self_ID
);
1027 ----------------------
1028 -- Environment_Task --
1029 ----------------------
1031 function Environment_Task
return Task_Id
is
1033 return Environment_Task_Id
;
1034 end Environment_Task
;
1040 function Suspend_Task
1042 Thread_Self
: Thread_Id
) return Boolean
1045 if T
.Common
.LL
.Thread
/= Thread_Self
then
1046 return pthread_kill
(T
.Common
.LL
.Thread
, SIGSTOP
) = 0;
1056 function Resume_Task
1058 Thread_Self
: Thread_Id
) return Boolean
1061 if T
.Common
.LL
.Thread
/= Thread_Self
then
1062 return pthread_kill
(T
.Common
.LL
.Thread
, SIGCONT
) = 0;
1072 procedure Initialize
(Environment_Task
: Task_Id
) is
1073 act
: aliased struct_sigaction
;
1074 old_act
: aliased struct_sigaction
;
1075 Tmp_Set
: aliased sigset_t
;
1076 Result
: Interfaces
.C
.int
;
1079 (Int
: System
.Interrupt_Management
.Interrupt_ID
) return Character;
1080 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
1081 -- Get interrupt state. Defined in a-init.c
1082 -- The input argument is the interrupt number,
1083 -- and the result is one of the following:
1085 Default
: constant Character := 's';
1086 -- 'n' this interrupt not set by any Interrupt_State pragma
1087 -- 'u' Interrupt_State pragma set state to User
1088 -- 'r' Interrupt_State pragma set state to Runtime
1089 -- 's' Interrupt_State pragma set state to System (use "default"
1093 Environment_Task_Id
:= Environment_Task
;
1095 Interrupt_Management
.Initialize
;
1097 -- Prepare the set of signals that should be unblocked in all tasks
1099 Result
:= sigemptyset
(Unblocked_Signal_Mask
'Access);
1100 pragma Assert
(Result
= 0);
1102 for J
in Interrupt_Management
.Interrupt_ID
loop
1103 if System
.Interrupt_Management
.Keep_Unmasked
(J
) then
1104 Result
:= sigaddset
(Unblocked_Signal_Mask
'Access, Signal
(J
));
1105 pragma Assert
(Result
= 0);
1109 Result
:= pthread_mutexattr_init
(Mutex_Attr
'Access);
1110 pragma Assert
(Result
= 0);
1112 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
1113 pragma Assert
(Result
= 0);
1115 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
1117 -- Initialize the global RTS lock
1119 Specific
.Initialize
(Environment_Task
);
1121 Enter_Task
(Environment_Task
);
1123 -- Install the abort-signal handler
1125 if State
(System
.Interrupt_Management
.Abort_Task_Interrupt
)
1129 act
.sa_handler
:= Abort_Handler
'Address;
1131 Result
:= sigemptyset
(Tmp_Set
'Access);
1132 pragma Assert
(Result
= 0);
1133 act
.sa_mask
:= Tmp_Set
;
1137 (Signal
(Interrupt_Management
.Abort_Task_Interrupt
),
1138 act
'Unchecked_Access,
1139 old_act
'Unchecked_Access);
1140 pragma Assert
(Result
= 0);
1144 end System
.Task_Primitives
.Operations
;