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 DEC Unix 4.0d 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
46 with System
.Task_Info
;
47 -- used for Task_Info_Type
50 -- used for Shift_Left
56 with System
.Interrupt_Management
;
57 -- used for Keep_Unmasked
58 -- Abort_Task_Interrupt
61 with System
.Interrupt_Management
.Operations
;
62 -- used for Set_Interrupt_Mask
64 pragma Elaborate_All
(System
.Interrupt_Management
.Operations
);
66 with System
.Parameters
;
70 -- used for Ada_Task_Control_Block
72 -- ATCB components and types
74 with System
.Soft_Links
;
75 -- used for Defer/Undefer_Abort
77 -- Note that we do not use System.Tasking.Initialization directly since
78 -- this is a higher level package that we shouldn't depend on. For example
79 -- when using the restricted run time, it is replaced by
80 -- System.Tasking.Restricted.Initialization
82 with System
.OS_Primitives
;
83 -- used for Delay_Modes
85 with Unchecked_Deallocation
;
87 package body System
.Task_Primitives
.Operations
is
89 use System
.Tasking
.Debug
;
92 use System
.OS_Interface
;
93 use System
.Parameters
;
94 use System
.OS_Primitives
;
96 package SSL
renames System
.Soft_Links
;
102 -- The followings are logically constants, but need to be initialized
105 Single_RTS_Lock
: aliased RTS_Lock
;
106 -- This is a lock to allow only one thread of control in the RTS at
107 -- a time; it is used to execute in mutual exclusion from all other tasks.
108 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
110 ATCB_Key
: aliased pthread_key_t
;
111 -- Key used to find the Ada Task_ID associated with a thread
113 Environment_Task_ID
: Task_ID
;
114 -- A variable to hold Task_ID for the environment task.
116 Unblocked_Signal_Mask
: aliased sigset_t
;
117 -- The set of signals that should unblocked in all tasks
119 Time_Slice_Val
: Integer;
120 pragma Import
(C
, Time_Slice_Val
, "__gl_time_slice_val");
122 Locking_Policy
: Character;
123 pragma Import
(C
, Locking_Policy
, "__gl_locking_policy");
125 Dispatching_Policy
: Character;
126 pragma Import
(C
, Dispatching_Policy
, "__gl_task_dispatching_policy");
128 FIFO_Within_Priorities
: constant Boolean := Dispatching_Policy
= 'F';
129 -- Indicates whether FIFO_Within_Priorities is set.
133 Foreign_Task_Elaborated
: aliased Boolean := True;
134 -- Used to identified fake tasks (i.e., non-Ada Threads).
142 procedure Initialize
(Environment_Task
: Task_ID
);
143 pragma Inline
(Initialize
);
144 -- Initialize various data needed by this package.
146 function Is_Valid_Task
return Boolean;
147 pragma Inline
(Is_Valid_Task
);
148 -- Does executing thread have a TCB?
150 procedure Set
(Self_Id
: Task_ID
);
152 -- Set the self id for the current task.
154 function Self
return Task_ID
;
155 pragma Inline
(Self
);
156 -- Return a pointer to the Ada Task Control Block of the calling task.
160 package body Specific
is separate;
161 -- The body of this package is target specific.
163 ---------------------------------
164 -- Support for foreign threads --
165 ---------------------------------
167 function Register_Foreign_Thread
(Thread
: Thread_Id
) return Task_ID
;
168 -- Allocate and Initialize a new ATCB for the current Thread.
170 function Register_Foreign_Thread
171 (Thread
: Thread_Id
) return Task_ID
is separate;
173 -----------------------
174 -- Local Subprograms --
175 -----------------------
177 procedure Abort_Handler
(Sig
: Signal
);
178 -- Signal handler used to implement asynchronous abortion.
184 procedure Abort_Handler
(Sig
: Signal
) is
185 pragma Unreferenced
(Sig
);
187 T
: constant Task_ID
:= Self
;
188 Result
: Interfaces
.C
.int
;
189 Old_Set
: aliased sigset_t
;
192 -- It is not safe to raise an exception when using ZCX and the GCC
193 -- exception handling mechanism.
195 if ZCX_By_Default
and then GCC_ZCX_Support
then
199 if T
.Deferral_Level
= 0
200 and then T
.Pending_ATC_Level
< T
.ATC_Nesting_Level
and then
205 -- Make sure signals used for RTS internal purpose are unmasked
207 Result
:= pthread_sigmask
(SIG_UNBLOCK
,
208 Unblocked_Signal_Mask
'Unchecked_Access, Old_Set
'Unchecked_Access);
209 pragma Assert
(Result
= 0);
211 raise Standard
'Abort_Signal;
219 -- The underlying thread system sets a guard page at the
220 -- bottom of a thread stack, so nothing is needed.
222 procedure Stack_Guard
(T
: ST
.Task_ID
; On
: Boolean) is
223 pragma Unreferenced
(T
);
224 pragma Unreferenced
(On
);
234 function Get_Thread_Id
(T
: ST
.Task_ID
) return OSI
.Thread_Id
is
236 return T
.Common
.LL
.Thread
;
243 function Self
return Task_ID
renames Specific
.Self
;
245 ---------------------
246 -- Initialize_Lock --
247 ---------------------
249 -- Note: mutexes and cond_variables needed per-task basis are
250 -- initialized in Initialize_TCB and the Storage_Error is
251 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
252 -- used in RTS is initialized before any status change of RTS.
253 -- Therefore rasing Storage_Error in the following routines
254 -- should be able to be handled safely.
256 procedure Initialize_Lock
257 (Prio
: System
.Any_Priority
;
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 if Locking_Policy
= 'C' then
272 L
.Ceiling
:= Interfaces
.C
.int
(Prio
);
275 Result
:= pthread_mutex_init
(L
.L
'Access, Attributes
'Access);
276 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
278 if Result
= ENOMEM
then
279 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
283 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
284 pragma Assert
(Result
= 0);
287 procedure Initialize_Lock
(L
: access RTS_Lock
; Level
: Lock_Level
) is
288 pragma Unreferenced
(Level
);
290 Attributes
: aliased pthread_mutexattr_t
;
291 Result
: Interfaces
.C
.int
;
294 Result
:= pthread_mutexattr_init
(Attributes
'Access);
295 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
297 if Result
= ENOMEM
then
301 Result
:= pthread_mutex_init
(L
, Attributes
'Access);
302 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
304 if Result
= ENOMEM
then
305 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
309 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
310 pragma Assert
(Result
= 0);
317 procedure Finalize_Lock
(L
: access Lock
) is
318 Result
: Interfaces
.C
.int
;
320 Result
:= pthread_mutex_destroy
(L
.L
'Access);
321 pragma Assert
(Result
= 0);
324 procedure Finalize_Lock
(L
: access RTS_Lock
) is
325 Result
: Interfaces
.C
.int
;
327 Result
:= pthread_mutex_destroy
(L
);
328 pragma Assert
(Result
= 0);
335 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
336 Result
: Interfaces
.C
.int
;
338 All_Tasks_Link
: Task_ID
;
339 Current_Prio
: System
.Any_Priority
;
342 -- Perform ceiling checks only when this is the locking policy in use.
344 if Locking_Policy
= 'C' then
346 All_Tasks_Link
:= Self_ID
.Common
.All_Tasks_Link
;
347 Current_Prio
:= Get_Priority
(Self_ID
);
349 -- If there is no other task, no need to check priorities
351 if All_Tasks_Link
/= Null_Task
352 and then L
.Ceiling
< Interfaces
.C
.int
(Current_Prio
)
354 Ceiling_Violation
:= True;
359 Result
:= pthread_mutex_lock
(L
.L
'Access);
360 pragma Assert
(Result
= 0);
362 Ceiling_Violation
:= False;
366 (L
: access RTS_Lock
; Global_Lock
: Boolean := False)
368 Result
: Interfaces
.C
.int
;
370 if not Single_Lock
or else Global_Lock
then
371 Result
:= pthread_mutex_lock
(L
);
372 pragma Assert
(Result
= 0);
376 procedure Write_Lock
(T
: Task_ID
) is
377 Result
: Interfaces
.C
.int
;
379 if not Single_Lock
then
380 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
381 pragma Assert
(Result
= 0);
389 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
391 Write_Lock
(L
, Ceiling_Violation
);
398 procedure Unlock
(L
: access Lock
) is
399 Result
: Interfaces
.C
.int
;
401 Result
:= pthread_mutex_unlock
(L
.L
'Access);
402 pragma Assert
(Result
= 0);
405 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
406 Result
: Interfaces
.C
.int
;
408 if not Single_Lock
or else Global_Lock
then
409 Result
:= pthread_mutex_unlock
(L
);
410 pragma Assert
(Result
= 0);
414 procedure Unlock
(T
: Task_ID
) is
415 Result
: Interfaces
.C
.int
;
417 if not Single_Lock
then
418 Result
:= pthread_mutex_unlock
(T
.Common
.LL
.L
'Access);
419 pragma Assert
(Result
= 0);
429 Reason
: System
.Tasking
.Task_States
)
431 pragma Unreferenced
(Reason
);
433 Result
: Interfaces
.C
.int
;
437 Result
:= pthread_cond_wait
438 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access);
440 Result
:= pthread_cond_wait
441 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access);
444 -- EINTR is not considered a failure.
446 pragma Assert
(Result
= 0 or else Result
= EINTR
);
453 -- This is for use within the run-time system, so abort is
454 -- assumed to be already deferred, and the caller should be
455 -- holding its own ATCB lock.
457 procedure Timed_Sleep
460 Mode
: ST
.Delay_Modes
;
461 Reason
: System
.Tasking
.Task_States
;
462 Timedout
: out Boolean;
463 Yielded
: out Boolean)
465 pragma Unreferenced
(Reason
);
467 Check_Time
: constant Duration := Monotonic_Clock
;
469 Request
: aliased timespec
;
470 Result
: Interfaces
.C
.int
;
476 if Mode
= Relative
then
477 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
479 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
482 if Abs_Time
> Check_Time
then
483 Request
:= To_Timespec
(Abs_Time
);
486 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
487 or else Self_ID
.Pending_Priority_Change
;
490 Result
:= pthread_cond_timedwait
491 (Self_ID
.Common
.LL
.CV
'Access,
492 Single_RTS_Lock
'Access,
496 Result
:= pthread_cond_timedwait
497 (Self_ID
.Common
.LL
.CV
'Access,
498 Self_ID
.Common
.LL
.L
'Access,
502 exit when Abs_Time
<= Monotonic_Clock
;
504 if Result
= 0 or Result
= EINTR
then
506 -- Somebody may have called Wakeup for us
512 pragma Assert
(Result
= ETIMEDOUT
);
521 -- This is for use in implementing delay statements, so
522 -- we assume the caller is abort-deferred but is holding
525 procedure Timed_Delay
528 Mode
: ST
.Delay_Modes
)
530 Check_Time
: constant Duration := Monotonic_Clock
;
532 Request
: aliased timespec
;
533 Result
: Interfaces
.C
.int
;
536 -- Only the little window between deferring abort and
537 -- locking Self_ID is the reason we need to
538 -- check for pending abort and priority change below! :(
546 Write_Lock
(Self_ID
);
548 if Mode
= Relative
then
549 Abs_Time
:= Time
+ Check_Time
;
551 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
554 if Abs_Time
> Check_Time
then
555 Request
:= To_Timespec
(Abs_Time
);
556 Self_ID
.Common
.State
:= Delay_Sleep
;
559 if Self_ID
.Pending_Priority_Change
then
560 Self_ID
.Pending_Priority_Change
:= False;
561 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
562 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
565 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
568 Result
:= pthread_cond_timedwait
569 (Self_ID
.Common
.LL
.CV
'Access,
570 Single_RTS_Lock
'Access,
573 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
574 Self_ID
.Common
.LL
.L
'Access, Request
'Access);
577 exit when Abs_Time
<= Monotonic_Clock
;
579 pragma Assert
(Result
= 0 or else
580 Result
= ETIMEDOUT
or else
584 Self_ID
.Common
.State
:= Runnable
;
594 SSL
.Abort_Undefer
.all;
597 ---------------------
598 -- Monotonic_Clock --
599 ---------------------
601 function Monotonic_Clock
return Duration is
602 TS
: aliased timespec
;
603 Result
: Interfaces
.C
.int
;
606 Result
:= clock_gettime
(CLOCK_REALTIME
, TS
'Unchecked_Access);
607 pragma Assert
(Result
= 0);
608 return To_Duration
(TS
);
615 function RT_Resolution
return Duration is
617 return 1.0 / 1024.0; -- Clock on DEC Alpha ticks at 1024 Hz
624 procedure Wakeup
(T
: Task_ID
; Reason
: System
.Tasking
.Task_States
) is
625 pragma Unreferenced
(Reason
);
626 Result
: Interfaces
.C
.int
;
628 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
629 pragma Assert
(Result
= 0);
636 procedure Yield
(Do_Yield
: Boolean := True) is
637 Result
: Interfaces
.C
.int
;
638 pragma Unreferenced
(Result
);
641 Result
:= sched_yield
;
649 procedure Set_Priority
651 Prio
: System
.Any_Priority
;
652 Loss_Of_Inheritance
: Boolean := False)
654 pragma Unreferenced
(Loss_Of_Inheritance
);
656 Result
: Interfaces
.C
.int
;
657 Param
: aliased struct_sched_param
;
660 T
.Common
.Current_Priority
:= Prio
;
661 Param
.sched_priority
:= Interfaces
.C
.int
(Underlying_Priorities
(Prio
));
663 if Time_Slice_Val
> 0 then
664 Result
:= pthread_setschedparam
665 (T
.Common
.LL
.Thread
, SCHED_RR
, Param
'Access);
667 elsif FIFO_Within_Priorities
or else Time_Slice_Val
= 0 then
668 Result
:= pthread_setschedparam
669 (T
.Common
.LL
.Thread
, SCHED_FIFO
, Param
'Access);
672 Result
:= pthread_setschedparam
673 (T
.Common
.LL
.Thread
, SCHED_OTHER
, Param
'Access);
676 pragma Assert
(Result
= 0);
683 function Get_Priority
(T
: Task_ID
) return System
.Any_Priority
is
685 return T
.Common
.Current_Priority
;
692 procedure Enter_Task
(Self_ID
: Task_ID
) is
694 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
695 Specific
.Set
(Self_ID
);
699 for J
in Known_Tasks
'Range loop
700 if Known_Tasks
(J
) = null then
701 Known_Tasks
(J
) := Self_ID
;
702 Self_ID
.Known_Tasks_Index
:= J
;
714 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_ID
is
716 return new Ada_Task_Control_Block
(Entry_Num
);
723 function Is_Valid_Task
return Boolean renames Specific
.Is_Valid_Task
;
725 -----------------------------
726 -- Register_Foreign_Thread --
727 -----------------------------
729 function Register_Foreign_Thread
return Task_ID
is
731 if Is_Valid_Task
then
734 return Register_Foreign_Thread
(pthread_self
);
736 end Register_Foreign_Thread
;
742 procedure Initialize_TCB
(Self_ID
: Task_ID
; Succeeded
: out Boolean) is
743 Mutex_Attr
: aliased pthread_mutexattr_t
;
744 Result
: Interfaces
.C
.int
;
745 Cond_Attr
: aliased pthread_condattr_t
;
748 if not Single_Lock
then
749 Result
:= pthread_mutexattr_init
(Mutex_Attr
'Access);
750 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
753 Result
:= pthread_mutex_init
754 (Self_ID
.Common
.LL
.L
'Access, Mutex_Attr
'Access);
755 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
763 Result
:= pthread_mutexattr_destroy
(Mutex_Attr
'Access);
764 pragma Assert
(Result
= 0);
767 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
768 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
771 Result
:= pthread_cond_init
772 (Self_ID
.Common
.LL
.CV
'Access, Cond_Attr
'Access);
773 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
779 if not Single_Lock
then
780 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
781 pragma Assert
(Result
= 0);
787 Result
:= pthread_condattr_destroy
(Cond_Attr
'Access);
788 pragma Assert
(Result
= 0);
795 procedure Create_Task
797 Wrapper
: System
.Address
;
798 Stack_Size
: System
.Parameters
.Size_Type
;
799 Priority
: System
.Any_Priority
;
800 Succeeded
: out Boolean)
802 Attributes
: aliased pthread_attr_t
;
803 Adjusted_Stack_Size
: Interfaces
.C
.size_t
;
804 Result
: Interfaces
.C
.int
;
805 Param
: aliased System
.OS_Interface
.struct_sched_param
;
807 use System
.Task_Info
;
810 if Stack_Size
= Unspecified_Size
then
811 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Default_Stack_Size
);
813 elsif Stack_Size
< Minimum_Stack_Size
then
814 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Minimum_Stack_Size
);
817 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Stack_Size
);
820 Result
:= pthread_attr_init
(Attributes
'Access);
821 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
828 Result
:= pthread_attr_setdetachstate
829 (Attributes
'Access, PTHREAD_CREATE_DETACHED
);
830 pragma Assert
(Result
= 0);
832 Result
:= pthread_attr_setstacksize
833 (Attributes
'Access, Adjusted_Stack_Size
);
834 pragma Assert
(Result
= 0);
836 Param
.sched_priority
:=
837 Interfaces
.C
.int
(Underlying_Priorities
(Priority
));
838 Result
:= pthread_attr_setschedparam
839 (Attributes
'Access, Param
'Access);
840 pragma Assert
(Result
= 0);
842 if Time_Slice_Val
> 0 then
843 Result
:= pthread_attr_setschedpolicy
844 (Attributes
'Access, System
.OS_Interface
.SCHED_RR
);
846 elsif FIFO_Within_Priorities
or else Time_Slice_Val
= 0 then
847 Result
:= pthread_attr_setschedpolicy
848 (Attributes
'Access, System
.OS_Interface
.SCHED_FIFO
);
851 Result
:= pthread_attr_setschedpolicy
852 (Attributes
'Access, System
.OS_Interface
.SCHED_OTHER
);
855 pragma Assert
(Result
= 0);
857 -- Set the scheduling parameters explicitly, since this is the
858 -- only way to force the OS to take e.g. the sched policy and scope
859 -- attributes into account.
861 Result
:= pthread_attr_setinheritsched
862 (Attributes
'Access, PTHREAD_EXPLICIT_SCHED
);
863 pragma Assert
(Result
= 0);
865 T
.Common
.Current_Priority
:= Priority
;
867 if T
.Common
.Task_Info
/= null then
868 case T
.Common
.Task_Info
.Contention_Scope
is
869 when System
.Task_Info
.Process_Scope
=>
870 Result
:= pthread_attr_setscope
871 (Attributes
'Access, PTHREAD_SCOPE_PROCESS
);
873 when System
.Task_Info
.System_Scope
=>
874 Result
:= pthread_attr_setscope
875 (Attributes
'Access, PTHREAD_SCOPE_SYSTEM
);
877 when System
.Task_Info
.Default_Scope
=>
881 pragma Assert
(Result
= 0);
884 -- Since the initial signal mask of a thread is inherited from the
885 -- creator, and the Environment task has all its signals masked, we
886 -- do not need to manipulate caller's signal mask at this point.
887 -- All tasks in RTS will have All_Tasks_Mask initially.
889 Result
:= pthread_create
890 (T
.Common
.LL
.Thread
'Access,
892 Thread_Body_Access
(Wrapper
),
894 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
896 Succeeded
:= Result
= 0;
898 Result
:= pthread_attr_destroy
(Attributes
'Access);
899 pragma Assert
(Result
= 0);
901 if T
.Common
.Task_Info
/= null then
902 -- ??? We're using a process-wide function to implement a task
903 -- specific characteristic.
905 if T
.Common
.Task_Info
.Bind_To_Cpu_Number
= 0 then
906 Result
:= bind_to_cpu
(Curpid
, 0);
907 elsif T
.Common
.Task_Info
.Bind_To_Cpu_Number
> 0 then
908 Result
:= bind_to_cpu
910 Interfaces
.C
.unsigned_long
(
911 Interfaces
.Shift_Left
912 (Interfaces
.Unsigned_64
'(1),
913 T.Common.Task_Info.Bind_To_Cpu_Number - 1)));
914 pragma Assert (Result = 0);
923 procedure Finalize_TCB (T : Task_ID) is
924 Result : Interfaces.C.int;
926 Is_Self : constant Boolean := T = Self;
928 procedure Free is new
929 Unchecked_Deallocation (Ada_Task_Control_Block, Task_ID);
932 if not Single_Lock then
933 Result := pthread_mutex_destroy (T.Common.LL.L'Access);
934 pragma Assert (Result = 0);
937 Result := pthread_cond_destroy (T.Common.LL.CV'Access);
938 pragma Assert (Result = 0);
940 if T.Known_Tasks_Index /= -1 then
941 Known_Tasks (T.Known_Tasks_Index) := null;
955 procedure Exit_Task is
964 procedure Abort_Task (T : Task_ID) is
965 Result : Interfaces.C.int;
970 Signal (System.Interrupt_Management.Abort_Task_Interrupt));
971 pragma Assert (Result = 0);
980 function Check_Exit (Self_ID : ST.Task_ID) return Boolean is
981 pragma Unreferenced (Self_ID);
991 function Check_No_Locks (Self_ID : ST.Task_ID) return Boolean is
992 pragma Unreferenced (Self_ID);
998 ----------------------
999 -- Environment_Task --
1000 ----------------------
1002 function Environment_Task return Task_ID is
1004 return Environment_Task_ID;
1005 end Environment_Task;
1011 procedure Lock_RTS is
1013 Write_Lock (Single_RTS_Lock'Access, Global_Lock => True);
1020 procedure Unlock_RTS is
1022 Unlock (Single_RTS_Lock'Access, Global_Lock => True);
1029 function Suspend_Task
1031 Thread_Self : Thread_Id) return Boolean
1033 pragma Warnings (Off, T);
1034 pragma Warnings (Off, Thread_Self);
1044 function Resume_Task
1046 Thread_Self : Thread_Id) return Boolean
1048 pragma Warnings (Off, T);
1049 pragma Warnings (Off, Thread_Self);
1059 procedure Initialize (Environment_Task : Task_ID) is
1060 act : aliased struct_sigaction;
1061 old_act : aliased struct_sigaction;
1062 Tmp_Set : aliased sigset_t;
1063 Result : Interfaces.C.int;
1066 (Int : System.Interrupt_Management.Interrupt_ID) return Character;
1067 pragma Import (C, State, "__gnat_get_interrupt_state");
1068 -- Get interrupt state. Defined in a-init.c. The input argument is
1069 -- the interrupt number, and the result is one of the following:
1071 Default : constant Character := 's
';
1072 -- 'n
' this interrupt not set by any Interrupt_State pragma
1073 -- 'u
' Interrupt_State pragma set state to User
1074 -- 'r
' Interrupt_State pragma set state to Runtime
1075 -- 's
' Interrupt_State pragma set state to System (use "default"
1079 Environment_Task_ID := Environment_Task;
1081 -- Initialize the lock used to synchronize chain of all ATCBs.
1083 Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
1085 Specific.Initialize (Environment_Task);
1087 Enter_Task (Environment_Task);
1089 -- Install the abort-signal handler
1091 if State (System.Interrupt_Management.Abort_Task_Interrupt)
1095 act.sa_handler := Abort_Handler'Address;
1097 Result := sigemptyset (Tmp_Set'Access);
1098 pragma Assert (Result = 0);
1099 act.sa_mask := Tmp_Set;
1103 (Signal (System.Interrupt_Management.Abort_Task_Interrupt),
1104 act'Unchecked_Access,
1105 old_act'Unchecked_Access);
1106 pragma Assert (Result = 0);
1112 Result : Interfaces.C.int;
1115 -- Mask Environment task for all signals. The original mask of the
1116 -- Environment task will be recovered by Interrupt_Server task
1117 -- during the elaboration of s-interr.adb.
1119 System.Interrupt_Management.Operations.Set_Interrupt_Mask
1120 (System.Interrupt_Management.Operations.All_Tasks_Mask'Access);
1122 -- Prepare the set of signals that should unblocked in all tasks
1124 Result := sigemptyset (Unblocked_Signal_Mask'Access);
1125 pragma Assert (Result = 0);
1127 for J in Interrupt_Management.Interrupt_ID loop
1128 if System.Interrupt_Management.Keep_Unmasked (J) then
1129 Result := sigaddset (Unblocked_Signal_Mask'Access, Signal (J));
1130 pragma Assert (Result = 0);
1136 end System.Task_Primitives.Operations;