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-2001, 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 IRIX (pthread library) 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
.Task_Info
;
49 with System
.Tasking
.Debug
;
50 -- used for Known_Tasks
55 with System
.Interrupt_Management
;
56 -- used for Keep_Unmasked
57 -- Abort_Task_Interrupt
60 with System
.Interrupt_Management
.Operations
;
61 -- used for Set_Interrupt_Mask
63 pragma Elaborate_All
(System
.Interrupt_Management
.Operations
);
65 with System
.Parameters
;
69 -- used for Ada_Task_Control_Block
72 with System
.Soft_Links
;
73 -- used for Defer/Undefer_Abort
75 -- Note that we do not use System.Tasking.Initialization directly since
76 -- this is a higher level package that we shouldn't depend on. For example
77 -- when using the restricted run time, it is replaced by
78 -- System.Tasking.Restricted.Initialization
80 with System
.Program_Info
;
81 -- used for Default_Task_Stack
84 -- Pthread_Sched_Signal
87 with System
.OS_Interface
;
88 -- used for various type, constant, and operations
90 with System
.OS_Primitives
;
91 -- used for Delay_Modes
93 with Unchecked_Conversion
;
94 with Unchecked_Deallocation
;
96 package body System
.Task_Primitives
.Operations
is
99 use System
.Tasking
.Debug
;
101 use System
.OS_Interface
;
102 use System
.OS_Primitives
;
103 use System
.Parameters
;
105 package SSL
renames System
.Soft_Links
;
111 -- The followings are logically constants, but need to be initialized
114 ATCB_Key
: aliased pthread_key_t
;
115 -- Key used to find the Ada Task_ID associated with a thread
117 Single_RTS_Lock
: aliased RTS_Lock
;
118 -- This is a lock to allow only one thread of control in the RTS at
119 -- a time; it is used to execute in mutual exclusion from all other tasks.
120 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
122 Environment_Task_ID
: Task_ID
;
123 -- A variable to hold Task_ID for the environment task.
125 Locking_Policy
: Character;
126 pragma Import
(C
, Locking_Policy
, "__gl_locking_policy");
128 Real_Time_Clock_Id
: constant clockid_t
:= CLOCK_REALTIME
;
130 Unblocked_Signal_Mask
: aliased sigset_t
;
132 -----------------------
133 -- Local Subprograms --
134 -----------------------
136 function To_Task_ID
is new Unchecked_Conversion
(System
.Address
, Task_ID
);
138 function To_Address
is new Unchecked_Conversion
(Task_ID
, System
.Address
);
140 procedure Abort_Handler
(Sig
: Signal
);
146 procedure Abort_Handler
(Sig
: Signal
) is
148 Result
: Interfaces
.C
.int
;
149 Old_Set
: aliased sigset_t
;
152 if T
.Deferral_Level
= 0
153 and then T
.Pending_ATC_Level
< T
.ATC_Nesting_Level
155 -- Make sure signals used for RTS internal purpose are unmasked
157 Result
:= pthread_sigmask
159 Unblocked_Signal_Mask
'Unchecked_Access,
160 Old_Set
'Unchecked_Access);
161 pragma Assert
(Result
= 0);
163 raise Standard
'Abort_Signal;
171 -- The underlying thread system sets a guard page at the
172 -- bottom of a thread stack, so nothing is needed.
174 procedure Stack_Guard
(T
: ST
.Task_ID
; On
: Boolean) is
183 function Get_Thread_Id
(T
: ST
.Task_ID
) return OSI
.Thread_Id
is
185 return T
.Common
.LL
.Thread
;
192 function Self
return Task_ID
is
193 Result
: System
.Address
;
196 Result
:= pthread_getspecific
(ATCB_Key
);
197 pragma Assert
(Result
/= System
.Null_Address
);
199 return To_Task_ID
(Result
);
202 ---------------------
203 -- Initialize_Lock --
204 ---------------------
206 -- Note: mutexes and cond_variables needed per-task basis are
207 -- initialized in Initialize_TCB and the Storage_Error is
208 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
209 -- used in RTS is initialized before any status change of RTS.
210 -- Therefore rasing Storage_Error in the following routines
211 -- should be able to be handled safely.
213 procedure Initialize_Lock
214 (Prio
: System
.Any_Priority
;
217 Attributes
: aliased pthread_mutexattr_t
;
218 Result
: Interfaces
.C
.int
;
221 Result
:= pthread_mutexattr_init
(Attributes
'Access);
222 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
224 if Result
= ENOMEM
then
228 if Locking_Policy
= 'C' then
229 Result
:= pthread_mutexattr_setprotocol
230 (Attributes
'Access, PTHREAD_PRIO_PROTECT
);
231 pragma Assert
(Result
= 0);
233 Result
:= pthread_mutexattr_setprioceiling
234 (Attributes
'Access, Interfaces
.C
.int
(Prio
));
235 pragma Assert
(Result
= 0);
238 Result
:= pthread_mutex_init
(L
, Attributes
'Access);
239 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
241 if Result
= ENOMEM
then
242 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
246 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
247 pragma Assert
(Result
= 0);
250 procedure Initialize_Lock
(L
: access RTS_Lock
; Level
: Lock_Level
) is
251 Attributes
: aliased pthread_mutexattr_t
;
252 Result
: Interfaces
.C
.int
;
255 Result
:= pthread_mutexattr_init
(Attributes
'Access);
256 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
258 if Result
= ENOMEM
then
262 if Locking_Policy
= 'C' then
263 Result
:= pthread_mutexattr_setprotocol
264 (Attributes
'Access, PTHREAD_PRIO_PROTECT
);
265 pragma Assert
(Result
= 0);
267 Result
:= pthread_mutexattr_setprioceiling
268 (Attributes
'Access, Interfaces
.C
.int
(System
.Any_Priority
'Last));
269 pragma Assert
(Result
= 0);
272 Result
:= pthread_mutex_init
(L
, Attributes
'Access);
274 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
276 if Result
= ENOMEM
then
277 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
281 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
288 procedure Finalize_Lock
(L
: access Lock
) is
289 Result
: Interfaces
.C
.int
;
292 Result
:= pthread_mutex_destroy
(L
);
293 pragma Assert
(Result
= 0);
296 procedure Finalize_Lock
(L
: access RTS_Lock
) is
297 Result
: Interfaces
.C
.int
;
300 Result
:= pthread_mutex_destroy
(L
);
301 pragma Assert
(Result
= 0);
308 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
309 Result
: Interfaces
.C
.int
;
311 Result
:= pthread_mutex_lock
(L
);
312 Ceiling_Violation
:= Result
= EINVAL
;
314 -- assumes the cause of EINVAL is a priority ceiling violation
316 pragma Assert
(Result
= 0 or else Result
= EINVAL
);
320 (L
: access RTS_Lock
; Global_Lock
: Boolean := False)
322 Result
: Interfaces
.C
.int
;
324 if not Single_Lock
or else Global_Lock
then
325 Result
:= pthread_mutex_lock
(L
);
326 pragma Assert
(Result
= 0);
330 procedure Write_Lock
(T
: Task_ID
) is
331 Result
: Interfaces
.C
.int
;
333 if not Single_Lock
then
334 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
335 pragma Assert
(Result
= 0);
343 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
345 Write_Lock
(L
, Ceiling_Violation
);
352 procedure Unlock
(L
: access Lock
) is
353 Result
: Interfaces
.C
.int
;
355 Result
:= pthread_mutex_unlock
(L
);
356 pragma Assert
(Result
= 0);
359 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
360 Result
: Interfaces
.C
.int
;
362 if not Single_Lock
or else Global_Lock
then
363 Result
:= pthread_mutex_unlock
(L
);
364 pragma Assert
(Result
= 0);
368 procedure Unlock
(T
: Task_ID
) is
369 Result
: Interfaces
.C
.int
;
371 if not Single_Lock
then
372 Result
:= pthread_mutex_unlock
(T
.Common
.LL
.L
'Access);
373 pragma Assert
(Result
= 0);
382 (Self_ID
: ST
.Task_ID
;
383 Reason
: System
.Tasking
.Task_States
)
385 Result
: Interfaces
.C
.int
;
388 Result
:= pthread_cond_wait
389 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access);
391 Result
:= pthread_cond_wait
392 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access);
395 -- EINTR is not considered a failure.
397 pragma Assert
(Result
= 0 or else Result
= EINTR
);
404 procedure Timed_Sleep
407 Mode
: ST
.Delay_Modes
;
408 Reason
: Task_States
;
409 Timedout
: out Boolean;
410 Yielded
: out Boolean)
412 Check_Time
: constant Duration := Monotonic_Clock
;
414 Request
: aliased timespec
;
415 Result
: Interfaces
.C
.int
;
421 if Mode
= Relative
then
422 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
424 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
427 if Abs_Time
> Check_Time
then
428 Request
:= To_Timespec
(Abs_Time
);
431 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
432 or else Self_ID
.Pending_Priority_Change
;
435 Result
:= pthread_cond_timedwait
436 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access,
440 Result
:= pthread_cond_timedwait
441 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access,
445 exit when Abs_Time
<= Monotonic_Clock
;
447 if Result
= 0 or else errno
= EINTR
then
459 -- This is for use in implementing delay statements, so
460 -- we assume the caller is abort-deferred but is holding
463 procedure Timed_Delay
466 Mode
: ST
.Delay_Modes
)
468 Check_Time
: constant Duration := Monotonic_Clock
;
470 Request
: aliased timespec
;
471 Result
: Interfaces
.C
.int
;
474 -- Only the little window between deferring abort and
475 -- locking Self_ID is the reason we need to
476 -- check for pending abort and priority change below! :(
484 Write_Lock
(Self_ID
);
486 if Mode
= Relative
then
487 Abs_Time
:= Time
+ Check_Time
;
489 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
492 if Abs_Time
> Check_Time
then
493 Request
:= To_Timespec
(Abs_Time
);
494 Self_ID
.Common
.State
:= Delay_Sleep
;
497 if Self_ID
.Pending_Priority_Change
then
498 Self_ID
.Pending_Priority_Change
:= False;
499 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
500 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
503 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
505 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
506 Self_ID
.Common
.LL
.L
'Access, Request
'Access);
507 exit when Abs_Time
<= Monotonic_Clock
;
509 pragma Assert
(Result
= 0
510 or else Result
= ETIMEDOUT
511 or else Result
= EINTR
);
514 Self_ID
.Common
.State
:= Runnable
;
524 SSL
.Abort_Undefer
.all;
527 ---------------------
528 -- Monotonic_Clock --
529 ---------------------
531 function Monotonic_Clock
return Duration is
532 TS
: aliased timespec
;
533 Result
: Interfaces
.C
.int
;
536 Result
:= clock_gettime
(Real_Time_Clock_Id
, TS
'Unchecked_Access);
537 pragma Assert
(Result
= 0);
538 return To_Duration
(TS
);
545 function RT_Resolution
return Duration is
547 -- The clock_getres (Real_Time_Clock_Id) function appears to return
548 -- the interrupt resolution of the realtime clock and not the actual
549 -- resolution of reading the clock. Even though this last value is
550 -- only guaranteed to be 100 Hz, at least the Origin 200 appears to
551 -- have a microsecond resolution or better.
552 -- ??? We should figure out a method to return the right value on
555 return 0.000_001
; -- Assume microsecond resolution of clock
562 procedure Wakeup
(T
: ST
.Task_ID
; Reason
: System
.Tasking
.Task_States
) is
563 Result
: Interfaces
.C
.int
;
565 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
566 pragma Assert
(Result
= 0);
573 procedure Yield
(Do_Yield
: Boolean := True) is
574 Result
: Interfaces
.C
.int
;
577 Result
:= sched_yield
;
585 procedure Set_Priority
587 Prio
: System
.Any_Priority
;
588 Loss_Of_Inheritance
: Boolean := False)
590 Result
: Interfaces
.C
.int
;
591 Param
: aliased struct_sched_param
;
592 Sched_Policy
: Interfaces
.C
.int
;
594 use type System
.Task_Info
.Task_Info_Type
;
596 function To_Int
is new Unchecked_Conversion
597 (System
.Task_Info
.Thread_Scheduling_Policy
, Interfaces
.C
.int
);
600 T
.Common
.Current_Priority
:= Prio
;
601 Param
.sched_priority
:= Interfaces
.C
.int
(Prio
);
603 if T
.Common
.Task_Info
/= null then
604 Sched_Policy
:= To_Int
(T
.Common
.Task_Info
.Policy
);
606 Sched_Policy
:= SCHED_FIFO
;
609 Result
:= pthread_setschedparam
(T
.Common
.LL
.Thread
, Sched_Policy
,
611 pragma Assert
(Result
= 0);
618 function Get_Priority
(T
: Task_ID
) return System
.Any_Priority
is
620 return T
.Common
.Current_Priority
;
627 procedure Enter_Task
(Self_ID
: Task_ID
) is
628 Result
: Interfaces
.C
.int
;
630 function To_Int
is new Unchecked_Conversion
631 (System
.Task_Info
.CPU_Number
, Interfaces
.C
.int
);
633 use System
.Task_Info
;
636 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
637 Result
:= pthread_setspecific
(ATCB_Key
, To_Address
(Self_ID
));
638 pragma Assert
(Result
= 0);
640 if Self_ID
.Common
.Task_Info
/= null
641 and then Self_ID
.Common
.Task_Info
.Scope
= PTHREAD_SCOPE_SYSTEM
642 and then Self_ID
.Common
.Task_Info
.Runon_CPU
/= ANY_CPU
644 Result
:= pthread_setrunon_np
645 (To_Int
(Self_ID
.Common
.Task_Info
.Runon_CPU
));
646 pragma Assert
(Result
= 0);
651 for J
in Known_Tasks
'Range loop
652 if Known_Tasks
(J
) = null then
653 Known_Tasks
(J
) := Self_ID
;
654 Self_ID
.Known_Tasks_Index
:= J
;
666 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_ID
is
668 return new Ada_Task_Control_Block
(Entry_Num
);
675 procedure Initialize_TCB
(Self_ID
: Task_ID
; Succeeded
: out Boolean) is
676 Result
: Interfaces
.C
.int
;
677 Cond_Attr
: aliased pthread_condattr_t
;
680 if not Single_Lock
then
681 Initialize_Lock
(Self_ID
.Common
.LL
.L
'Access, ATCB_Level
);
684 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
685 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
688 Result
:= pthread_cond_init
(Self_ID
.Common
.LL
.CV
'Access,
690 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
696 if not Single_Lock
then
697 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
698 pragma Assert
(Result
= 0);
704 Result
:= pthread_condattr_destroy
(Cond_Attr
'Access);
705 pragma Assert
(Result
= 0);
712 procedure Create_Task
714 Wrapper
: System
.Address
;
715 Stack_Size
: System
.Parameters
.Size_Type
;
716 Priority
: System
.Any_Priority
;
717 Succeeded
: out Boolean)
719 use System
.Task_Info
;
721 Attributes
: aliased pthread_attr_t
;
722 Sched_Param
: aliased struct_sched_param
;
723 Adjusted_Stack_Size
: Interfaces
.C
.size_t
;
724 Result
: Interfaces
.C
.int
;
726 function Thread_Body_Access
is new
727 Unchecked_Conversion
(System
.Address
, Thread_Body
);
729 function To_Int
is new Unchecked_Conversion
730 (System
.Task_Info
.Thread_Scheduling_Scope
, Interfaces
.C
.int
);
731 function To_Int
is new Unchecked_Conversion
732 (System
.Task_Info
.Thread_Scheduling_Inheritance
, Interfaces
.C
.int
);
733 function To_Int
is new Unchecked_Conversion
734 (System
.Task_Info
.Thread_Scheduling_Policy
, Interfaces
.C
.int
);
737 if Stack_Size
= System
.Parameters
.Unspecified_Size
then
738 Adjusted_Stack_Size
:=
739 Interfaces
.C
.size_t
(System
.Program_Info
.Default_Task_Stack
);
741 elsif Stack_Size
< Size_Type
(Minimum_Stack_Size
) then
742 Adjusted_Stack_Size
:=
743 Interfaces
.C
.size_t
(Minimum_Stack_Size
);
746 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Stack_Size
);
749 Result
:= pthread_attr_init
(Attributes
'Access);
750 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
757 Result
:= pthread_attr_setdetachstate
758 (Attributes
'Access, PTHREAD_CREATE_DETACHED
);
759 pragma Assert
(Result
= 0);
761 Result
:= pthread_attr_setstacksize
762 (Attributes
'Access, Interfaces
.C
.size_t
(Adjusted_Stack_Size
));
763 pragma Assert
(Result
= 0);
765 if T
.Common
.Task_Info
/= null then
766 Result
:= pthread_attr_setscope
767 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Scope
));
768 pragma Assert
(Result
= 0);
770 Result
:= pthread_attr_setinheritsched
771 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Inheritance
));
772 pragma Assert
(Result
= 0);
774 Result
:= pthread_attr_setschedpolicy
775 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Policy
));
776 pragma Assert
(Result
= 0);
778 Sched_Param
.sched_priority
:=
779 Interfaces
.C
.int
(T
.Common
.Task_Info
.Priority
);
781 Result
:= pthread_attr_setschedparam
782 (Attributes
'Access, Sched_Param
'Access);
783 pragma Assert
(Result
= 0);
786 -- Since the initial signal mask of a thread is inherited from the
787 -- creator, and the Environment task has all its signals masked, we
788 -- do not need to manipulate caller's signal mask at this point.
789 -- All tasks in RTS will have All_Tasks_Mask initially.
791 Result
:= pthread_create
792 (T
.Common
.LL
.Thread
'Access,
794 Thread_Body_Access
(Wrapper
),
798 and then T
.Common
.Task_Info
/= null
799 and then T
.Common
.Task_Info
.Scope
= PTHREAD_SCOPE_SYSTEM
801 -- The pthread_create call may have failed because we
802 -- asked for a system scope pthread and none were
803 -- available (probably because the program was not executed
804 -- by the superuser). Let's try for a process scope pthread
805 -- instead of raising Tasking_Error.
808 ("Request for PTHREAD_SCOPE_SYSTEM in Task_Info pragma for task");
809 System
.IO
.Put
("""");
810 System
.IO
.Put
(T
.Common
.Task_Image
.all);
811 System
.IO
.Put_Line
(""" could not be honored. ");
812 System
.IO
.Put_Line
("Scope changed to PTHREAD_SCOPE_PROCESS");
814 T
.Common
.Task_Info
.Scope
:= PTHREAD_SCOPE_PROCESS
;
815 Result
:= pthread_attr_setscope
816 (Attributes
'Access, To_Int
(T
.Common
.Task_Info
.Scope
));
817 pragma Assert
(Result
= 0);
819 Result
:= pthread_create
820 (T
.Common
.LL
.Thread
'Access,
822 Thread_Body_Access
(Wrapper
),
826 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
828 Succeeded
:= Result
= 0;
830 Set_Priority
(T
, Priority
);
832 Result
:= pthread_attr_destroy
(Attributes
'Access);
833 pragma Assert
(Result
= 0);
840 procedure Finalize_TCB
(T
: Task_ID
) is
841 Result
: Interfaces
.C
.int
;
844 procedure Free
is new
845 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_ID
);
848 if not Single_Lock
then
849 Result
:= pthread_mutex_destroy
(T
.Common
.LL
.L
'Access);
850 pragma Assert
(Result
= 0);
853 Result
:= pthread_cond_destroy
(T
.Common
.LL
.CV
'Access);
854 pragma Assert
(Result
= 0);
856 if T
.Known_Tasks_Index
/= -1 then
857 Known_Tasks
(T
.Known_Tasks_Index
) := null;
867 procedure Exit_Task
is
869 pthread_exit
(System
.Null_Address
);
876 procedure Abort_Task
(T
: Task_ID
) is
877 Result
: Interfaces
.C
.int
;
879 Result
:= pthread_kill
(T
.Common
.LL
.Thread
,
880 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
));
881 pragma Assert
(Result
= 0);
888 -- Dummy versions. The only currently working versions is for solaris
891 function Check_Exit
(Self_ID
: ST
.Task_ID
) return Boolean is
900 function Check_No_Locks
(Self_ID
: ST
.Task_ID
) return Boolean is
905 ----------------------
906 -- Environment_Task --
907 ----------------------
909 function Environment_Task
return Task_ID
is
911 return Environment_Task_ID
;
912 end Environment_Task
;
918 procedure Lock_RTS
is
920 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
927 procedure Unlock_RTS
is
929 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
936 function Suspend_Task
938 Thread_Self
: Thread_Id
) return Boolean is
949 Thread_Self
: Thread_Id
) return Boolean is
958 procedure Initialize
(Environment_Task
: Task_ID
) is
959 act
: aliased struct_sigaction
;
960 old_act
: aliased struct_sigaction
;
961 Tmp_Set
: aliased sigset_t
;
962 Result
: Interfaces
.C
.int
;
965 Environment_Task_ID
:= Environment_Task
;
967 -- Initialize the lock used to synchronize chain of all ATCBs.
968 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
970 Enter_Task
(Environment_Task
);
972 -- Install the abort-signal handler
975 act
.sa_handler
:= Abort_Handler
'Address;
977 Result
:= sigemptyset
(Tmp_Set
'Access);
978 pragma Assert
(Result
= 0);
979 act
.sa_mask
:= Tmp_Set
;
983 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
),
984 act
'Unchecked_Access,
985 old_act
'Unchecked_Access);
986 pragma Assert
(Result
= 0);
991 Result
: Interfaces
.C
.int
;
993 -- Mask Environment task for all signals. The original mask of the
994 -- Environment task will be recovered by Interrupt_Server task
995 -- during the elaboration of s-interr.adb.
997 System
.Interrupt_Management
.Operations
.Set_Interrupt_Mask
998 (System
.Interrupt_Management
.Operations
.All_Tasks_Mask
'Access);
1000 -- Prepare the set of signals that should unblocked in all tasks
1002 Result
:= sigemptyset
(Unblocked_Signal_Mask
'Access);
1003 pragma Assert
(Result
= 0);
1005 for J
in Interrupt_Management
.Interrupt_ID
loop
1006 if System
.Interrupt_Management
.Keep_Unmasked
(J
) then
1007 Result
:= sigaddset
(Unblocked_Signal_Mask
'Access, Signal
(J
));
1008 pragma Assert
(Result
= 0);
1012 Result
:= pthread_key_create
(ATCB_Key
'Access, null);
1013 pragma Assert
(Result
= 0);
1015 -- Pick the highest resolution Clock for Clock_Realtime
1016 -- ??? This code currently doesn't work (see c94007[ab] for example)
1018 -- if syssgi (SGI_CYCLECNTR_SIZE) = 64 then
1019 -- Real_Time_Clock_Id := CLOCK_SGI_CYCLE;
1021 -- Real_Time_Clock_Id := CLOCK_REALTIME;
1024 end System
.Task_Primitives
.Operations
;