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-2004, 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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.
43 with System
.Tasking
.Debug
;
44 -- used for Known_Tasks
50 with System
.Interrupt_Management
;
51 -- used for Keep_Unmasked
52 -- Abort_Task_Interrupt
55 with System
.Interrupt_Management
.Operations
;
56 -- used for Set_Interrupt_Mask
58 pragma Elaborate_All
(System
.Interrupt_Management
.Operations
);
60 with System
.Parameters
;
64 -- used for Ada_Task_Control_Block
68 -- used for Raise_Exception
69 -- Raise_From_Signal_Handler
72 with System
.Soft_Links
;
73 -- used for Defer/Undefer_Abort
75 -- Note that we do not use System.Tasking.Initialization directly since
76 -- this is a higher level package that we shouldn't depend on. For example
77 -- when using the restricted run time, it is replaced by
78 -- System.Tasking.Restricted.Stages.
80 with System
.OS_Primitives
;
81 -- used for Delay_Modes
83 with System
.Soft_Links
;
84 -- used for Get_Machine_State_Addr
86 with Unchecked_Conversion
;
87 with Unchecked_Deallocation
;
89 package body System
.Task_Primitives
.Operations
is
91 use System
.Tasking
.Debug
;
94 use System
.OS_Interface
;
95 use System
.Parameters
;
96 use System
.OS_Primitives
;
98 package SSL
renames System
.Soft_Links
;
104 -- The followings are logically constants, but need to be initialized
107 Single_RTS_Lock
: aliased RTS_Lock
;
108 -- This is a lock to allow only one thread of control in the RTS at
109 -- a time; it is used to execute in mutual exclusion from all other tasks.
110 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
112 ATCB_Key
: aliased pthread_key_t
;
113 -- Key used to find the Ada Task_Id associated with a thread
115 Environment_Task_Id
: Task_Id
;
116 -- A variable to hold Task_Id for the environment task
118 Unblocked_Signal_Mask
: aliased sigset_t
;
119 -- The set of signals that should unblocked in all tasks
121 -- The followings are internal configuration constants needed
123 Priority_Ceiling_Emulation
: constant Boolean := True;
125 Next_Serial_Number
: Task_Serial_Number
:= 100;
126 -- We start at 100, to reserve some special values for
127 -- using in error checking.
129 Time_Slice_Val
: Integer;
130 pragma Import
(C
, Time_Slice_Val
, "__gl_time_slice_val");
132 Dispatching_Policy
: Character;
133 pragma Import
(C
, Dispatching_Policy
, "__gl_task_dispatching_policy");
135 FIFO_Within_Priorities
: constant Boolean := Dispatching_Policy
= 'F';
136 -- Indicates whether FIFO_Within_Priorities is set
138 -- The following are effectively constants, but they need to
139 -- be initialized by calling a pthread_ function.
141 Mutex_Attr
: aliased pthread_mutexattr_t
;
142 Cond_Attr
: aliased pthread_condattr_t
;
144 Foreign_Task_Elaborated
: aliased Boolean := True;
145 -- Used to identified fake tasks (i.e., non-Ada Threads)
153 procedure Initialize
(Environment_Task
: Task_Id
);
154 pragma Inline
(Initialize
);
155 -- Initialize various data needed by this package
157 function Is_Valid_Task
return Boolean;
158 pragma Inline
(Is_Valid_Task
);
159 -- Does executing thread have a TCB?
161 procedure Set
(Self_Id
: Task_Id
);
163 -- Set the self id for the current task
165 function Self
return Task_Id
;
166 pragma Inline
(Self
);
167 -- Return a pointer to the Ada Task Control Block of the calling task.
171 package body Specific
is separate;
172 -- The body of this package is target specific
174 ---------------------------------
175 -- Support for foreign threads --
176 ---------------------------------
178 function Register_Foreign_Thread
(Thread
: Thread_Id
) return Task_Id
;
179 -- Allocate and Initialize a new ATCB for the current Thread
181 function Register_Foreign_Thread
182 (Thread
: Thread_Id
) return Task_Id
is separate;
184 -----------------------
185 -- Local Subprograms --
186 -----------------------
188 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
190 procedure Abort_Handler
(signo
: Signal
);
192 function To_pthread_t
is new Unchecked_Conversion
193 (unsigned_long
, System
.OS_Interface
.pthread_t
);
199 procedure Abort_Handler
(signo
: Signal
) is
200 pragma Unreferenced
(signo
);
202 Self_Id
: constant Task_Id
:= Self
;
203 Result
: Interfaces
.C
.int
;
204 Old_Set
: aliased sigset_t
;
207 if ZCX_By_Default
and then GCC_ZCX_Support
then
211 if Self_Id
.Deferral_Level
= 0
212 and then Self_Id
.Pending_ATC_Level
< Self_Id
.ATC_Nesting_Level
213 and then not Self_Id
.Aborting
215 Self_Id
.Aborting
:= True;
217 -- Make sure signals used for RTS internal purpose are unmasked
219 Result
:= pthread_sigmask
(SIG_UNBLOCK
,
220 Unblocked_Signal_Mask
'Unchecked_Access, Old_Set
'Unchecked_Access);
221 pragma Assert
(Result
= 0);
223 raise Standard
'Abort_Signal;
231 procedure Lock_RTS
is
233 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
240 procedure Unlock_RTS
is
242 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
249 -- The underlying thread system extends the memory (up to 2MB) when needed
251 procedure Stack_Guard
(T
: ST
.Task_Id
; On
: Boolean) is
252 pragma Unreferenced
(T
);
253 pragma Unreferenced
(On
);
262 function Get_Thread_Id
(T
: ST
.Task_Id
) return OSI
.Thread_Id
is
264 return T
.Common
.LL
.Thread
;
271 function Self
return Task_Id
renames Specific
.Self
;
273 ---------------------
274 -- Initialize_Lock --
275 ---------------------
277 -- Note: mutexes and cond_variables needed per-task basis are
278 -- initialized in Initialize_TCB and the Storage_Error is
279 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
280 -- used in RTS is initialized before any status change of RTS.
281 -- Therefore rasing Storage_Error in the following routines
282 -- should be able to be handled safely.
284 procedure Initialize_Lock
285 (Prio
: System
.Any_Priority
;
288 Result
: Interfaces
.C
.int
;
291 if Priority_Ceiling_Emulation
then
295 Result
:= pthread_mutex_init
(L
.L
'Access, Mutex_Attr
'Access);
297 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
299 if Result
= ENOMEM
then
300 Ada
.Exceptions
.Raise_Exception
(Storage_Error
'Identity,
301 "Failed to allocate a lock");
305 procedure Initialize_Lock
(L
: access RTS_Lock
; Level
: Lock_Level
) is
306 pragma Unreferenced
(Level
);
308 Result
: Interfaces
.C
.int
;
311 Result
:= pthread_mutex_init
(L
, Mutex_Attr
'Access);
313 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
315 if Result
= ENOMEM
then
324 procedure Finalize_Lock
(L
: access Lock
) is
325 Result
: Interfaces
.C
.int
;
327 Result
:= pthread_mutex_destroy
(L
.L
'Access);
328 pragma Assert
(Result
= 0);
331 procedure Finalize_Lock
(L
: access RTS_Lock
) is
332 Result
: Interfaces
.C
.int
;
334 Result
:= pthread_mutex_destroy
(L
);
335 pragma Assert
(Result
= 0);
342 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
343 Result
: Interfaces
.C
.int
;
346 if Priority_Ceiling_Emulation
then
348 Self_ID
: constant Task_Id
:= Self
;
351 if Self_ID
.Common
.LL
.Active_Priority
> L
.Ceiling
then
352 Ceiling_Violation
:= True;
356 L
.Saved_Priority
:= Self_ID
.Common
.LL
.Active_Priority
;
358 if Self_ID
.Common
.LL
.Active_Priority
< L
.Ceiling
then
359 Self_ID
.Common
.LL
.Active_Priority
:= L
.Ceiling
;
362 Result
:= pthread_mutex_lock
(L
.L
'Access);
363 pragma Assert
(Result
= 0);
364 Ceiling_Violation
:= False;
368 Result
:= pthread_mutex_lock
(L
.L
'Access);
369 Ceiling_Violation
:= Result
= EINVAL
;
371 -- Assume the cause of EINVAL is a priority ceiling violation
373 pragma Assert
(Result
= 0 or else Result
= EINVAL
);
378 (L
: access RTS_Lock
;
379 Global_Lock
: Boolean := False)
381 Result
: Interfaces
.C
.int
;
383 if not Single_Lock
or else Global_Lock
then
384 Result
:= pthread_mutex_lock
(L
);
385 pragma Assert
(Result
= 0);
389 procedure Write_Lock
(T
: Task_Id
) is
390 Result
: Interfaces
.C
.int
;
392 if not Single_Lock
then
393 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
394 pragma Assert
(Result
= 0);
402 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
404 Write_Lock
(L
, Ceiling_Violation
);
411 procedure Unlock
(L
: access Lock
) is
412 Result
: Interfaces
.C
.int
;
415 if Priority_Ceiling_Emulation
then
417 Self_ID
: constant Task_Id
:= Self
;
420 Result
:= pthread_mutex_unlock
(L
.L
'Access);
421 pragma Assert
(Result
= 0);
423 if Self_ID
.Common
.LL
.Active_Priority
> L
.Saved_Priority
then
424 Self_ID
.Common
.LL
.Active_Priority
:= L
.Saved_Priority
;
429 Result
:= pthread_mutex_unlock
(L
.L
'Access);
430 pragma Assert
(Result
= 0);
434 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
435 Result
: Interfaces
.C
.int
;
437 if not Single_Lock
or else Global_Lock
then
438 Result
:= pthread_mutex_unlock
(L
);
439 pragma Assert
(Result
= 0);
443 procedure Unlock
(T
: Task_Id
) is
444 Result
: Interfaces
.C
.int
;
446 if not Single_Lock
then
447 Result
:= pthread_mutex_unlock
(T
.Common
.LL
.L
'Access);
448 pragma Assert
(Result
= 0);
458 Reason
: System
.Tasking
.Task_States
)
460 pragma Unreferenced
(Reason
);
462 Result
: Interfaces
.C
.int
;
465 pragma Assert
(Self_ID
= Self
);
468 Result
:= pthread_cond_wait
469 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access);
471 Result
:= pthread_cond_wait
472 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access);
475 -- EINTR is not considered a failure
477 pragma Assert
(Result
= 0 or else Result
= EINTR
);
484 -- This is for use within the run-time system, so abort is
485 -- assumed to be already deferred, and the caller should be
486 -- holding its own ATCB lock.
488 procedure Timed_Sleep
491 Mode
: ST
.Delay_Modes
;
492 Reason
: System
.Tasking
.Task_States
;
493 Timedout
: out Boolean;
494 Yielded
: out Boolean)
496 pragma Unreferenced
(Reason
);
498 Check_Time
: constant Duration := Monotonic_Clock
;
500 Request
: aliased timespec
;
501 Result
: Interfaces
.C
.int
;
507 if Mode
= Relative
then
508 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
510 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
513 if Abs_Time
> Check_Time
then
514 Request
:= To_Timespec
(Abs_Time
);
517 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
518 or else Self_ID
.Pending_Priority_Change
;
521 Result
:= pthread_cond_timedwait
522 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access,
526 Result
:= pthread_cond_timedwait
527 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access,
531 exit when Abs_Time
<= Monotonic_Clock
;
533 if Result
= 0 or Result
= EINTR
then
534 -- somebody may have called Wakeup for us
539 pragma Assert
(Result
= ETIMEDOUT
);
548 -- This is for use in implementing delay statements, so
549 -- we assume the caller is abort-deferred but is holding
552 procedure Timed_Delay
555 Mode
: ST
.Delay_Modes
)
557 Check_Time
: constant Duration := Monotonic_Clock
;
559 Request
: aliased timespec
;
560 Result
: Interfaces
.C
.int
;
563 -- Only the little window between deferring abort and
564 -- locking Self_ID is the reason we need to
565 -- check for pending abort and priority change below! :(
573 Write_Lock
(Self_ID
);
575 if Mode
= Relative
then
576 Abs_Time
:= Time
+ Check_Time
;
578 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
581 if Abs_Time
> Check_Time
then
582 Request
:= To_Timespec
(Abs_Time
);
583 Self_ID
.Common
.State
:= Delay_Sleep
;
586 if Self_ID
.Pending_Priority_Change
then
587 Self_ID
.Pending_Priority_Change
:= False;
588 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
589 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
592 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
595 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
596 Single_RTS_Lock
'Access, Request
'Access);
598 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
599 Self_ID
.Common
.LL
.L
'Access, Request
'Access);
602 exit when Abs_Time
<= Monotonic_Clock
;
604 pragma Assert
(Result
= 0 or else
605 Result
= ETIMEDOUT
or else
609 Self_ID
.Common
.State
:= Runnable
;
618 Result
:= sched_yield
;
619 SSL
.Abort_Undefer
.all;
622 ---------------------
623 -- Monotonic_Clock --
624 ---------------------
626 function Monotonic_Clock
return Duration is
627 TV
: aliased struct_timeval
;
628 Result
: Interfaces
.C
.int
;
630 Result
:= gettimeofday
(TV
'Access, System
.Null_Address
);
631 pragma Assert
(Result
= 0);
632 return To_Duration
(TV
);
639 function RT_Resolution
return Duration is
648 procedure Wakeup
(T
: Task_Id
; Reason
: System
.Tasking
.Task_States
) is
649 pragma Unreferenced
(Reason
);
650 Result
: Interfaces
.C
.int
;
652 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
653 pragma Assert
(Result
= 0);
660 procedure Yield
(Do_Yield
: Boolean := True) is
661 Result
: Interfaces
.C
.int
;
662 pragma Unreferenced
(Result
);
665 Result
:= sched_yield
;
673 procedure Set_Priority
675 Prio
: System
.Any_Priority
;
676 Loss_Of_Inheritance
: Boolean := False)
678 pragma Unreferenced
(Loss_Of_Inheritance
);
680 Result
: Interfaces
.C
.int
;
681 Param
: aliased struct_sched_param
;
684 T
.Common
.Current_Priority
:= Prio
;
686 if Priority_Ceiling_Emulation
then
687 if T
.Common
.LL
.Active_Priority
< Prio
then
688 T
.Common
.LL
.Active_Priority
:= Prio
;
692 -- Priorities are in range 1 .. 99 on GNU/Linux, so we map
693 -- map 0 .. 31 to 1 .. 32
695 Param
.sched_priority
:= Interfaces
.C
.int
(Prio
) + 1;
697 if Time_Slice_Val
> 0 then
698 Result
:= pthread_setschedparam
699 (T
.Common
.LL
.Thread
, SCHED_RR
, Param
'Access);
701 elsif FIFO_Within_Priorities
or else Time_Slice_Val
= 0 then
702 Result
:= pthread_setschedparam
703 (T
.Common
.LL
.Thread
, SCHED_FIFO
, Param
'Access);
706 Param
.sched_priority
:= 0;
707 Result
:= pthread_setschedparam
708 (T
.Common
.LL
.Thread
, SCHED_OTHER
, Param
'Access);
711 pragma Assert
(Result
= 0 or else Result
= EPERM
);
718 function Get_Priority
(T
: Task_Id
) return System
.Any_Priority
is
720 return T
.Common
.Current_Priority
;
727 procedure Enter_Task
(Self_ID
: Task_Id
) is
729 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
731 Specific
.Set
(Self_ID
);
735 for J
in Known_Tasks
'Range loop
736 if Known_Tasks
(J
) = null then
737 Known_Tasks
(J
) := Self_ID
;
738 Self_ID
.Known_Tasks_Index
:= J
;
750 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_Id
is
752 return new Ada_Task_Control_Block
(Entry_Num
);
759 function Is_Valid_Task
return Boolean renames Specific
.Is_Valid_Task
;
761 -----------------------------
762 -- Register_Foreign_Thread --
763 -----------------------------
765 function Register_Foreign_Thread
return Task_Id
is
767 if Is_Valid_Task
then
770 return Register_Foreign_Thread
(pthread_self
);
772 end Register_Foreign_Thread
;
778 procedure Initialize_TCB
(Self_ID
: Task_Id
; Succeeded
: out Boolean) is
779 Result
: Interfaces
.C
.int
;
782 -- Give the task a unique serial number
784 Self_ID
.Serial_Number
:= Next_Serial_Number
;
785 Next_Serial_Number
:= Next_Serial_Number
+ 1;
786 pragma Assert
(Next_Serial_Number
/= 0);
788 Self_ID
.Common
.LL
.Thread
:= To_pthread_t
(-1);
790 if not Single_Lock
then
791 Result
:= pthread_mutex_init
(Self_ID
.Common
.LL
.L
'Access,
793 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
801 Result
:= pthread_cond_init
(Self_ID
.Common
.LL
.CV
'Access,
803 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
808 if not Single_Lock
then
809 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
810 pragma Assert
(Result
= 0);
821 procedure Create_Task
823 Wrapper
: System
.Address
;
824 Stack_Size
: System
.Parameters
.Size_Type
;
825 Priority
: System
.Any_Priority
;
826 Succeeded
: out Boolean)
828 Adjusted_Stack_Size
: Interfaces
.C
.size_t
;
830 Attributes
: aliased pthread_attr_t
;
831 Result
: Interfaces
.C
.int
;
834 if Stack_Size
= Unspecified_Size
then
835 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Default_Stack_Size
);
837 elsif Stack_Size
< Minimum_Stack_Size
then
838 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Minimum_Stack_Size
);
841 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Stack_Size
);
844 Result
:= pthread_attr_init
(Attributes
'Access);
845 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
853 pthread_attr_setstacksize
854 (Attributes
'Access, Adjusted_Stack_Size
);
855 pragma Assert
(Result
= 0);
858 pthread_attr_setdetachstate
859 (Attributes
'Access, PTHREAD_CREATE_DETACHED
);
860 pragma Assert
(Result
= 0);
862 -- Since the initial signal mask of a thread is inherited from the
863 -- creator, and the Environment task has all its signals masked, we
864 -- do not need to manipulate caller's signal mask at this point.
865 -- All tasks in RTS will have All_Tasks_Mask initially.
867 Result
:= pthread_create
868 (T
.Common
.LL
.Thread
'Access,
870 Thread_Body_Access
(Wrapper
),
872 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
874 Succeeded
:= Result
= 0;
876 Result
:= pthread_attr_destroy
(Attributes
'Access);
877 pragma Assert
(Result
= 0);
879 Set_Priority
(T
, Priority
);
886 procedure Finalize_TCB
(T
: Task_Id
) is
887 Result
: Interfaces
.C
.int
;
889 Is_Self
: constant Boolean := T
= Self
;
891 procedure Free
is new
892 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_Id
);
895 if not Single_Lock
then
896 Result
:= pthread_mutex_destroy
(T
.Common
.LL
.L
'Access);
897 pragma Assert
(Result
= 0);
900 Result
:= pthread_cond_destroy
(T
.Common
.LL
.CV
'Access);
901 pragma Assert
(Result
= 0);
903 if T
.Known_Tasks_Index
/= -1 then
904 Known_Tasks
(T
.Known_Tasks_Index
) := null;
918 procedure Exit_Task
is
927 procedure Abort_Task
(T
: Task_Id
) is
928 Result
: Interfaces
.C
.int
;
930 Result
:= pthread_kill
(T
.Common
.LL
.Thread
,
931 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
));
932 pragma Assert
(Result
= 0);
941 function Check_Exit
(Self_ID
: ST
.Task_Id
) return Boolean is
942 pragma Unreferenced
(Self_ID
);
951 function Check_No_Locks
(Self_ID
: ST
.Task_Id
) return Boolean is
952 pragma Unreferenced
(Self_ID
);
957 ----------------------
958 -- Environment_Task --
959 ----------------------
961 function Environment_Task
return Task_Id
is
963 return Environment_Task_Id
;
964 end Environment_Task
;
970 function Suspend_Task
972 Thread_Self
: Thread_Id
) return Boolean
975 if T
.Common
.LL
.Thread
/= Thread_Self
then
976 return pthread_kill
(T
.Common
.LL
.Thread
, SIGSTOP
) = 0;
988 Thread_Self
: Thread_Id
) return Boolean
991 if T
.Common
.LL
.Thread
/= Thread_Self
then
992 return pthread_kill
(T
.Common
.LL
.Thread
, SIGCONT
) = 0;
1002 procedure Initialize
(Environment_Task
: Task_Id
) is
1003 act
: aliased struct_sigaction
;
1004 old_act
: aliased struct_sigaction
;
1005 Tmp_Set
: aliased sigset_t
;
1006 Result
: Interfaces
.C
.int
;
1009 (Int
: System
.Interrupt_Management
.Interrupt_ID
) return Character;
1010 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
1011 -- Get interrupt state. Defined in a-init.c
1012 -- The input argument is the interrupt number,
1013 -- and the result is one of the following:
1015 Default
: constant Character := 's';
1016 -- 'n' this interrupt not set by any Interrupt_State pragma
1017 -- 'u' Interrupt_State pragma set state to User
1018 -- 'r' Interrupt_State pragma set state to Runtime
1019 -- 's' Interrupt_State pragma set state to System (use "default"
1023 Environment_Task_Id
:= Environment_Task
;
1025 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
1027 -- Initialize the global RTS lock
1029 Specific
.Initialize
(Environment_Task
);
1031 Enter_Task
(Environment_Task
);
1033 -- Install the abort-signal handler
1035 if State
(System
.Interrupt_Management
.Abort_Task_Interrupt
)
1039 act
.sa_handler
:= Abort_Handler
'Address;
1041 Result
:= sigemptyset
(Tmp_Set
'Access);
1042 pragma Assert
(Result
= 0);
1043 act
.sa_mask
:= Tmp_Set
;
1047 (Signal
(Interrupt_Management
.Abort_Task_Interrupt
),
1048 act
'Unchecked_Access,
1049 old_act
'Unchecked_Access);
1050 pragma Assert
(Result
= 0);
1056 Result
: Interfaces
.C
.int
;
1059 -- Mask Environment task for all signals. The original mask of the
1060 -- Environment task will be recovered by Interrupt_Server task
1061 -- during the elaboration of s-interr.adb.
1063 System
.Interrupt_Management
.Operations
.Set_Interrupt_Mask
1064 (System
.Interrupt_Management
.Operations
.All_Tasks_Mask
'Access);
1066 -- Prepare the set of signals that should unblocked in all tasks
1068 Result
:= sigemptyset
(Unblocked_Signal_Mask
'Access);
1069 pragma Assert
(Result
= 0);
1071 for J
in Interrupt_Management
.Interrupt_ID
loop
1072 if System
.Interrupt_Management
.Keep_Unmasked
(J
) then
1073 Result
:= sigaddset
(Unblocked_Signal_Mask
'Access, Signal
(J
));
1074 pragma Assert
(Result
= 0);
1078 Result
:= pthread_mutexattr_init
(Mutex_Attr
'Access);
1079 pragma Assert
(Result
= 0);
1081 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
1082 pragma Assert
(Result
= 0);
1084 end System
.Task_Primitives
.Operations
;