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 HP-UX DCE threads (HPUX 10) 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
;
63 with System
.Task_Primitives
.Interrupt_Operations
;
64 -- used for Get_Interrupt_ID
67 -- used for Ada_Task_Control_Block
70 with System
.Soft_Links
;
71 -- used for Defer/Undefer_Abort
73 -- Note that we do not use System.Tasking.Initialization directly since
74 -- this is a higher level package that we shouldn't depend on. For example
75 -- when using the restricted run time, it is replaced by
76 -- System.Tasking.Restricted.Initialization
78 with System
.OS_Primitives
;
79 -- used for Delay_Modes
81 with Unchecked_Conversion
;
82 with Unchecked_Deallocation
;
84 package body System
.Task_Primitives
.Operations
is
86 use System
.Tasking
.Debug
;
89 use System
.OS_Interface
;
90 use System
.Parameters
;
91 use System
.OS_Primitives
;
93 package PIO
renames System
.Task_Primitives
.Interrupt_Operations
;
94 package SSL
renames System
.Soft_Links
;
100 -- The followings are logically constants, but need to be initialized
103 Single_RTS_Lock
: aliased RTS_Lock
;
104 -- This is a lock to allow only one thread of control in the RTS at
105 -- a time; it is used to execute in mutual exclusion from all other tasks.
106 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
108 ATCB_Key
: aliased pthread_key_t
;
109 -- Key used to find the Ada Task_ID associated with a thread
111 Environment_Task_ID
: Task_ID
;
112 -- A variable to hold Task_ID for the environment task.
114 Unblocked_Signal_Mask
: aliased sigset_t
;
115 -- The set of signals that should unblocked in all tasks
117 Time_Slice_Val
: Integer;
118 pragma Import
(C
, Time_Slice_Val
, "__gl_time_slice_val");
120 Dispatching_Policy
: Character;
121 pragma Import
(C
, Dispatching_Policy
, "__gl_task_dispatching_policy");
123 -- Note: the reason that Locking_Policy is not needed is that this
124 -- is not implemented for DCE threads. The HPUX 10 port is at this
125 -- stage considered dead, and no further work is planned on it.
127 FIFO_Within_Priorities
: constant Boolean := Dispatching_Policy
= 'F';
128 -- Indicates whether FIFO_Within_Priorities is set.
130 Foreign_Task_Elaborated
: aliased Boolean := True;
131 -- Used to identified fake tasks (i.e., non-Ada Threads).
139 procedure Initialize
(Environment_Task
: Task_ID
);
140 pragma Inline
(Initialize
);
141 -- Initialize various data needed by this package.
143 function Is_Valid_Task
return Boolean;
144 pragma Inline
(Is_Valid_Task
);
145 -- Does the executing thread have a TCB?
147 procedure Set
(Self_Id
: Task_ID
);
149 -- Set the self id for the current task.
151 function Self
return Task_ID
;
152 pragma Inline
(Self
);
153 -- Return a pointer to the Ada Task Control Block of the calling task.
157 package body Specific
is separate;
158 -- The body of this package is target specific.
160 ---------------------------------
161 -- Support for foreign threads --
162 ---------------------------------
164 function Register_Foreign_Thread
(Thread
: Thread_Id
) return Task_ID
;
165 -- Allocate and Initialize a new ATCB for the current Thread.
167 function Register_Foreign_Thread
168 (Thread
: Thread_Id
) return Task_ID
is separate;
170 -----------------------
171 -- Local Subprograms --
172 -----------------------
174 procedure Abort_Handler
(Sig
: Signal
);
176 function To_Address
is new Unchecked_Conversion
(Task_ID
, System
.Address
);
182 procedure Abort_Handler
(Sig
: Signal
) is
183 pragma Unreferenced
(Sig
);
185 Self_Id
: constant Task_ID
:= Self
;
186 Result
: Interfaces
.C
.int
;
187 Old_Set
: aliased sigset_t
;
190 if Self_Id
.Deferral_Level
= 0
191 and then Self_Id
.Pending_ATC_Level
< Self_Id
.ATC_Nesting_Level
and then
194 Self_Id
.Aborting
:= True;
196 -- Make sure signals used for RTS internal purpose are unmasked
198 Result
:= pthread_sigmask
(SIG_UNBLOCK
,
199 Unblocked_Signal_Mask
'Unchecked_Access, Old_Set
'Unchecked_Access);
200 pragma Assert
(Result
= 0);
202 raise Standard
'Abort_Signal;
210 -- The underlying thread system sets a guard page at the
211 -- bottom of a thread stack, so nothing is needed.
212 -- ??? Check the comment above
214 procedure Stack_Guard
(T
: ST
.Task_ID
; On
: Boolean) is
215 pragma Unreferenced
(T
, On
);
224 function Get_Thread_Id
(T
: ST
.Task_ID
) return OSI
.Thread_Id
is
226 return T
.Common
.LL
.Thread
;
233 function Self
return Task_ID
renames Specific
.Self
;
235 ---------------------
236 -- Initialize_Lock --
237 ---------------------
239 -- Note: mutexes and cond_variables needed per-task basis are
240 -- initialized in Initialize_TCB and the Storage_Error is
241 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
242 -- used in RTS is initialized before any status change of RTS.
243 -- Therefore rasing Storage_Error in the following routines
244 -- should be able to be handled safely.
246 procedure Initialize_Lock
247 (Prio
: System
.Any_Priority
;
250 Attributes
: aliased pthread_mutexattr_t
;
251 Result
: Interfaces
.C
.int
;
254 Result
:= pthread_mutexattr_init
(Attributes
'Access);
255 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
257 if Result
= ENOMEM
then
263 Result
:= pthread_mutex_init
(L
.L
'Access, Attributes
'Access);
264 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
266 if Result
= ENOMEM
then
270 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
271 pragma Assert
(Result
= 0);
274 procedure Initialize_Lock
(L
: access RTS_Lock
; Level
: Lock_Level
) is
275 pragma Unreferenced
(Level
);
277 Attributes
: aliased pthread_mutexattr_t
;
278 Result
: Interfaces
.C
.int
;
281 Result
:= pthread_mutexattr_init
(Attributes
'Access);
282 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
284 if Result
= ENOMEM
then
288 Result
:= pthread_mutex_init
(L
, Attributes
'Access);
290 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
292 if Result
= ENOMEM
then
296 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
297 pragma Assert
(Result
= 0);
304 procedure Finalize_Lock
(L
: access Lock
) is
305 Result
: Interfaces
.C
.int
;
307 Result
:= pthread_mutex_destroy
(L
.L
'Access);
308 pragma Assert
(Result
= 0);
311 procedure Finalize_Lock
(L
: access RTS_Lock
) is
312 Result
: Interfaces
.C
.int
;
314 Result
:= pthread_mutex_destroy
(L
);
315 pragma Assert
(Result
= 0);
322 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
323 Result
: Interfaces
.C
.int
;
326 L
.Owner_Priority
:= Get_Priority
(Self
);
328 if L
.Priority
< L
.Owner_Priority
then
329 Ceiling_Violation
:= True;
333 Result
:= pthread_mutex_lock
(L
.L
'Access);
334 pragma Assert
(Result
= 0);
335 Ceiling_Violation
:= False;
339 (L
: access RTS_Lock
; Global_Lock
: Boolean := False)
341 Result
: Interfaces
.C
.int
;
344 if not Single_Lock
or else Global_Lock
then
345 Result
:= pthread_mutex_lock
(L
);
346 pragma Assert
(Result
= 0);
350 procedure Write_Lock
(T
: Task_ID
) is
351 Result
: Interfaces
.C
.int
;
354 if not Single_Lock
then
355 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
356 pragma Assert
(Result
= 0);
364 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
366 Write_Lock
(L
, Ceiling_Violation
);
373 procedure Unlock
(L
: access Lock
) is
374 Result
: Interfaces
.C
.int
;
377 Result
:= pthread_mutex_unlock
(L
.L
'Access);
378 pragma Assert
(Result
= 0);
381 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
382 Result
: Interfaces
.C
.int
;
384 if not Single_Lock
or else Global_Lock
then
385 Result
:= pthread_mutex_unlock
(L
);
386 pragma Assert
(Result
= 0);
390 procedure Unlock
(T
: Task_ID
) is
391 Result
: Interfaces
.C
.int
;
394 if not Single_Lock
then
395 Result
:= pthread_mutex_unlock
(T
.Common
.LL
.L
'Access);
396 pragma Assert
(Result
= 0);
406 Reason
: System
.Tasking
.Task_States
)
408 pragma Unreferenced
(Reason
);
410 Result
: Interfaces
.C
.int
;
413 Result
:= pthread_cond_wait
414 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access);
416 Result
:= pthread_cond_wait
417 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access);
420 -- EINTR is not considered a failure.
421 pragma Assert
(Result
= 0 or else Result
= EINTR
);
428 procedure Timed_Sleep
431 Mode
: ST
.Delay_Modes
;
432 Reason
: System
.Tasking
.Task_States
;
433 Timedout
: out Boolean;
434 Yielded
: out Boolean)
436 pragma Unreferenced
(Reason
);
438 Check_Time
: constant Duration := Monotonic_Clock
;
440 Request
: aliased timespec
;
441 Result
: Interfaces
.C
.int
;
447 if Mode
= Relative
then
448 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
450 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
453 if Abs_Time
> Check_Time
then
454 Request
:= To_Timespec
(Abs_Time
);
457 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
458 or else Self_ID
.Pending_Priority_Change
;
461 Result
:= pthread_cond_timedwait
462 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access,
466 Result
:= pthread_cond_timedwait
467 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access,
471 exit when Abs_Time
<= Monotonic_Clock
;
473 if Result
= 0 or Result
= EINTR
then
475 -- Somebody may have called Wakeup for us
481 pragma Assert
(Result
= ETIMEDOUT
);
490 procedure Timed_Delay
493 Mode
: ST
.Delay_Modes
)
495 Check_Time
: constant Duration := Monotonic_Clock
;
497 Request
: aliased timespec
;
498 Result
: Interfaces
.C
.int
;
501 -- Only the little window between deferring abort and
502 -- locking Self_ID is the reason we need to
503 -- check for pending abort and priority change below! :(
511 Write_Lock
(Self_ID
);
513 if Mode
= Relative
then
514 Abs_Time
:= Time
+ Check_Time
;
516 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
519 if Abs_Time
> Check_Time
then
520 Request
:= To_Timespec
(Abs_Time
);
521 Self_ID
.Common
.State
:= Delay_Sleep
;
524 if Self_ID
.Pending_Priority_Change
then
525 Self_ID
.Pending_Priority_Change
:= False;
526 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
527 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
530 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
533 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
534 Single_RTS_Lock
'Access, Request
'Access);
536 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
537 Self_ID
.Common
.LL
.L
'Access, Request
'Access);
540 exit when Abs_Time
<= Monotonic_Clock
;
542 pragma Assert
(Result
= 0 or else
543 Result
= ETIMEDOUT
or else
547 Self_ID
.Common
.State
:= Runnable
;
556 Result
:= sched_yield
;
557 SSL
.Abort_Undefer
.all;
560 ---------------------
561 -- Monotonic_Clock --
562 ---------------------
564 function Monotonic_Clock
return Duration is
565 TS
: aliased timespec
;
566 Result
: Interfaces
.C
.int
;
569 Result
:= Clock_Gettime
(CLOCK_REALTIME
, TS
'Unchecked_Access);
570 pragma Assert
(Result
= 0);
571 return To_Duration
(TS
);
578 function RT_Resolution
return Duration is
587 procedure Wakeup
(T
: Task_ID
; Reason
: System
.Tasking
.Task_States
) is
588 pragma Unreferenced
(Reason
);
590 Result
: Interfaces
.C
.int
;
593 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
594 pragma Assert
(Result
= 0);
601 procedure Yield
(Do_Yield
: Boolean := True) is
602 Result
: Interfaces
.C
.int
;
603 pragma Unreferenced
(Result
);
606 Result
:= sched_yield
;
614 type Prio_Array_Type
is array (System
.Any_Priority
) of Integer;
615 pragma Atomic_Components
(Prio_Array_Type
);
617 Prio_Array
: Prio_Array_Type
;
618 -- Global array containing the id of the currently running task for
621 -- Note: we assume that we are on a single processor with run-til-blocked
624 procedure Set_Priority
626 Prio
: System
.Any_Priority
;
627 Loss_Of_Inheritance
: Boolean := False)
629 Result
: Interfaces
.C
.int
;
630 Array_Item
: Integer;
631 Param
: aliased struct_sched_param
;
634 Param
.sched_priority
:= Interfaces
.C
.int
(Underlying_Priorities
(Prio
));
636 if Time_Slice_Val
> 0 then
637 Result
:= pthread_setschedparam
638 (T
.Common
.LL
.Thread
, SCHED_RR
, Param
'Access);
640 elsif FIFO_Within_Priorities
or else Time_Slice_Val
= 0 then
641 Result
:= pthread_setschedparam
642 (T
.Common
.LL
.Thread
, SCHED_FIFO
, Param
'Access);
645 Result
:= pthread_setschedparam
646 (T
.Common
.LL
.Thread
, SCHED_OTHER
, Param
'Access);
649 pragma Assert
(Result
= 0);
651 if FIFO_Within_Priorities
then
653 -- Annex D requirement [RM D.2.2 par. 9]:
654 -- If the task drops its priority due to the loss of inherited
655 -- priority, it is added at the head of the ready queue for its
656 -- new active priority.
658 if Loss_Of_Inheritance
659 and then Prio
< T
.Common
.Current_Priority
661 Array_Item
:= Prio_Array
(T
.Common
.Base_Priority
) + 1;
662 Prio_Array
(T
.Common
.Base_Priority
) := Array_Item
;
665 -- Let some processes a chance to arrive
669 -- Then wait for our turn to proceed
671 exit when Array_Item
= Prio_Array
(T
.Common
.Base_Priority
)
672 or else Prio_Array
(T
.Common
.Base_Priority
) = 1;
675 Prio_Array
(T
.Common
.Base_Priority
) :=
676 Prio_Array
(T
.Common
.Base_Priority
) - 1;
680 T
.Common
.Current_Priority
:= Prio
;
687 function Get_Priority
(T
: Task_ID
) return System
.Any_Priority
is
689 return T
.Common
.Current_Priority
;
696 procedure Enter_Task
(Self_ID
: Task_ID
) is
698 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
699 Specific
.Set
(Self_ID
);
703 for J
in Known_Tasks
'Range loop
704 if Known_Tasks
(J
) = null then
705 Known_Tasks
(J
) := Self_ID
;
706 Self_ID
.Known_Tasks_Index
:= J
;
718 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_ID
is
720 return new Ada_Task_Control_Block
(Entry_Num
);
727 function Is_Valid_Task
return Boolean renames Specific
.Is_Valid_Task
;
729 -----------------------------
730 -- Register_Foreign_Thread --
731 -----------------------------
733 function Register_Foreign_Thread
return Task_ID
is
735 if Is_Valid_Task
then
738 return Register_Foreign_Thread
(pthread_self
);
740 end Register_Foreign_Thread
;
746 procedure Initialize_TCB
(Self_ID
: Task_ID
; Succeeded
: out Boolean) is
747 Mutex_Attr
: aliased pthread_mutexattr_t
;
748 Result
: Interfaces
.C
.int
;
749 Cond_Attr
: aliased pthread_condattr_t
;
752 if not Single_Lock
then
753 Result
:= pthread_mutexattr_init
(Mutex_Attr
'Access);
754 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
757 Result
:= pthread_mutex_init
(Self_ID
.Common
.LL
.L
'Access,
759 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
767 Result
:= pthread_mutexattr_destroy
(Mutex_Attr
'Access);
768 pragma Assert
(Result
= 0);
771 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
772 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
775 Result
:= pthread_cond_init
(Self_ID
.Common
.LL
.CV
'Access,
777 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
783 if not Single_Lock
then
784 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
785 pragma Assert
(Result
= 0);
791 Result
:= pthread_condattr_destroy
(Cond_Attr
'Access);
792 pragma Assert
(Result
= 0);
799 procedure Create_Task
801 Wrapper
: System
.Address
;
802 Stack_Size
: System
.Parameters
.Size_Type
;
803 Priority
: System
.Any_Priority
;
804 Succeeded
: out Boolean)
806 Attributes
: aliased pthread_attr_t
;
807 Adjusted_Stack_Size
: Interfaces
.C
.size_t
;
808 Result
: Interfaces
.C
.int
;
810 function Thread_Body_Access
is new
811 Unchecked_Conversion
(System
.Address
, Thread_Body
);
814 if Stack_Size
= Unspecified_Size
then
815 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Default_Stack_Size
);
817 elsif Stack_Size
< Minimum_Stack_Size
then
818 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Minimum_Stack_Size
);
821 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Stack_Size
);
824 Result
:= pthread_attr_init
(Attributes
'Access);
825 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
832 Result
:= pthread_attr_setstacksize
833 (Attributes
'Access, Adjusted_Stack_Size
);
834 pragma Assert
(Result
= 0);
836 -- Since the initial signal mask of a thread is inherited from the
837 -- creator, and the Environment task has all its signals masked, we
838 -- do not need to manipulate caller's signal mask at this point.
839 -- All tasks in RTS will have All_Tasks_Mask initially.
841 Result
:= pthread_create
842 (T
.Common
.LL
.Thread
'Access,
844 Thread_Body_Access
(Wrapper
),
846 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
848 Succeeded
:= Result
= 0;
850 pthread_detach
(T
.Common
.LL
.Thread
'Access);
851 -- Detach the thread using pthread_detach, sinc DCE threads do not have
852 -- pthread_attr_set_detachstate.
854 Result
:= pthread_attr_destroy
(Attributes
'Access);
855 pragma Assert
(Result
= 0);
857 Set_Priority
(T
, Priority
);
864 procedure Finalize_TCB
(T
: Task_ID
) is
865 Result
: Interfaces
.C
.int
;
867 Is_Self
: constant Boolean := T
= Self
;
869 procedure Free
is new
870 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_ID
);
873 if not Single_Lock
then
874 Result
:= pthread_mutex_destroy
(T
.Common
.LL
.L
'Access);
875 pragma Assert
(Result
= 0);
878 Result
:= pthread_cond_destroy
(T
.Common
.LL
.CV
'Access);
879 pragma Assert
(Result
= 0);
881 if T
.Known_Tasks_Index
/= -1 then
882 Known_Tasks
(T
.Known_Tasks_Index
) := null;
896 procedure Exit_Task
is
905 procedure Abort_Task
(T
: Task_ID
) is
908 -- Interrupt Server_Tasks may be waiting on an "event" flag (signal)
910 if T
.Common
.State
= Interrupt_Server_Blocked_On_Event_Flag
then
911 System
.Interrupt_Management
.Operations
.Interrupt_Self_Process
912 (System
.Interrupt_Management
.Interrupt_ID
913 (PIO
.Get_Interrupt_ID
(T
)));
921 -- Dummy versions. The only currently working versions is for solaris
924 function Check_Exit
(Self_ID
: ST
.Task_ID
) return Boolean is
925 pragma Unreferenced
(Self_ID
);
934 function Check_No_Locks
(Self_ID
: ST
.Task_ID
) return Boolean is
935 pragma Unreferenced
(Self_ID
);
940 ----------------------
941 -- Environment_Task --
942 ----------------------
944 function Environment_Task
return Task_ID
is
946 return Environment_Task_ID
;
947 end Environment_Task
;
953 procedure Lock_RTS
is
955 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
962 procedure Unlock_RTS
is
964 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
971 function Suspend_Task
973 Thread_Self
: Thread_Id
)
976 pragma Unreferenced
(T
);
977 pragma Unreferenced
(Thread_Self
);
989 Thread_Self
: Thread_Id
)
992 pragma Unreferenced
(T
);
993 pragma Unreferenced
(Thread_Self
);
1003 procedure Initialize
(Environment_Task
: Task_ID
) is
1004 act
: aliased struct_sigaction
;
1005 old_act
: aliased struct_sigaction
;
1006 Tmp_Set
: aliased sigset_t
;
1007 Result
: Interfaces
.C
.int
;
1009 function State
(Int
: System
.Interrupt_Management
.Interrupt_ID
)
1011 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
1012 -- Get interrupt state. Defined in a-init.c
1013 -- The input argument is the interrupt number,
1014 -- and the result is one of the following:
1016 Default
: constant Character := 's';
1017 -- 'n' this interrupt not set by any Interrupt_State pragma
1018 -- 'u' Interrupt_State pragma set state to User
1019 -- 'r' Interrupt_State pragma set state to Runtime
1020 -- 's' Interrupt_State pragma set state to System (use "default"
1024 Environment_Task_ID
:= Environment_Task
;
1026 -- Initialize the lock used to synchronize chain of all ATCBs.
1028 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
1030 Specific
.Initialize
(Environment_Task
);
1032 Enter_Task
(Environment_Task
);
1034 -- Install the abort-signal handler
1036 if State
(System
.Interrupt_Management
.Abort_Task_Interrupt
)
1040 act
.sa_handler
:= Abort_Handler
'Address;
1042 Result
:= sigemptyset
(Tmp_Set
'Access);
1043 pragma Assert
(Result
= 0);
1044 act
.sa_mask
:= Tmp_Set
;
1048 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
),
1049 act
'Unchecked_Access,
1050 old_act
'Unchecked_Access);
1051 pragma Assert
(Result
= 0);
1055 -- NOTE: Unlike other pthread implementations, we do *not* mask all
1056 -- signals here since we handle signals using the process-wide primitive
1057 -- signal, rather than using sigthreadmask and sigwait. The reason of
1058 -- this difference is that sigwait doesn't work when some critical
1059 -- signals (SIGABRT, SIGPIPE) are masked.
1061 end System
.Task_Primitives
.Operations
;