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-2006, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
32 ------------------------------------------------------------------------------
34 -- This is a 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
.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
.Soft_Links
;
59 -- used for Abort_Defer/Undefer
62 -- used for Raise_Exception
63 -- Raise_From_Signal_Handler
66 with Unchecked_Conversion
;
67 with Unchecked_Deallocation
;
69 package body System
.Task_Primitives
.Operations
is
71 use System
.Tasking
.Debug
;
74 use System
.OS_Interface
;
75 use System
.Parameters
;
76 use System
.OS_Primitives
;
82 -- The followings are logically constants, but need to be initialized
85 Single_RTS_Lock
: aliased RTS_Lock
;
86 -- This is a lock to allow only one thread of control in the RTS at
87 -- a time; it is used to execute in mutual exclusion from all other tasks.
88 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
90 ATCB_Key
: aliased pthread_key_t
;
91 -- Key used to find the Ada Task_Id associated with a thread
93 Environment_Task_Id
: Task_Id
;
94 -- A variable to hold Task_Id for the environment task
96 Unblocked_Signal_Mask
: aliased sigset_t
;
97 -- The set of signals that should be unblocked in all tasks
99 -- The followings are internal configuration constants needed
101 Next_Serial_Number
: Task_Serial_Number
:= 100;
102 -- We start at 100, to reserve some special values for
103 -- using in error checking.
105 Time_Slice_Val
: Integer;
106 pragma Import
(C
, Time_Slice_Val
, "__gl_time_slice_val");
108 Dispatching_Policy
: Character;
109 pragma Import
(C
, Dispatching_Policy
, "__gl_task_dispatching_policy");
111 -- The following are effectively constants, but they need to
112 -- be initialized by calling a pthread_ function.
114 Mutex_Attr
: aliased pthread_mutexattr_t
;
115 Cond_Attr
: aliased pthread_condattr_t
;
117 Foreign_Task_Elaborated
: aliased Boolean := True;
118 -- Used to identified fake tasks (i.e., non-Ada Threads)
126 procedure Initialize
(Environment_Task
: Task_Id
);
127 pragma Inline
(Initialize
);
128 -- Initialize various data needed by this package
130 function Is_Valid_Task
return Boolean;
131 pragma Inline
(Is_Valid_Task
);
132 -- Does executing thread have a TCB?
134 procedure Set
(Self_Id
: Task_Id
);
136 -- Set the self id for the current task
138 function Self
return Task_Id
;
139 pragma Inline
(Self
);
140 -- Return a pointer to the Ada Task Control Block of the calling task.
144 package body Specific
is separate;
145 -- The body of this package is target specific
147 ---------------------------------
148 -- Support for foreign threads --
149 ---------------------------------
151 function Register_Foreign_Thread
(Thread
: Thread_Id
) return Task_Id
;
152 -- Allocate and Initialize a new ATCB for the current Thread
154 function Register_Foreign_Thread
155 (Thread
: Thread_Id
) return Task_Id
is separate;
157 -----------------------
158 -- Local Subprograms --
159 -----------------------
161 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
163 procedure Abort_Handler
(signo
: Signal
);
165 function To_pthread_t
is new Unchecked_Conversion
166 (unsigned_long
, System
.OS_Interface
.pthread_t
);
172 procedure Abort_Handler
(signo
: Signal
) is
173 pragma Unreferenced
(signo
);
175 Self_Id
: constant Task_Id
:= Self
;
176 Result
: Interfaces
.C
.int
;
177 Old_Set
: aliased sigset_t
;
180 if ZCX_By_Default
and then GCC_ZCX_Support
then
184 if Self_Id
.Deferral_Level
= 0
185 and then Self_Id
.Pending_ATC_Level
< Self_Id
.ATC_Nesting_Level
186 and then not Self_Id
.Aborting
188 Self_Id
.Aborting
:= True;
190 -- Make sure signals used for RTS internal purpose are unmasked
192 Result
:= pthread_sigmask
(SIG_UNBLOCK
,
193 Unblocked_Signal_Mask
'Unchecked_Access, Old_Set
'Unchecked_Access);
194 pragma Assert
(Result
= 0);
196 raise Standard
'Abort_Signal;
204 procedure Lock_RTS
is
206 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
213 procedure Unlock_RTS
is
215 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
222 -- The underlying thread system extends the memory (up to 2MB) when needed
224 procedure Stack_Guard
(T
: ST
.Task_Id
; On
: Boolean) is
225 pragma Unreferenced
(T
);
226 pragma Unreferenced
(On
);
235 function Get_Thread_Id
(T
: ST
.Task_Id
) return OSI
.Thread_Id
is
237 return T
.Common
.LL
.Thread
;
244 function Self
return Task_Id
renames Specific
.Self
;
246 ---------------------
247 -- Initialize_Lock --
248 ---------------------
250 -- Note: mutexes and cond_variables needed per-task basis are
251 -- initialized in Initialize_TCB and the Storage_Error is
252 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
253 -- used in RTS is initialized before any status change of RTS.
254 -- Therefore rasing Storage_Error in the following routines
255 -- should be able to be handled safely.
257 procedure Initialize_Lock
258 (Prio
: System
.Any_Priority
;
261 pragma Unreferenced
(Prio
);
263 Result
: Interfaces
.C
.int
;
265 Result
:= pthread_mutex_init
(L
, Mutex_Attr
'Access);
267 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
269 if Result
= ENOMEM
then
270 Ada
.Exceptions
.Raise_Exception
(Storage_Error
'Identity,
271 "Failed to allocate a lock");
275 procedure Initialize_Lock
(L
: access RTS_Lock
; Level
: Lock_Level
) is
276 pragma Unreferenced
(Level
);
278 Result
: Interfaces
.C
.int
;
281 Result
:= pthread_mutex_init
(L
, Mutex_Attr
'Access);
283 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
285 if Result
= ENOMEM
then
294 procedure Finalize_Lock
(L
: access Lock
) is
295 Result
: Interfaces
.C
.int
;
297 Result
:= pthread_mutex_destroy
(L
);
298 pragma Assert
(Result
= 0);
301 procedure Finalize_Lock
(L
: access RTS_Lock
) is
302 Result
: Interfaces
.C
.int
;
304 Result
:= pthread_mutex_destroy
(L
);
305 pragma Assert
(Result
= 0);
312 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
313 Result
: Interfaces
.C
.int
;
315 Result
:= pthread_mutex_lock
(L
);
316 Ceiling_Violation
:= Result
= EINVAL
;
318 -- Assume the cause of EINVAL is a priority ceiling violation
320 pragma Assert
(Result
= 0 or else Result
= EINVAL
);
324 (L
: access RTS_Lock
;
325 Global_Lock
: Boolean := False)
327 Result
: Interfaces
.C
.int
;
329 if not Single_Lock
or else Global_Lock
then
330 Result
:= pthread_mutex_lock
(L
);
331 pragma Assert
(Result
= 0);
335 procedure Write_Lock
(T
: Task_Id
) is
336 Result
: Interfaces
.C
.int
;
338 if not Single_Lock
then
339 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
340 pragma Assert
(Result
= 0);
348 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
350 Write_Lock
(L
, Ceiling_Violation
);
357 procedure Unlock
(L
: access Lock
) is
358 Result
: Interfaces
.C
.int
;
360 Result
:= pthread_mutex_unlock
(L
);
361 pragma Assert
(Result
= 0);
364 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
365 Result
: Interfaces
.C
.int
;
367 if not Single_Lock
or else Global_Lock
then
368 Result
:= pthread_mutex_unlock
(L
);
369 pragma Assert
(Result
= 0);
373 procedure Unlock
(T
: Task_Id
) is
374 Result
: Interfaces
.C
.int
;
376 if not Single_Lock
then
377 Result
:= pthread_mutex_unlock
(T
.Common
.LL
.L
'Access);
378 pragma Assert
(Result
= 0);
388 Reason
: System
.Tasking
.Task_States
)
390 pragma Unreferenced
(Reason
);
392 Result
: Interfaces
.C
.int
;
395 pragma Assert
(Self_ID
= Self
);
398 Result
:= pthread_cond_wait
399 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access);
401 Result
:= pthread_cond_wait
402 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access);
405 -- EINTR is not considered a failure
407 pragma Assert
(Result
= 0 or else Result
= EINTR
);
414 -- This is for use within the run-time system, so abort is
415 -- assumed to be already deferred, and the caller should be
416 -- holding its own ATCB lock.
418 procedure Timed_Sleep
421 Mode
: ST
.Delay_Modes
;
422 Reason
: System
.Tasking
.Task_States
;
423 Timedout
: out Boolean;
424 Yielded
: out Boolean)
426 pragma Unreferenced
(Reason
);
428 Check_Time
: constant Duration := Monotonic_Clock
;
430 Request
: aliased timespec
;
431 Result
: Interfaces
.C
.int
;
437 if Mode
= Relative
then
438 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
440 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
443 if Abs_Time
> Check_Time
then
444 Request
:= To_Timespec
(Abs_Time
);
447 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
448 or else Self_ID
.Pending_Priority_Change
;
451 Result
:= pthread_cond_timedwait
452 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access,
456 Result
:= pthread_cond_timedwait
457 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access,
461 exit when Abs_Time
<= Monotonic_Clock
;
463 if Result
= 0 or Result
= EINTR
then
464 -- somebody may have called Wakeup for us
469 pragma Assert
(Result
= ETIMEDOUT
);
478 -- This is for use in implementing delay statements, so
479 -- we assume the caller is abort-deferred but is holding
482 procedure Timed_Delay
485 Mode
: ST
.Delay_Modes
)
487 Check_Time
: constant Duration := Monotonic_Clock
;
489 Request
: aliased timespec
;
490 Result
: Interfaces
.C
.int
;
497 Write_Lock
(Self_ID
);
499 if Mode
= Relative
then
500 Abs_Time
:= Time
+ Check_Time
;
502 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
505 if Abs_Time
> Check_Time
then
506 Request
:= To_Timespec
(Abs_Time
);
507 Self_ID
.Common
.State
:= Delay_Sleep
;
510 if Self_ID
.Pending_Priority_Change
then
511 Self_ID
.Pending_Priority_Change
:= False;
512 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
513 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
516 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
519 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
520 Single_RTS_Lock
'Access, Request
'Access);
522 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
523 Self_ID
.Common
.LL
.L
'Access, Request
'Access);
526 exit when Abs_Time
<= Monotonic_Clock
;
528 pragma Assert
(Result
= 0 or else
529 Result
= ETIMEDOUT
or else
533 Self_ID
.Common
.State
:= Runnable
;
542 Result
:= sched_yield
;
545 ---------------------
546 -- Monotonic_Clock --
547 ---------------------
549 function Monotonic_Clock
return Duration is
550 TV
: aliased struct_timeval
;
551 Result
: Interfaces
.C
.int
;
553 Result
:= gettimeofday
(TV
'Access, System
.Null_Address
);
554 pragma Assert
(Result
= 0);
555 return To_Duration
(TV
);
562 function RT_Resolution
return Duration is
571 procedure Wakeup
(T
: Task_Id
; Reason
: System
.Tasking
.Task_States
) is
572 pragma Unreferenced
(Reason
);
573 Result
: Interfaces
.C
.int
;
575 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
576 pragma Assert
(Result
= 0);
583 procedure Yield
(Do_Yield
: Boolean := True) is
584 Result
: Interfaces
.C
.int
;
585 pragma Unreferenced
(Result
);
588 Result
:= sched_yield
;
596 procedure Set_Priority
598 Prio
: System
.Any_Priority
;
599 Loss_Of_Inheritance
: Boolean := False)
601 pragma Unreferenced
(Loss_Of_Inheritance
);
603 Result
: Interfaces
.C
.int
;
604 Param
: aliased struct_sched_param
;
607 T
.Common
.Current_Priority
:= Prio
;
609 -- Priorities are in range 1 .. 99 on GNU/Linux, so we map
610 -- map 0 .. 31 to 1 .. 32
612 Param
.sched_priority
:= Interfaces
.C
.int
(Prio
) + 1;
614 if Time_Slice_Val
> 0 then
615 Result
:= pthread_setschedparam
616 (T
.Common
.LL
.Thread
, SCHED_RR
, Param
'Access);
618 elsif Dispatching_Policy
= 'F' or else Time_Slice_Val
= 0 then
619 Result
:= pthread_setschedparam
620 (T
.Common
.LL
.Thread
, SCHED_FIFO
, Param
'Access);
623 Param
.sched_priority
:= 0;
624 Result
:= pthread_setschedparam
625 (T
.Common
.LL
.Thread
, SCHED_OTHER
, Param
'Access);
628 pragma Assert
(Result
= 0 or else Result
= EPERM
);
635 function Get_Priority
(T
: Task_Id
) return System
.Any_Priority
is
637 return T
.Common
.Current_Priority
;
644 procedure Enter_Task
(Self_ID
: Task_Id
) is
646 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
648 Specific
.Set
(Self_ID
);
652 for J
in Known_Tasks
'Range loop
653 if Known_Tasks
(J
) = null then
654 Known_Tasks
(J
) := Self_ID
;
655 Self_ID
.Known_Tasks_Index
:= J
;
667 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_Id
is
669 return new Ada_Task_Control_Block
(Entry_Num
);
676 function Is_Valid_Task
return Boolean renames Specific
.Is_Valid_Task
;
678 -----------------------------
679 -- Register_Foreign_Thread --
680 -----------------------------
682 function Register_Foreign_Thread
return Task_Id
is
684 if Is_Valid_Task
then
687 return Register_Foreign_Thread
(pthread_self
);
689 end Register_Foreign_Thread
;
695 procedure Initialize_TCB
(Self_ID
: Task_Id
; Succeeded
: out Boolean) is
696 Result
: Interfaces
.C
.int
;
699 -- Give the task a unique serial number
701 Self_ID
.Serial_Number
:= Next_Serial_Number
;
702 Next_Serial_Number
:= Next_Serial_Number
+ 1;
703 pragma Assert
(Next_Serial_Number
/= 0);
705 Self_ID
.Common
.LL
.Thread
:= To_pthread_t
(-1);
707 if not Single_Lock
then
708 Result
:= pthread_mutex_init
(Self_ID
.Common
.LL
.L
'Access,
710 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
718 Result
:= pthread_cond_init
(Self_ID
.Common
.LL
.CV
'Access,
720 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
725 if not Single_Lock
then
726 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
727 pragma Assert
(Result
= 0);
738 procedure Create_Task
740 Wrapper
: System
.Address
;
741 Stack_Size
: System
.Parameters
.Size_Type
;
742 Priority
: System
.Any_Priority
;
743 Succeeded
: out Boolean)
745 Attributes
: aliased pthread_attr_t
;
746 Result
: Interfaces
.C
.int
;
749 Result
:= pthread_attr_init
(Attributes
'Access);
750 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
758 pthread_attr_setstacksize
759 (Attributes
'Access, Interfaces
.C
.size_t
(Stack_Size
));
760 pragma Assert
(Result
= 0);
763 pthread_attr_setdetachstate
764 (Attributes
'Access, PTHREAD_CREATE_DETACHED
);
765 pragma Assert
(Result
= 0);
767 -- Since the initial signal mask of a thread is inherited from the
768 -- creator, and the Environment task has all its signals masked, we
769 -- do not need to manipulate caller's signal mask at this point.
770 -- All tasks in RTS will have All_Tasks_Mask initially.
772 Result
:= pthread_create
773 (T
.Common
.LL
.Thread
'Access,
775 Thread_Body_Access
(Wrapper
),
777 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
779 Succeeded
:= Result
= 0;
781 Result
:= pthread_attr_destroy
(Attributes
'Access);
782 pragma Assert
(Result
= 0);
784 Set_Priority
(T
, Priority
);
791 procedure Finalize_TCB
(T
: Task_Id
) is
792 Result
: Interfaces
.C
.int
;
794 Is_Self
: constant Boolean := T
= Self
;
796 procedure Free
is new
797 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_Id
);
800 if not Single_Lock
then
801 Result
:= pthread_mutex_destroy
(T
.Common
.LL
.L
'Access);
802 pragma Assert
(Result
= 0);
805 Result
:= pthread_cond_destroy
(T
.Common
.LL
.CV
'Access);
806 pragma Assert
(Result
= 0);
808 if T
.Known_Tasks_Index
/= -1 then
809 Known_Tasks
(T
.Known_Tasks_Index
) := null;
823 procedure Exit_Task
is
832 procedure Abort_Task
(T
: Task_Id
) is
833 Result
: Interfaces
.C
.int
;
835 Result
:= pthread_kill
(T
.Common
.LL
.Thread
,
836 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
));
837 pragma Assert
(Result
= 0);
844 procedure Initialize
(S
: in out Suspension_Object
) is
845 Result
: Interfaces
.C
.int
;
847 -- Initialize internal state. It is always initialized to False (ARM
853 -- Initialize internal mutex
855 Result
:= pthread_mutex_init
(S
.L
'Access, Mutex_Attr
'Access);
857 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
859 if Result
= ENOMEM
then
863 -- Initialize internal condition variable
865 Result
:= pthread_cond_init
(S
.CV
'Access, Cond_Attr
'Access);
867 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
870 Result
:= pthread_mutex_destroy
(S
.L
'Access);
871 pragma Assert
(Result
= 0);
873 if Result
= ENOMEM
then
883 procedure Finalize
(S
: in out Suspension_Object
) is
884 Result
: Interfaces
.C
.int
;
886 -- Destroy internal mutex
888 Result
:= pthread_mutex_destroy
(S
.L
'Access);
889 pragma Assert
(Result
= 0);
891 -- Destroy internal condition variable
893 Result
:= pthread_cond_destroy
(S
.CV
'Access);
894 pragma Assert
(Result
= 0);
901 function Current_State
(S
: Suspension_Object
) return Boolean is
903 -- We do not want to use lock on this read operation. State is marked
904 -- as Atomic so that we ensure that the value retrieved is correct.
913 procedure Set_False
(S
: in out Suspension_Object
) is
914 Result
: Interfaces
.C
.int
;
916 Result
:= pthread_mutex_lock
(S
.L
'Access);
917 pragma Assert
(Result
= 0);
921 Result
:= pthread_mutex_unlock
(S
.L
'Access);
922 pragma Assert
(Result
= 0);
929 procedure Set_True
(S
: in out Suspension_Object
) is
930 Result
: Interfaces
.C
.int
;
932 Result
:= pthread_mutex_lock
(S
.L
'Access);
933 pragma Assert
(Result
= 0);
935 -- If there is already a task waiting on this suspension object then
936 -- we resume it, leaving the state of the suspension object to False,
937 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
938 -- the state to True.
944 Result
:= pthread_cond_signal
(S
.CV
'Access);
945 pragma Assert
(Result
= 0);
950 Result
:= pthread_mutex_unlock
(S
.L
'Access);
951 pragma Assert
(Result
= 0);
954 ------------------------
955 -- Suspend_Until_True --
956 ------------------------
958 procedure Suspend_Until_True
(S
: in out Suspension_Object
) is
959 Result
: Interfaces
.C
.int
;
961 Result
:= pthread_mutex_lock
(S
.L
'Access);
962 pragma Assert
(Result
= 0);
965 -- Program_Error must be raised upon calling Suspend_Until_True
966 -- if another task is already waiting on that suspension object
967 -- (ARM D.10 par. 10).
969 Result
:= pthread_mutex_unlock
(S
.L
'Access);
970 pragma Assert
(Result
= 0);
974 -- Suspend the task if the state is False. Otherwise, the task
975 -- continues its execution, and the state of the suspension object
976 -- is set to False (ARM D.10 par. 9).
982 Result
:= pthread_cond_wait
(S
.CV
'Access, S
.L
'Access);
986 Result
:= pthread_mutex_unlock
(S
.L
'Access);
987 pragma Assert
(Result
= 0);
988 end Suspend_Until_True
;
996 function Check_Exit
(Self_ID
: ST
.Task_Id
) return Boolean is
997 pragma Unreferenced
(Self_ID
);
1002 --------------------
1003 -- Check_No_Locks --
1004 --------------------
1006 function Check_No_Locks
(Self_ID
: ST
.Task_Id
) return Boolean is
1007 pragma Unreferenced
(Self_ID
);
1012 ----------------------
1013 -- Environment_Task --
1014 ----------------------
1016 function Environment_Task
return Task_Id
is
1018 return Environment_Task_Id
;
1019 end Environment_Task
;
1025 function Suspend_Task
1027 Thread_Self
: Thread_Id
) return Boolean
1030 if T
.Common
.LL
.Thread
/= Thread_Self
then
1031 return pthread_kill
(T
.Common
.LL
.Thread
, SIGSTOP
) = 0;
1041 function Resume_Task
1043 Thread_Self
: Thread_Id
) return Boolean
1046 if T
.Common
.LL
.Thread
/= Thread_Self
then
1047 return pthread_kill
(T
.Common
.LL
.Thread
, SIGCONT
) = 0;
1057 procedure Initialize
(Environment_Task
: Task_Id
) is
1058 act
: aliased struct_sigaction
;
1059 old_act
: aliased struct_sigaction
;
1060 Tmp_Set
: aliased sigset_t
;
1061 Result
: Interfaces
.C
.int
;
1064 (Int
: System
.Interrupt_Management
.Interrupt_ID
) return Character;
1065 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
1066 -- Get interrupt state. Defined in a-init.c
1067 -- The input argument is the interrupt number,
1068 -- and the result is one of the following:
1070 Default
: constant Character := 's';
1071 -- 'n' this interrupt not set by any Interrupt_State pragma
1072 -- 'u' Interrupt_State pragma set state to User
1073 -- 'r' Interrupt_State pragma set state to Runtime
1074 -- 's' Interrupt_State pragma set state to System (use "default"
1078 Environment_Task_Id
:= Environment_Task
;
1080 Interrupt_Management
.Initialize
;
1082 -- Prepare the set of signals that should be unblocked in all tasks
1084 Result
:= sigemptyset
(Unblocked_Signal_Mask
'Access);
1085 pragma Assert
(Result
= 0);
1087 for J
in Interrupt_Management
.Interrupt_ID
loop
1088 if System
.Interrupt_Management
.Keep_Unmasked
(J
) then
1089 Result
:= sigaddset
(Unblocked_Signal_Mask
'Access, Signal
(J
));
1090 pragma Assert
(Result
= 0);
1094 Result
:= pthread_mutexattr_init
(Mutex_Attr
'Access);
1095 pragma Assert
(Result
= 0);
1097 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
1098 pragma Assert
(Result
= 0);
1100 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
1102 -- Initialize the global RTS lock
1104 Specific
.Initialize
(Environment_Task
);
1106 Enter_Task
(Environment_Task
);
1108 -- Install the abort-signal handler
1110 if State
(System
.Interrupt_Management
.Abort_Task_Interrupt
)
1114 act
.sa_handler
:= Abort_Handler
'Address;
1116 Result
:= sigemptyset
(Tmp_Set
'Access);
1117 pragma Assert
(Result
= 0);
1118 act
.sa_mask
:= Tmp_Set
;
1122 (Signal
(Interrupt_Management
.Abort_Task_Interrupt
),
1123 act
'Unchecked_Access,
1124 old_act
'Unchecked_Access);
1125 pragma Assert
(Result
= 0);
1129 end System
.Task_Primitives
.Operations
;