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 --
10 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
12 -- GNARL is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies, Inc. (http://www.gnat.com). --
33 ------------------------------------------------------------------------------
35 -- This is a IRIX (pthread library) version of this package.
37 -- This package contains all the GNULL primitives that interface directly
38 -- with the underlying OS.
41 -- Turn off polling, we do not want ATC polling to take place during
42 -- tasking operations. It causes infinite loops and other problems.
48 with System
.Task_Info
;
50 with System
.Tasking
.Debug
;
51 -- used for Known_Tasks
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
73 with System
.Soft_Links
;
74 -- used for Defer/Undefer_Abort
76 -- Note that we do not use System.Tasking.Initialization directly since
77 -- this is a higher level package that we shouldn't depend on. For example
78 -- when using the restricted run time, it is replaced by
79 -- System.Tasking.Restricted.Initialization
81 with System
.Program_Info
;
82 -- used for Default_Task_Stack
85 -- Pthread_Sched_Signal
88 with System
.OS_Interface
;
89 -- used for various type, constant, and operations
91 with System
.OS_Primitives
;
92 -- used for Delay_Modes
94 with Unchecked_Conversion
;
95 with Unchecked_Deallocation
;
97 package body System
.Task_Primitives
.Operations
is
100 use System
.Tasking
.Debug
;
102 use System
.OS_Interface
;
103 use System
.OS_Primitives
;
104 use System
.Parameters
;
106 package SSL
renames System
.Soft_Links
;
112 -- The followings are logically constants, but need to be initialized
115 ATCB_Key
: aliased pthread_key_t
;
116 -- Key used to find the Ada Task_ID associated with a thread
118 Single_RTS_Lock
: aliased RTS_Lock
;
119 -- This is a lock to allow only one thread of control in the RTS at
120 -- a time; it is used to execute in mutual exclusion from all other tasks.
121 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
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 Initialize_TCB and the Storage_Error is
209 -- handled. Other mutexes (such as RTS_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
;
312 Result
:= pthread_mutex_lock
(L
);
313 Ceiling_Violation
:= Result
= EINVAL
;
315 -- assumes the cause of EINVAL is a priority ceiling violation
317 pragma Assert
(Result
= 0 or else Result
= EINVAL
);
321 (L
: access RTS_Lock
; Global_Lock
: Boolean := False)
323 Result
: Interfaces
.C
.int
;
325 if not Single_Lock
or else Global_Lock
then
326 Result
:= pthread_mutex_lock
(L
);
327 pragma Assert
(Result
= 0);
331 procedure Write_Lock
(T
: Task_ID
) is
332 Result
: Interfaces
.C
.int
;
334 if not Single_Lock
then
335 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
336 pragma Assert
(Result
= 0);
344 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
346 Write_Lock
(L
, Ceiling_Violation
);
353 procedure Unlock
(L
: access Lock
) is
354 Result
: Interfaces
.C
.int
;
356 Result
:= pthread_mutex_unlock
(L
);
357 pragma Assert
(Result
= 0);
360 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
361 Result
: Interfaces
.C
.int
;
363 if not Single_Lock
or else Global_Lock
then
364 Result
:= pthread_mutex_unlock
(L
);
365 pragma Assert
(Result
= 0);
369 procedure Unlock
(T
: Task_ID
) is
370 Result
: Interfaces
.C
.int
;
372 if not Single_Lock
then
373 Result
:= pthread_mutex_unlock
(T
.Common
.LL
.L
'Access);
374 pragma Assert
(Result
= 0);
383 (Self_ID
: ST
.Task_ID
;
384 Reason
: System
.Tasking
.Task_States
)
386 Result
: Interfaces
.C
.int
;
389 Result
:= pthread_cond_wait
390 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access);
392 Result
:= pthread_cond_wait
393 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access);
396 -- EINTR is not considered a failure.
398 pragma Assert
(Result
= 0 or else Result
= EINTR
);
405 procedure Timed_Sleep
408 Mode
: ST
.Delay_Modes
;
409 Reason
: Task_States
;
410 Timedout
: out Boolean;
411 Yielded
: out Boolean)
413 Check_Time
: constant Duration := Monotonic_Clock
;
415 Request
: aliased timespec
;
416 Result
: Interfaces
.C
.int
;
422 if Mode
= Relative
then
423 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
425 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
428 if Abs_Time
> Check_Time
then
429 Request
:= To_Timespec
(Abs_Time
);
432 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
433 or else Self_ID
.Pending_Priority_Change
;
436 Result
:= pthread_cond_timedwait
437 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access,
441 Result
:= pthread_cond_timedwait
442 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access,
446 exit when Abs_Time
<= Monotonic_Clock
;
448 if Result
= 0 or else errno
= EINTR
then
460 -- This is for use in implementing delay statements, so
461 -- we assume the caller is abort-deferred but is holding
464 procedure Timed_Delay
467 Mode
: ST
.Delay_Modes
)
469 Check_Time
: constant Duration := Monotonic_Clock
;
471 Request
: aliased timespec
;
472 Result
: Interfaces
.C
.int
;
475 -- Only the little window between deferring abort and
476 -- locking Self_ID is the reason we need to
477 -- check for pending abort and priority change below! :(
485 Write_Lock
(Self_ID
);
487 if Mode
= Relative
then
488 Abs_Time
:= Time
+ Check_Time
;
490 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
493 if Abs_Time
> Check_Time
then
494 Request
:= To_Timespec
(Abs_Time
);
495 Self_ID
.Common
.State
:= Delay_Sleep
;
498 if Self_ID
.Pending_Priority_Change
then
499 Self_ID
.Pending_Priority_Change
:= False;
500 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
501 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
504 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
506 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
507 Self_ID
.Common
.LL
.L
'Access, Request
'Access);
508 exit when Abs_Time
<= Monotonic_Clock
;
510 pragma Assert
(Result
= 0
511 or else Result
= ETIMEDOUT
512 or else Result
= EINTR
);
515 Self_ID
.Common
.State
:= Runnable
;
525 SSL
.Abort_Undefer
.all;
528 ---------------------
529 -- Monotonic_Clock --
530 ---------------------
532 function Monotonic_Clock
return Duration is
533 TS
: aliased timespec
;
534 Result
: Interfaces
.C
.int
;
537 Result
:= clock_gettime
(Real_Time_Clock_Id
, TS
'Unchecked_Access);
538 pragma Assert
(Result
= 0);
539 return To_Duration
(TS
);
546 function RT_Resolution
return Duration is
548 -- The clock_getres (Real_Time_Clock_Id) function appears to return
549 -- the interrupt resolution of the realtime clock and not the actual
550 -- resolution of reading the clock. Even though this last value is
551 -- only guaranteed to be 100 Hz, at least the Origin 200 appears to
552 -- have a microsecond resolution or better.
553 -- ??? We should figure out a method to return the right value on
556 return 0.000_001
; -- Assume microsecond resolution of clock
563 procedure Wakeup
(T
: ST
.Task_ID
; Reason
: System
.Tasking
.Task_States
) is
564 Result
: Interfaces
.C
.int
;
566 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
567 pragma Assert
(Result
= 0);
574 procedure Yield
(Do_Yield
: Boolean := True) is
575 Result
: Interfaces
.C
.int
;
578 Result
:= sched_yield
;
586 procedure Set_Priority
588 Prio
: System
.Any_Priority
;
589 Loss_Of_Inheritance
: Boolean := False)
591 Result
: Interfaces
.C
.int
;
592 Param
: aliased struct_sched_param
;
593 Sched_Policy
: Interfaces
.C
.int
;
595 use type System
.Task_Info
.Task_Info_Type
;
597 function To_Int
is new Unchecked_Conversion
598 (System
.Task_Info
.Thread_Scheduling_Policy
, Interfaces
.C
.int
);
601 T
.Common
.Current_Priority
:= Prio
;
602 Param
.sched_priority
:= Interfaces
.C
.int
(Prio
);
604 if T
.Common
.Task_Info
/= null then
605 Sched_Policy
:= To_Int
(T
.Common
.Task_Info
.Policy
);
607 Sched_Policy
:= SCHED_FIFO
;
610 Result
:= pthread_setschedparam
(T
.Common
.LL
.Thread
, Sched_Policy
,
612 pragma Assert
(Result
= 0);
619 function Get_Priority
(T
: Task_ID
) return System
.Any_Priority
is
621 return T
.Common
.Current_Priority
;
628 procedure Enter_Task
(Self_ID
: Task_ID
) is
629 Result
: Interfaces
.C
.int
;
631 function To_Int
is new Unchecked_Conversion
632 (System
.Task_Info
.CPU_Number
, Interfaces
.C
.int
);
634 use System
.Task_Info
;
637 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
638 Result
:= pthread_setspecific
(ATCB_Key
, To_Address
(Self_ID
));
639 pragma Assert
(Result
= 0);
641 if Self_ID
.Common
.Task_Info
/= null
642 and then Self_ID
.Common
.Task_Info
.Scope
= PTHREAD_SCOPE_SYSTEM
643 and then Self_ID
.Common
.Task_Info
.Runon_CPU
/= ANY_CPU
645 Result
:= pthread_setrunon_np
646 (To_Int
(Self_ID
.Common
.Task_Info
.Runon_CPU
));
647 pragma Assert
(Result
= 0);
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 procedure Initialize_TCB
(Self_ID
: Task_ID
; Succeeded
: out Boolean) is
677 Result
: Interfaces
.C
.int
;
678 Cond_Attr
: aliased pthread_condattr_t
;
681 if not Single_Lock
then
682 Initialize_Lock
(Self_ID
.Common
.LL
.L
'Access, ATCB_Level
);
685 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
686 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
689 Result
:= pthread_cond_init
(Self_ID
.Common
.LL
.CV
'Access,
691 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
697 if not Single_Lock
then
698 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
699 pragma Assert
(Result
= 0);
705 Result
:= pthread_condattr_destroy
(Cond_Attr
'Access);
706 pragma Assert
(Result
= 0);
713 procedure Create_Task
715 Wrapper
: System
.Address
;
716 Stack_Size
: System
.Parameters
.Size_Type
;
717 Priority
: System
.Any_Priority
;
718 Succeeded
: out Boolean)
720 use System
.Task_Info
;
722 Attributes
: aliased pthread_attr_t
;
723 Sched_Param
: aliased struct_sched_param
;
724 Adjusted_Stack_Size
: Interfaces
.C
.size_t
;
725 Result
: Interfaces
.C
.int
;
727 function Thread_Body_Access
is new
728 Unchecked_Conversion
(System
.Address
, Thread_Body
);
730 function To_Int
is new Unchecked_Conversion
731 (System
.Task_Info
.Thread_Scheduling_Scope
, Interfaces
.C
.int
);
732 function To_Int
is new Unchecked_Conversion
733 (System
.Task_Info
.Thread_Scheduling_Inheritance
, Interfaces
.C
.int
);
734 function To_Int
is new Unchecked_Conversion
735 (System
.Task_Info
.Thread_Scheduling_Policy
, Interfaces
.C
.int
);
738 if Stack_Size
= System
.Parameters
.Unspecified_Size
then
739 Adjusted_Stack_Size
:=
740 Interfaces
.C
.size_t
(System
.Program_Info
.Default_Task_Stack
);
742 elsif Stack_Size
< Size_Type
(Minimum_Stack_Size
) then
743 Adjusted_Stack_Size
:=
744 Interfaces
.C
.size_t
(Minimum_Stack_Size
);
747 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Stack_Size
);
750 Result
:= pthread_attr_init
(Attributes
'Access);
751 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
758 Result
:= pthread_attr_setdetachstate
759 (Attributes
'Access, PTHREAD_CREATE_DETACHED
);
760 pragma Assert
(Result
= 0);
762 Result
:= pthread_attr_setstacksize
763 (Attributes
'Access, Interfaces
.C
.size_t
(Adjusted_Stack_Size
));
764 pragma Assert
(Result
= 0);
766 if T
.Common
.Task_Info
/= null then
767 Result
:= pthread_attr_setscope
768 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Scope
));
769 pragma Assert
(Result
= 0);
771 Result
:= pthread_attr_setinheritsched
772 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Inheritance
));
773 pragma Assert
(Result
= 0);
775 Result
:= pthread_attr_setschedpolicy
776 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Policy
));
777 pragma Assert
(Result
= 0);
779 Sched_Param
.sched_priority
:=
780 Interfaces
.C
.int
(T
.Common
.Task_Info
.Priority
);
782 Result
:= pthread_attr_setschedparam
783 (Attributes
'Access, Sched_Param
'Access);
784 pragma Assert
(Result
= 0);
787 -- Since the initial signal mask of a thread is inherited from the
788 -- creator, and the Environment task has all its signals masked, we
789 -- do not need to manipulate caller's signal mask at this point.
790 -- All tasks in RTS will have All_Tasks_Mask initially.
792 Result
:= pthread_create
793 (T
.Common
.LL
.Thread
'Access,
795 Thread_Body_Access
(Wrapper
),
799 and then T
.Common
.Task_Info
/= null
800 and then T
.Common
.Task_Info
.Scope
= PTHREAD_SCOPE_SYSTEM
802 -- The pthread_create call may have failed because we
803 -- asked for a system scope pthread and none were
804 -- available (probably because the program was not executed
805 -- by the superuser). Let's try for a process scope pthread
806 -- instead of raising Tasking_Error.
809 ("Request for PTHREAD_SCOPE_SYSTEM in Task_Info pragma for task");
810 System
.IO
.Put
("""");
811 System
.IO
.Put
(T
.Common
.Task_Image
.all);
812 System
.IO
.Put_Line
(""" could not be honored. ");
813 System
.IO
.Put_Line
("Scope changed to PTHREAD_SCOPE_PROCESS");
815 T
.Common
.Task_Info
.Scope
:= PTHREAD_SCOPE_PROCESS
;
816 Result
:= pthread_attr_setscope
817 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Scope
));
818 pragma Assert
(Result
= 0);
820 Result
:= pthread_create
821 (T
.Common
.LL
.Thread
'Access,
823 Thread_Body_Access
(Wrapper
),
827 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
829 Succeeded
:= Result
= 0;
831 Set_Priority
(T
, Priority
);
833 Result
:= pthread_attr_destroy
(Attributes
'Access);
834 pragma Assert
(Result
= 0);
841 procedure Finalize_TCB
(T
: Task_ID
) is
842 Result
: Interfaces
.C
.int
;
845 procedure Free
is new
846 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_ID
);
849 if not Single_Lock
then
850 Result
:= pthread_mutex_destroy
(T
.Common
.LL
.L
'Access);
851 pragma Assert
(Result
= 0);
854 Result
:= pthread_cond_destroy
(T
.Common
.LL
.CV
'Access);
855 pragma Assert
(Result
= 0);
857 if T
.Known_Tasks_Index
/= -1 then
858 Known_Tasks
(T
.Known_Tasks_Index
) := null;
868 procedure Exit_Task
is
870 pthread_exit
(System
.Null_Address
);
877 procedure Abort_Task
(T
: Task_ID
) is
878 Result
: Interfaces
.C
.int
;
880 Result
:= pthread_kill
(T
.Common
.LL
.Thread
,
881 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
));
882 pragma Assert
(Result
= 0);
889 -- Dummy versions. The only currently working versions is for solaris
892 function Check_Exit
(Self_ID
: ST
.Task_ID
) return Boolean is
901 function Check_No_Locks
(Self_ID
: ST
.Task_ID
) return Boolean is
906 ----------------------
907 -- Environment_Task --
908 ----------------------
910 function Environment_Task
return Task_ID
is
912 return Environment_Task_ID
;
913 end Environment_Task
;
919 procedure Lock_RTS
is
921 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
928 procedure Unlock_RTS
is
930 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
937 function Suspend_Task
939 Thread_Self
: Thread_Id
) return Boolean is
950 Thread_Self
: Thread_Id
) return Boolean is
959 procedure Initialize
(Environment_Task
: Task_ID
) is
960 act
: aliased struct_sigaction
;
961 old_act
: aliased struct_sigaction
;
962 Tmp_Set
: aliased sigset_t
;
963 Result
: Interfaces
.C
.int
;
966 Environment_Task_ID
:= Environment_Task
;
968 -- Initialize the lock used to synchronize chain of all ATCBs.
969 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
971 Enter_Task
(Environment_Task
);
973 -- Install the abort-signal handler
976 act
.sa_handler
:= Abort_Handler
'Address;
978 Result
:= sigemptyset
(Tmp_Set
'Access);
979 pragma Assert
(Result
= 0);
980 act
.sa_mask
:= Tmp_Set
;
984 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
),
985 act
'Unchecked_Access,
986 old_act
'Unchecked_Access);
987 pragma Assert
(Result
= 0);
992 Result
: Interfaces
.C
.int
;
994 -- Mask Environment task for all signals. The original mask of the
995 -- Environment task will be recovered by Interrupt_Server task
996 -- during the elaboration of s-interr.adb.
998 System
.Interrupt_Management
.Operations
.Set_Interrupt_Mask
999 (System
.Interrupt_Management
.Operations
.All_Tasks_Mask
'Access);
1001 -- Prepare the set of signals that should unblocked in all tasks
1003 Result
:= sigemptyset
(Unblocked_Signal_Mask
'Access);
1004 pragma Assert
(Result
= 0);
1006 for J
in Interrupt_Management
.Interrupt_ID
loop
1007 if System
.Interrupt_Management
.Keep_Unmasked
(J
) then
1008 Result
:= sigaddset
(Unblocked_Signal_Mask
'Access, Signal
(J
));
1009 pragma Assert
(Result
= 0);
1013 Result
:= pthread_key_create
(ATCB_Key
'Access, null);
1014 pragma Assert
(Result
= 0);
1016 -- Pick the highest resolution Clock for Clock_Realtime
1017 -- ??? This code currently doesn't work (see c94007[ab] for example)
1019 -- if syssgi (SGI_CYCLECNTR_SIZE) = 64 then
1020 -- Real_Time_Clock_Id := CLOCK_SGI_CYCLE;
1022 -- Real_Time_Clock_Id := CLOCK_REALTIME;
1025 end System
.Task_Primitives
.Operations
;