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 --
11 -- Copyright (C) 1991-2001, Florida State University --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
37 -- This is a IRIX (pthread library) version of this package.
39 -- This package contains all the GNULL primitives that interface directly
40 -- with the underlying OS.
43 -- Turn off polling, we do not want ATC polling to take place during
44 -- tasking operations. It causes infinite loops and other problems.
50 with System
.Task_Info
;
52 with System
.Tasking
.Debug
;
53 -- used for Known_Tasks
58 with System
.Interrupt_Management
;
59 -- used for Keep_Unmasked
60 -- Abort_Task_Interrupt
63 with System
.Interrupt_Management
.Operations
;
64 -- used for Set_Interrupt_Mask
66 pragma Elaborate_All
(System
.Interrupt_Management
.Operations
);
68 with System
.Parameters
;
72 -- used for Ada_Task_Control_Block
75 with System
.Soft_Links
;
76 -- used for Defer/Undefer_Abort
78 -- Note that we do not use System.Tasking.Initialization directly since
79 -- this is a higher level package that we shouldn't depend on. For example
80 -- when using the restricted run time, it is replaced by
81 -- System.Tasking.Restricted.Initialization
83 with System
.Program_Info
;
84 -- used for Default_Task_Stack
87 -- Pthread_Sched_Signal
90 with System
.OS_Interface
;
91 -- used for various type, constant, and operations
93 with System
.OS_Primitives
;
94 -- used for Delay_Modes
96 with Unchecked_Conversion
;
97 with Unchecked_Deallocation
;
99 package body System
.Task_Primitives
.Operations
is
102 use System
.Tasking
.Debug
;
104 use System
.OS_Interface
;
105 use System
.OS_Primitives
;
106 use System
.Parameters
;
108 package SSL
renames System
.Soft_Links
;
114 -- The followings are logically constants, but need to be initialized
117 ATCB_Key
: aliased pthread_key_t
;
118 -- Key used to find the Ada Task_ID associated with a thread
120 All_Tasks_L
: aliased System
.Task_Primitives
.RTS_Lock
;
121 -- See comments on locking rules in System.Locking_Rules (spec).
123 Environment_Task_ID
: Task_ID
;
124 -- A variable to hold Task_ID for the environment task.
126 Locking_Policy
: Character;
127 pragma Import
(C
, Locking_Policy
, "__gl_locking_policy");
129 Real_Time_Clock_Id
: constant clockid_t
:= CLOCK_REALTIME
;
131 Unblocked_Signal_Mask
: aliased sigset_t
;
133 -----------------------
134 -- Local Subprograms --
135 -----------------------
137 function To_Task_ID
is new Unchecked_Conversion
(System
.Address
, Task_ID
);
139 function To_Address
is new Unchecked_Conversion
(Task_ID
, System
.Address
);
141 procedure Abort_Handler
(Sig
: Signal
);
147 procedure Abort_Handler
(Sig
: Signal
) is
149 Result
: Interfaces
.C
.int
;
150 Old_Set
: aliased sigset_t
;
153 if T
.Deferral_Level
= 0
154 and then T
.Pending_ATC_Level
< T
.ATC_Nesting_Level
156 -- Make sure signals used for RTS internal purpose are unmasked
158 Result
:= pthread_sigmask
160 Unblocked_Signal_Mask
'Unchecked_Access,
161 Old_Set
'Unchecked_Access);
162 pragma Assert
(Result
= 0);
164 raise Standard
'Abort_Signal;
172 -- The underlying thread system sets a guard page at the
173 -- bottom of a thread stack, so nothing is needed.
175 procedure Stack_Guard
(T
: ST
.Task_ID
; On
: Boolean) is
184 function Get_Thread_Id
(T
: ST
.Task_ID
) return OSI
.Thread_Id
is
186 return T
.Common
.LL
.Thread
;
193 function Self
return Task_ID
is
194 Result
: System
.Address
;
197 Result
:= pthread_getspecific
(ATCB_Key
);
198 pragma Assert
(Result
/= System
.Null_Address
);
200 return To_Task_ID
(Result
);
203 ---------------------
204 -- Initialize_Lock --
205 ---------------------
207 -- Note: mutexes and cond_variables needed per-task basis are
208 -- initialized in Intialize_TCB and the Storage_Error is
209 -- handled. Other mutexes (such as All_Tasks_Lock, Memory_Lock...)
210 -- used in RTS is initialized before any status change of RTS.
211 -- Therefore rasing Storage_Error in the following routines
212 -- should be able to be handled safely.
214 procedure Initialize_Lock
215 (Prio
: System
.Any_Priority
;
218 Attributes
: aliased pthread_mutexattr_t
;
219 Result
: Interfaces
.C
.int
;
222 Result
:= pthread_mutexattr_init
(Attributes
'Access);
223 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
225 if Result
= ENOMEM
then
229 if Locking_Policy
= 'C' then
230 Result
:= pthread_mutexattr_setprotocol
231 (Attributes
'Access, PTHREAD_PRIO_PROTECT
);
232 pragma Assert
(Result
= 0);
234 Result
:= pthread_mutexattr_setprioceiling
235 (Attributes
'Access, Interfaces
.C
.int
(Prio
));
236 pragma Assert
(Result
= 0);
239 Result
:= pthread_mutex_init
(L
, Attributes
'Access);
240 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
242 if Result
= ENOMEM
then
243 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
247 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
248 pragma Assert
(Result
= 0);
251 procedure Initialize_Lock
(L
: access RTS_Lock
; Level
: Lock_Level
) is
252 Attributes
: aliased pthread_mutexattr_t
;
253 Result
: Interfaces
.C
.int
;
256 Result
:= pthread_mutexattr_init
(Attributes
'Access);
257 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
259 if Result
= ENOMEM
then
263 if Locking_Policy
= 'C' then
264 Result
:= pthread_mutexattr_setprotocol
265 (Attributes
'Access, PTHREAD_PRIO_PROTECT
);
266 pragma Assert
(Result
= 0);
268 Result
:= pthread_mutexattr_setprioceiling
269 (Attributes
'Access, Interfaces
.C
.int
(System
.Any_Priority
'Last));
270 pragma Assert
(Result
= 0);
273 Result
:= pthread_mutex_init
(L
, Attributes
'Access);
275 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
277 if Result
= ENOMEM
then
278 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
282 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
289 procedure Finalize_Lock
(L
: access Lock
) is
290 Result
: Interfaces
.C
.int
;
293 Result
:= pthread_mutex_destroy
(L
);
294 pragma Assert
(Result
= 0);
297 procedure Finalize_Lock
(L
: access RTS_Lock
) is
298 Result
: Interfaces
.C
.int
;
301 Result
:= pthread_mutex_destroy
(L
);
302 pragma Assert
(Result
= 0);
309 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
310 Result
: Interfaces
.C
.int
;
313 Result
:= pthread_mutex_lock
(L
);
314 Ceiling_Violation
:= Result
= EINVAL
;
316 -- assumes the cause of EINVAL is a priority ceiling violation
318 pragma Assert
(Result
= 0 or else Result
= EINVAL
);
321 procedure Write_Lock
(L
: access RTS_Lock
) is
322 Result
: Interfaces
.C
.int
;
325 Result
:= pthread_mutex_lock
(L
);
326 pragma Assert
(Result
= 0);
329 procedure Write_Lock
(T
: Task_ID
) is
330 Result
: Interfaces
.C
.int
;
333 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
334 pragma Assert
(Result
= 0);
341 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
343 Write_Lock
(L
, Ceiling_Violation
);
350 procedure Unlock
(L
: access Lock
) is
351 Result
: Interfaces
.C
.int
;
354 Result
:= pthread_mutex_unlock
(L
);
355 pragma Assert
(Result
= 0);
358 procedure Unlock
(L
: access RTS_Lock
) is
359 Result
: Interfaces
.C
.int
;
362 Result
:= pthread_mutex_unlock
(L
);
363 pragma Assert
(Result
= 0);
366 procedure Unlock
(T
: Task_ID
) is
367 Result
: Interfaces
.C
.int
;
370 Result
:= pthread_mutex_unlock
(T
.Common
.LL
.L
'Access);
371 pragma Assert
(Result
= 0);
379 (Self_ID
: ST
.Task_ID
;
380 Reason
: System
.Tasking
.Task_States
)
382 Result
: Interfaces
.C
.int
;
384 pragma Assert
(Self_ID
= Self
);
385 Result
:= pthread_cond_wait
(Self_ID
.Common
.LL
.CV
'Access,
386 Self_ID
.Common
.LL
.L
'Access);
388 -- EINTR is not considered a failure.
390 pragma Assert
(Result
= 0 or else Result
= EINTR
);
397 procedure Timed_Sleep
400 Mode
: ST
.Delay_Modes
;
401 Reason
: Task_States
;
402 Timedout
: out Boolean;
403 Yielded
: out Boolean)
405 Check_Time
: constant Duration := Monotonic_Clock
;
407 Request
: aliased timespec
;
408 Result
: Interfaces
.C
.int
;
414 if Mode
= Relative
then
415 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
417 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
420 if Abs_Time
> Check_Time
then
421 Request
:= To_Timespec
(Abs_Time
);
424 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
425 or else Self_ID
.Pending_Priority_Change
;
427 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
428 Self_ID
.Common
.LL
.L
'Access, Request
'Access);
430 exit when Abs_Time
<= Monotonic_Clock
;
432 if Result
= 0 or else errno
= EINTR
then
444 -- This is for use in implementing delay statements, so
445 -- we assume the caller is abort-deferred but is holding
448 procedure Timed_Delay
451 Mode
: ST
.Delay_Modes
)
453 Check_Time
: constant Duration := Monotonic_Clock
;
455 Request
: aliased timespec
;
456 Result
: Interfaces
.C
.int
;
459 -- Only the little window between deferring abort and
460 -- locking Self_ID is the reason we need to
461 -- check for pending abort and priority change below! :(
464 Write_Lock
(Self_ID
);
466 if Mode
= Relative
then
467 Abs_Time
:= Time
+ Check_Time
;
469 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
472 if Abs_Time
> Check_Time
then
473 Request
:= To_Timespec
(Abs_Time
);
474 Self_ID
.Common
.State
:= Delay_Sleep
;
477 if Self_ID
.Pending_Priority_Change
then
478 Self_ID
.Pending_Priority_Change
:= False;
479 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
480 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
483 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
485 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
486 Self_ID
.Common
.LL
.L
'Access, Request
'Access);
487 exit when Abs_Time
<= Monotonic_Clock
;
489 pragma Assert
(Result
= 0
490 or else Result
= ETIMEDOUT
491 or else Result
= EINTR
);
494 Self_ID
.Common
.State
:= Runnable
;
499 SSL
.Abort_Undefer
.all;
502 ---------------------
503 -- Monotonic_Clock --
504 ---------------------
506 function Monotonic_Clock
return Duration is
507 TS
: aliased timespec
;
508 Result
: Interfaces
.C
.int
;
511 Result
:= clock_gettime
(Real_Time_Clock_Id
, TS
'Unchecked_Access);
512 pragma Assert
(Result
= 0);
513 return To_Duration
(TS
);
520 function RT_Resolution
return Duration is
522 -- The clock_getres (Real_Time_Clock_Id) function appears to return
523 -- the interrupt resolution of the realtime clock and not the actual
524 -- resolution of reading the clock. Even though this last value is
525 -- only guaranteed to be 100 Hz, at least the Origin 200 appears to
526 -- have a microsecond resolution or better.
527 -- ??? We should figure out a method to return the right value on
530 return 0.000_001
; -- Assume microsecond resolution of clock
537 procedure Wakeup
(T
: ST
.Task_ID
; Reason
: System
.Tasking
.Task_States
) is
538 Result
: Interfaces
.C
.int
;
540 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
541 pragma Assert
(Result
= 0);
548 procedure Yield
(Do_Yield
: Boolean := True) is
549 Result
: Interfaces
.C
.int
;
552 Result
:= sched_yield
;
560 procedure Set_Priority
562 Prio
: System
.Any_Priority
;
563 Loss_Of_Inheritance
: Boolean := False)
565 Result
: Interfaces
.C
.int
;
566 Param
: aliased struct_sched_param
;
567 Sched_Policy
: Interfaces
.C
.int
;
569 use type System
.Task_Info
.Task_Info_Type
;
571 function To_Int
is new Unchecked_Conversion
572 (System
.Task_Info
.Thread_Scheduling_Policy
, Interfaces
.C
.int
);
575 T
.Common
.Current_Priority
:= Prio
;
576 Param
.sched_priority
:= Interfaces
.C
.int
(Prio
);
578 if T
.Common
.Task_Info
/= null then
579 Sched_Policy
:= To_Int
(T
.Common
.Task_Info
.Policy
);
581 Sched_Policy
:= SCHED_FIFO
;
584 Result
:= pthread_setschedparam
(T
.Common
.LL
.Thread
, Sched_Policy
,
586 pragma Assert
(Result
= 0);
593 function Get_Priority
(T
: Task_ID
) return System
.Any_Priority
is
595 return T
.Common
.Current_Priority
;
602 procedure Enter_Task
(Self_ID
: Task_ID
) is
603 Result
: Interfaces
.C
.int
;
605 function To_Int
is new Unchecked_Conversion
606 (System
.Task_Info
.CPU_Number
, Interfaces
.C
.int
);
608 use System
.Task_Info
;
611 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
612 Result
:= pthread_setspecific
(ATCB_Key
, To_Address
(Self_ID
));
613 pragma Assert
(Result
= 0);
615 if Self_ID
.Common
.Task_Info
/= null
616 and then Self_ID
.Common
.Task_Info
.Scope
= PTHREAD_SCOPE_SYSTEM
617 and then Self_ID
.Common
.Task_Info
.Runon_CPU
/= ANY_CPU
619 Result
:= pthread_setrunon_np
620 (To_Int
(Self_ID
.Common
.Task_Info
.Runon_CPU
));
621 pragma Assert
(Result
= 0);
626 for J
in Known_Tasks
'Range loop
627 if Known_Tasks
(J
) = null then
628 Known_Tasks
(J
) := Self_ID
;
629 Self_ID
.Known_Tasks_Index
:= J
;
634 Unlock_All_Tasks_List
;
641 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_ID
is
643 return new Ada_Task_Control_Block
(Entry_Num
);
650 procedure Initialize_TCB
(Self_ID
: Task_ID
; Succeeded
: out Boolean) is
651 Result
: Interfaces
.C
.int
;
652 Cond_Attr
: aliased pthread_condattr_t
;
655 Initialize_Lock
(Self_ID
.Common
.LL
.L
'Access, All_Tasks_Level
);
657 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
658 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
661 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
662 pragma Assert
(Result
= 0);
668 Result
:= pthread_cond_init
(Self_ID
.Common
.LL
.CV
'Access,
670 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
675 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
676 pragma Assert
(Result
= 0);
680 Result
:= pthread_condattr_destroy
(Cond_Attr
'Access);
681 pragma Assert
(Result
= 0);
688 procedure Create_Task
690 Wrapper
: System
.Address
;
691 Stack_Size
: System
.Parameters
.Size_Type
;
692 Priority
: System
.Any_Priority
;
693 Succeeded
: out Boolean)
695 use System
.Task_Info
;
697 Attributes
: aliased pthread_attr_t
;
698 Sched_Param
: aliased struct_sched_param
;
699 Adjusted_Stack_Size
: Interfaces
.C
.size_t
;
700 Result
: Interfaces
.C
.int
;
702 function Thread_Body_Access
is new
703 Unchecked_Conversion
(System
.Address
, Thread_Body
);
705 function To_Int
is new Unchecked_Conversion
706 (System
.Task_Info
.Thread_Scheduling_Scope
, Interfaces
.C
.int
);
707 function To_Int
is new Unchecked_Conversion
708 (System
.Task_Info
.Thread_Scheduling_Inheritance
, Interfaces
.C
.int
);
709 function To_Int
is new Unchecked_Conversion
710 (System
.Task_Info
.Thread_Scheduling_Policy
, Interfaces
.C
.int
);
713 if Stack_Size
= System
.Parameters
.Unspecified_Size
then
714 Adjusted_Stack_Size
:=
715 Interfaces
.C
.size_t
(System
.Program_Info
.Default_Task_Stack
);
717 elsif Stack_Size
< Size_Type
(Minimum_Stack_Size
) then
718 Adjusted_Stack_Size
:=
719 Interfaces
.C
.size_t
(Minimum_Stack_Size
);
722 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Stack_Size
);
725 Result
:= pthread_attr_init
(Attributes
'Access);
726 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
733 Result
:= pthread_attr_setdetachstate
734 (Attributes
'Access, PTHREAD_CREATE_DETACHED
);
735 pragma Assert
(Result
= 0);
737 Result
:= pthread_attr_setstacksize
738 (Attributes
'Access, Interfaces
.C
.size_t
(Adjusted_Stack_Size
));
739 pragma Assert
(Result
= 0);
741 if T
.Common
.Task_Info
/= null then
742 Result
:= pthread_attr_setscope
743 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Scope
));
744 pragma Assert
(Result
= 0);
746 Result
:= pthread_attr_setinheritsched
747 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Inheritance
));
748 pragma Assert
(Result
= 0);
750 Result
:= pthread_attr_setschedpolicy
751 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Policy
));
752 pragma Assert
(Result
= 0);
754 Sched_Param
.sched_priority
:=
755 Interfaces
.C
.int
(T
.Common
.Task_Info
.Priority
);
757 Result
:= pthread_attr_setschedparam
758 (Attributes
'Access, Sched_Param
'Access);
759 pragma Assert
(Result
= 0);
762 -- Since the initial signal mask of a thread is inherited from the
763 -- creator, and the Environment task has all its signals masked, we
764 -- do not need to manipulate caller's signal mask at this point.
765 -- All tasks in RTS will have All_Tasks_Mask initially.
767 Result
:= pthread_create
768 (T
.Common
.LL
.Thread
'Access,
770 Thread_Body_Access
(Wrapper
),
774 and then T
.Common
.Task_Info
/= null
775 and then T
.Common
.Task_Info
.Scope
= PTHREAD_SCOPE_SYSTEM
777 -- The pthread_create call may have failed because we
778 -- asked for a system scope pthread and none were
779 -- available (probably because the program was not executed
780 -- by the superuser). Let's try for a process scope pthread
781 -- instead of raising Tasking_Error.
784 ("Request for PTHREAD_SCOPE_SYSTEM in Task_Info pragma for task");
785 System
.IO
.Put
("""");
786 System
.IO
.Put
(T
.Common
.Task_Image
.all);
787 System
.IO
.Put_Line
(""" could not be honored. ");
788 System
.IO
.Put_Line
("Scope changed to PTHREAD_SCOPE_PROCESS");
790 T
.Common
.Task_Info
.Scope
:= PTHREAD_SCOPE_PROCESS
;
791 Result
:= pthread_attr_setscope
792 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Scope
));
793 pragma Assert
(Result
= 0);
795 Result
:= pthread_create
796 (T
.Common
.LL
.Thread
'Access,
798 Thread_Body_Access
(Wrapper
),
802 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
804 Succeeded
:= Result
= 0;
806 Set_Priority
(T
, Priority
);
808 Result
:= pthread_attr_destroy
(Attributes
'Access);
809 pragma Assert
(Result
= 0);
816 procedure Finalize_TCB
(T
: Task_ID
) is
817 Result
: Interfaces
.C
.int
;
820 procedure Free
is new
821 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_ID
);
824 Result
:= pthread_mutex_destroy
(T
.Common
.LL
.L
'Access);
825 pragma Assert
(Result
= 0);
827 Result
:= pthread_cond_destroy
(T
.Common
.LL
.CV
'Access);
828 pragma Assert
(Result
= 0);
830 if T
.Known_Tasks_Index
/= -1 then
831 Known_Tasks
(T
.Known_Tasks_Index
) := null;
841 procedure Exit_Task
is
843 pthread_exit
(System
.Null_Address
);
850 procedure Abort_Task
(T
: Task_ID
) is
851 Result
: Interfaces
.C
.int
;
853 Result
:= pthread_kill
(T
.Common
.LL
.Thread
,
854 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
));
855 pragma Assert
(Result
= 0);
862 -- Dummy versions. The only currently working versions is for solaris
865 function Check_Exit
(Self_ID
: ST
.Task_ID
) return Boolean is
874 function Check_No_Locks
(Self_ID
: ST
.Task_ID
) return Boolean is
879 ----------------------
880 -- Environment_Task --
881 ----------------------
883 function Environment_Task
return Task_ID
is
885 return Environment_Task_ID
;
886 end Environment_Task
;
888 -------------------------
889 -- Lock_All_Tasks_List --
890 -------------------------
892 procedure Lock_All_Tasks_List
is
894 Write_Lock
(All_Tasks_L
'Access);
895 end Lock_All_Tasks_List
;
897 ---------------------------
898 -- Unlock_All_Tasks_List --
899 ---------------------------
901 procedure Unlock_All_Tasks_List
is
903 Unlock
(All_Tasks_L
'Access);
904 end Unlock_All_Tasks_List
;
910 function Suspend_Task
912 Thread_Self
: Thread_Id
) return Boolean is
923 Thread_Self
: Thread_Id
) return Boolean is
932 procedure Initialize
(Environment_Task
: Task_ID
) is
933 act
: aliased struct_sigaction
;
934 old_act
: aliased struct_sigaction
;
935 Tmp_Set
: aliased sigset_t
;
936 Result
: Interfaces
.C
.int
;
939 Environment_Task_ID
:= Environment_Task
;
941 -- Initialize the lock used to synchronize chain of all ATCBs.
942 Initialize_Lock
(All_Tasks_L
'Access, All_Tasks_Level
);
944 Enter_Task
(Environment_Task
);
946 -- Install the abort-signal handler
949 act
.sa_handler
:= Abort_Handler
'Address;
951 Result
:= sigemptyset
(Tmp_Set
'Access);
952 pragma Assert
(Result
= 0);
953 act
.sa_mask
:= Tmp_Set
;
957 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
),
958 act
'Unchecked_Access,
959 old_act
'Unchecked_Access);
960 pragma Assert
(Result
= 0);
965 Result
: Interfaces
.C
.int
;
967 -- Mask Environment task for all signals. The original mask of the
968 -- Environment task will be recovered by Interrupt_Server task
969 -- during the elaboration of s-interr.adb.
971 System
.Interrupt_Management
.Operations
.Set_Interrupt_Mask
972 (System
.Interrupt_Management
.Operations
.All_Tasks_Mask
'Access);
974 -- Prepare the set of signals that should unblocked in all tasks
976 Result
:= sigemptyset
(Unblocked_Signal_Mask
'Access);
977 pragma Assert
(Result
= 0);
979 for J
in Interrupt_Management
.Interrupt_ID
loop
980 if System
.Interrupt_Management
.Keep_Unmasked
(J
) then
981 Result
:= sigaddset
(Unblocked_Signal_Mask
'Access, Signal
(J
));
982 pragma Assert
(Result
= 0);
986 Result
:= pthread_key_create
(ATCB_Key
'Access, null);
987 pragma Assert
(Result
= 0);
989 -- Pick the highest resolution Clock for Clock_Realtime
990 -- ??? This code currently doesn't work (see c94007[ab] for example)
992 -- if syssgi (SGI_CYCLECNTR_SIZE) = 64 then
993 -- Real_Time_Clock_Id := CLOCK_SGI_CYCLE;
995 -- Real_Time_Clock_Id := CLOCK_REALTIME;
998 end System
.Task_Primitives
.Operations
;