1 ------------------------------------------------------------------------------
3 -- GNAT 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-2005, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 Solaris (native) 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
47 -- used for Raise_Exception
50 -- used for String_Access, Getenv
56 with System
.Interrupt_Management
;
57 -- used for Keep_Unmasked
58 -- Abort_Task_Interrupt
61 with System
.Parameters
;
65 -- used for Ada_Task_Control_Block
67 -- ATCB components and types
69 with System
.Task_Info
;
70 -- to initialize Task_Info for a C thread, in function Self
72 with System
.Soft_Links
;
73 -- used for Defer/Undefer_Abort
74 -- to initialize TSD for a C thread, in function Self
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.Stages.
81 with System
.OS_Primitives
;
82 -- used for Delay_Modes
84 with Unchecked_Deallocation
;
86 package body System
.Task_Primitives
.Operations
is
88 use System
.Tasking
.Debug
;
91 use System
.OS_Interface
;
92 use System
.Parameters
;
94 use System
.OS_Primitives
;
96 package SSL
renames System
.Soft_Links
;
102 -- The following are logically constants, but need to be initialized
105 Environment_Task_Id
: Task_Id
;
106 -- A variable to hold Task_Id for the environment task.
107 -- If we use this variable to get the Task_Id, we need the following
108 -- ATCB_Key only for non-Ada threads.
110 Unblocked_Signal_Mask
: aliased sigset_t
;
111 -- The set of signals that should unblocked in all tasks
113 ATCB_Key
: aliased thread_key_t
;
114 -- Key used to find the Ada Task_Id associated with a thread,
115 -- at least for C threads unknown to the Ada run-time system.
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 Next_Serial_Number
: Task_Serial_Number
:= 100;
123 -- We start at 100, to reserve some special values for
124 -- using in error checking.
125 -- The following are internal configuration constants needed.
127 ----------------------
128 -- Priority Support --
129 ----------------------
131 Priority_Ceiling_Emulation
: constant Boolean := True;
132 -- controls whether we emulate priority ceiling locking
134 -- To get a scheduling close to annex D requirements, we use the real-time
135 -- class provided for LWP's and map each task/thread to a specific and
136 -- unique LWP (there is 1 thread per LWP, and 1 LWP per thread).
138 -- The real time class can only be set when the process has root
139 -- priviledges, so in the other cases, we use the normal thread scheduling
140 -- and priority handling.
142 Using_Real_Time_Class
: Boolean := False;
143 -- indicates wether the real time class is being used (i.e the process
144 -- has root priviledges).
146 Prio_Param
: aliased struct_pcparms
;
147 -- Hold priority info (Real_Time) initialized during the package
150 -----------------------------------
151 -- External Configuration Values --
152 -----------------------------------
154 Time_Slice_Val
: Interfaces
.C
.long
;
155 pragma Import
(C
, Time_Slice_Val
, "__gl_time_slice_val");
157 Locking_Policy
: Character;
158 pragma Import
(C
, Locking_Policy
, "__gl_locking_policy");
160 Dispatching_Policy
: Character;
161 pragma Import
(C
, Dispatching_Policy
, "__gl_task_dispatching_policy");
163 Foreign_Task_Elaborated
: aliased Boolean := True;
164 -- Used to identified fake tasks (i.e., non-Ada Threads).
166 -----------------------
167 -- Local Subprograms --
168 -----------------------
170 function sysconf
(name
: System
.OS_Interface
.int
) return processorid_t
;
171 pragma Import
(C
, sysconf
, "sysconf");
173 SC_NPROCESSORS_CONF
: constant System
.OS_Interface
.int
:= 14;
176 (name
: System
.OS_Interface
.int
:= SC_NPROCESSORS_CONF
)
177 return processorid_t
renames sysconf
;
179 procedure Abort_Handler
181 Code
: access siginfo_t
;
182 Context
: access ucontext_t
);
183 -- Target-dependent binding of inter-thread Abort signal to
184 -- the raising of the Abort_Signal exception.
185 -- See also comments in 7staprop.adb
191 function Check_Initialize_Lock
193 Level
: Lock_Level
) return Boolean;
194 pragma Inline
(Check_Initialize_Lock
);
196 function Check_Lock
(L
: Lock_Ptr
) return Boolean;
197 pragma Inline
(Check_Lock
);
199 function Record_Lock
(L
: Lock_Ptr
) return Boolean;
200 pragma Inline
(Record_Lock
);
202 function Check_Sleep
(Reason
: Task_States
) return Boolean;
203 pragma Inline
(Check_Sleep
);
205 function Record_Wakeup
207 Reason
: Task_States
) return Boolean;
208 pragma Inline
(Record_Wakeup
);
210 function Check_Wakeup
212 Reason
: Task_States
) return Boolean;
213 pragma Inline
(Check_Wakeup
);
215 function Check_Unlock
(L
: Lock_Ptr
) return Boolean;
216 pragma Inline
(Check_Unlock
);
218 function Check_Finalize_Lock
(L
: Lock_Ptr
) return Boolean;
219 pragma Inline
(Check_Finalize_Lock
);
227 procedure Initialize
(Environment_Task
: Task_Id
);
228 pragma Inline
(Initialize
);
229 -- Initialize various data needed by this package.
231 function Is_Valid_Task
return Boolean;
232 pragma Inline
(Is_Valid_Task
);
233 -- Does executing thread have a TCB?
235 procedure Set
(Self_Id
: Task_Id
);
237 -- Set the self id for the current task.
239 function Self
return Task_Id
;
240 pragma Inline
(Self
);
241 -- Return a pointer to the Ada Task Control Block of the calling task.
245 package body Specific
is separate;
246 -- The body of this package is target specific.
248 ---------------------------------
249 -- Support for foreign threads --
250 ---------------------------------
252 function Register_Foreign_Thread
(Thread
: Thread_Id
) return Task_Id
;
253 -- Allocate and Initialize a new ATCB for the current Thread.
255 function Register_Foreign_Thread
256 (Thread
: Thread_Id
) return Task_Id
is separate;
262 Check_Count
: Integer := 0;
263 Lock_Count
: Integer := 0;
264 Unlock_Count
: Integer := 0;
270 procedure Abort_Handler
272 Code
: access siginfo_t
;
273 Context
: access ucontext_t
)
275 pragma Unreferenced
(Sig
);
276 pragma Unreferenced
(Code
);
277 pragma Unreferenced
(Context
);
279 Self_ID
: constant Task_Id
:= Self
;
280 Old_Set
: aliased sigset_t
;
282 Result
: Interfaces
.C
.int
;
283 pragma Unreferenced
(Result
);
286 -- It is not safe to raise an exception when using ZCX and the GCC
287 -- exception handling mechanism.
289 if ZCX_By_Default
and then GCC_ZCX_Support
then
293 if Self_ID
.Deferral_Level
= 0
294 and then Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
295 and then not Self_ID
.Aborting
297 Self_ID
.Aborting
:= True;
299 -- Make sure signals used for RTS internal purpose are unmasked
301 Result
:= thr_sigsetmask
(SIG_UNBLOCK
,
302 Unblocked_Signal_Mask
'Unchecked_Access, Old_Set
'Unchecked_Access);
303 pragma Assert
(Result
= 0);
305 raise Standard
'Abort_Signal;
313 -- The underlying thread system sets a guard page at the
314 -- bottom of a thread stack, so nothing is needed.
316 procedure Stack_Guard
(T
: ST
.Task_Id
; On
: Boolean) is
317 pragma Unreferenced
(T
);
318 pragma Unreferenced
(On
);
327 function Get_Thread_Id
(T
: ST
.Task_Id
) return OSI
.Thread_Id
is
329 return T
.Common
.LL
.Thread
;
336 procedure Initialize
(Environment_Task
: ST
.Task_Id
) is
337 act
: aliased struct_sigaction
;
338 old_act
: aliased struct_sigaction
;
339 Tmp_Set
: aliased sigset_t
;
340 Result
: Interfaces
.C
.int
;
342 procedure Configure_Processors
;
343 -- Processors configuration
344 -- The user can specify a processor which the program should run
345 -- on to emulate a single-processor system. This can be easily
346 -- done by setting environment variable GNAT_PROCESSOR to one of
349 -- -2 : use the default configuration (run the program on all
350 -- available processors) - this is the same as having
351 -- GNAT_PROCESSOR unset
352 -- -1 : let the RTS choose one processor and run the program on
354 -- 0 .. Last_Proc : run the program on the specified processor
356 -- Last_Proc is equal to the value of the system variable
357 -- _SC_NPROCESSORS_CONF, minus one.
359 procedure Configure_Processors
is
360 Proc_Acc
: constant GNAT
.OS_Lib
.String_Access
:=
361 GNAT
.OS_Lib
.Getenv
("GNAT_PROCESSOR");
362 Proc
: aliased processorid_t
; -- User processor #
363 Last_Proc
: processorid_t
; -- Last processor #
366 if Proc_Acc
.all'Length /= 0 then
367 -- Environment variable is defined
369 Last_Proc
:= Num_Procs
- 1;
371 if Last_Proc
/= -1 then
372 Proc
:= processorid_t
'Value (Proc_Acc
.all);
374 if Proc
<= -2 or else Proc
> Last_Proc
then
375 -- Use the default configuration
378 -- Choose a processor
382 while Proc
< Last_Proc
loop
384 Result
:= p_online
(Proc
, PR_STATUS
);
385 exit when Result
= PR_ONLINE
;
388 pragma Assert
(Result
= PR_ONLINE
);
389 Result
:= processor_bind
(P_PID
, P_MYID
, Proc
, null);
390 pragma Assert
(Result
= 0);
393 -- Use user processor
395 Result
:= processor_bind
(P_PID
, P_MYID
, Proc
, null);
396 pragma Assert
(Result
= 0);
402 when Constraint_Error
=>
404 -- Illegal environment variable GNAT_PROCESSOR - ignored
407 end Configure_Processors
;
410 (Int
: System
.Interrupt_Management
.Interrupt_ID
) return Character;
411 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
412 -- Get interrupt state. Defined in a-init.c
413 -- The input argument is the interrupt number,
414 -- and the result is one of the following:
416 Default
: constant Character := 's';
417 -- 'n' this interrupt not set by any Interrupt_State pragma
418 -- 'u' Interrupt_State pragma set state to User
419 -- 'r' Interrupt_State pragma set state to Runtime
420 -- 's' Interrupt_State pragma set state to System (use "default"
423 -- Start of processing for Initialize
426 Environment_Task_Id
:= Environment_Task
;
428 -- This is done in Enter_Task, but this is too late for the
429 -- Environment Task, since we need to call Self in Check_Locks when
430 -- the run time is compiled with assertions on.
432 Specific
.Initialize
(Environment_Task
);
434 -- Initialize the lock used to synchronize chain of all ATCBs.
436 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
438 Enter_Task
(Environment_Task
);
440 -- Install the abort-signal handler
442 if State
(System
.Interrupt_Management
.Abort_Task_Interrupt
)
445 -- Set sa_flags to SA_NODEFER so that during the handler execution
446 -- we do not change the Signal_Mask to be masked for the Abort_Signal
447 -- This is a temporary fix to the problem that the Signal_Mask is
448 -- not restored after the exception (longjmp) from the handler.
449 -- The right fix should be made in sigsetjmp so that we save
450 -- the Signal_Set and restore it after a longjmp.
451 -- In that case, this field should be changed back to 0. ???
455 act
.sa_handler
:= Abort_Handler
'Address;
456 Result
:= sigemptyset
(Tmp_Set
'Access);
457 pragma Assert
(Result
= 0);
458 act
.sa_mask
:= Tmp_Set
;
462 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
),
463 act
'Unchecked_Access,
464 old_act
'Unchecked_Access);
465 pragma Assert
(Result
= 0);
468 Configure_Processors
;
471 ---------------------
472 -- Initialize_Lock --
473 ---------------------
475 -- Note: mutexes and cond_variables needed per-task basis are
476 -- initialized in Initialize_TCB and the Storage_Error is
477 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
478 -- used in RTS is initialized before any status change of RTS.
479 -- Therefore rasing Storage_Error in the following routines
480 -- should be able to be handled safely.
482 procedure Initialize_Lock
483 (Prio
: System
.Any_Priority
;
486 Result
: Interfaces
.C
.int
;
489 pragma Assert
(Check_Initialize_Lock
(Lock_Ptr
(L
), PO_Level
));
491 if Priority_Ceiling_Emulation
then
495 Result
:= mutex_init
(L
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
496 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
498 if Result
= ENOMEM
then
499 Raise_Exception
(Storage_Error
'Identity, "Failed to allocate a lock");
503 procedure Initialize_Lock
504 (L
: access RTS_Lock
;
507 Result
: Interfaces
.C
.int
;
510 pragma Assert
(Check_Initialize_Lock
511 (To_Lock_Ptr
(RTS_Lock_Ptr
(L
)), Level
));
512 Result
:= mutex_init
(L
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
513 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
515 if Result
= ENOMEM
then
516 Raise_Exception
(Storage_Error
'Identity, "Failed to allocate a lock");
524 procedure Finalize_Lock
(L
: access Lock
) is
525 Result
: Interfaces
.C
.int
;
528 pragma Assert
(Check_Finalize_Lock
(Lock_Ptr
(L
)));
529 Result
:= mutex_destroy
(L
.L
'Access);
530 pragma Assert
(Result
= 0);
533 procedure Finalize_Lock
(L
: access RTS_Lock
) is
534 Result
: Interfaces
.C
.int
;
537 pragma Assert
(Check_Finalize_Lock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
538 Result
:= mutex_destroy
(L
.L
'Access);
539 pragma Assert
(Result
= 0);
546 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
547 Result
: Interfaces
.C
.int
;
550 pragma Assert
(Check_Lock
(Lock_Ptr
(L
)));
552 if Priority_Ceiling_Emulation
and then Locking_Policy
= 'C' then
554 Self_Id
: constant Task_Id
:= Self
;
555 Saved_Priority
: System
.Any_Priority
;
558 if Self_Id
.Common
.LL
.Active_Priority
> L
.Ceiling
then
559 Ceiling_Violation
:= True;
563 Saved_Priority
:= Self_Id
.Common
.LL
.Active_Priority
;
565 if Self_Id
.Common
.LL
.Active_Priority
< L
.Ceiling
then
566 Set_Priority
(Self_Id
, L
.Ceiling
);
569 Result
:= mutex_lock
(L
.L
'Access);
570 pragma Assert
(Result
= 0);
571 Ceiling_Violation
:= False;
573 L
.Saved_Priority
:= Saved_Priority
;
577 Result
:= mutex_lock
(L
.L
'Access);
578 pragma Assert
(Result
= 0);
579 Ceiling_Violation
:= False;
582 pragma Assert
(Record_Lock
(Lock_Ptr
(L
)));
586 (L
: access RTS_Lock
;
587 Global_Lock
: Boolean := False)
589 Result
: Interfaces
.C
.int
;
592 if not Single_Lock
or else Global_Lock
then
593 pragma Assert
(Check_Lock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
594 Result
:= mutex_lock
(L
.L
'Access);
595 pragma Assert
(Result
= 0);
596 pragma Assert
(Record_Lock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
600 procedure Write_Lock
(T
: Task_Id
) is
601 Result
: Interfaces
.C
.int
;
604 if not Single_Lock
then
605 pragma Assert
(Check_Lock
(To_Lock_Ptr
(T
.Common
.LL
.L
'Access)));
606 Result
:= mutex_lock
(T
.Common
.LL
.L
.L
'Access);
607 pragma Assert
(Result
= 0);
608 pragma Assert
(Record_Lock
(To_Lock_Ptr
(T
.Common
.LL
.L
'Access)));
616 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
618 Write_Lock
(L
, Ceiling_Violation
);
625 procedure Unlock
(L
: access Lock
) is
626 Result
: Interfaces
.C
.int
;
629 pragma Assert
(Check_Unlock
(Lock_Ptr
(L
)));
631 if Priority_Ceiling_Emulation
and then Locking_Policy
= 'C' then
633 Self_Id
: constant Task_Id
:= Self
;
636 Result
:= mutex_unlock
(L
.L
'Access);
637 pragma Assert
(Result
= 0);
639 if Self_Id
.Common
.LL
.Active_Priority
> L
.Saved_Priority
then
640 Set_Priority
(Self_Id
, L
.Saved_Priority
);
644 Result
:= mutex_unlock
(L
.L
'Access);
645 pragma Assert
(Result
= 0);
649 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
650 Result
: Interfaces
.C
.int
;
653 if not Single_Lock
or else Global_Lock
then
654 pragma Assert
(Check_Unlock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
655 Result
:= mutex_unlock
(L
.L
'Access);
656 pragma Assert
(Result
= 0);
660 procedure Unlock
(T
: Task_Id
) is
661 Result
: Interfaces
.C
.int
;
664 if not Single_Lock
then
665 pragma Assert
(Check_Unlock
(To_Lock_Ptr
(T
.Common
.LL
.L
'Access)));
666 Result
:= mutex_unlock
(T
.Common
.LL
.L
.L
'Access);
667 pragma Assert
(Result
= 0);
671 -- For the time delay implementation, we need to make sure we
672 -- achieve following criteria:
674 -- 1) We have to delay at least for the amount requested.
675 -- 2) We have to give up CPU even though the actual delay does not
676 -- result in blocking.
677 -- 3) Except for restricted run-time systems that do not support
678 -- ATC or task abort, the delay must be interrupted by the
679 -- abort_task operation.
680 -- 4) The implementation has to be efficient so that the delay overhead
681 -- is relatively cheap.
682 -- (1)-(3) are Ada requirements. Even though (2) is an Annex-D
683 -- requirement we still want to provide the effect in all cases.
684 -- The reason is that users may want to use short delays to implement
685 -- their own scheduling effect in the absence of language provided
686 -- scheduling policies.
688 ---------------------
689 -- Monotonic_Clock --
690 ---------------------
692 function Monotonic_Clock
return Duration is
693 TS
: aliased timespec
;
694 Result
: Interfaces
.C
.int
;
696 Result
:= clock_gettime
(CLOCK_REALTIME
, TS
'Unchecked_Access);
697 pragma Assert
(Result
= 0);
698 return To_Duration
(TS
);
705 function RT_Resolution
return Duration is
714 procedure Yield
(Do_Yield
: Boolean := True) is
717 System
.OS_Interface
.thr_yield
;
725 function Self
return Task_Id
renames Specific
.Self
;
731 procedure Set_Priority
733 Prio
: System
.Any_Priority
;
734 Loss_Of_Inheritance
: Boolean := False)
736 pragma Unreferenced
(Loss_Of_Inheritance
);
738 Result
: Interfaces
.C
.int
;
739 pragma Unreferenced
(Result
);
741 Param
: aliased struct_pcparms
;
746 T
.Common
.Current_Priority
:= Prio
;
748 if Priority_Ceiling_Emulation
then
749 T
.Common
.LL
.Active_Priority
:= Prio
;
752 if Using_Real_Time_Class
then
753 Param
.pc_cid
:= Prio_Param
.pc_cid
;
754 Param
.rt_pri
:= pri_t
(Prio
);
755 Param
.rt_tqsecs
:= Prio_Param
.rt_tqsecs
;
756 Param
.rt_tqnsecs
:= Prio_Param
.rt_tqnsecs
;
758 Result
:= Interfaces
.C
.int
(
759 priocntl
(PC_VERSION
, P_LWPID
, T
.Common
.LL
.LWP
, PC_SETPARMS
,
763 if T
.Common
.Task_Info
/= null
764 and then not T
.Common
.Task_Info
.Bound_To_LWP
766 -- The task is not bound to a LWP, so use thr_setprio
769 thr_setprio
(T
.Common
.LL
.Thread
, Interfaces
.C
.int
(Prio
));
773 -- The task is bound to a LWP, use priocntl
785 function Get_Priority
(T
: Task_Id
) return System
.Any_Priority
is
787 return T
.Common
.Current_Priority
;
794 procedure Enter_Task
(Self_ID
: Task_Id
) is
795 Result
: Interfaces
.C
.int
;
796 Proc
: processorid_t
; -- User processor #
797 Last_Proc
: processorid_t
; -- Last processor #
799 use System
.Task_Info
;
801 Self_ID
.Common
.LL
.Thread
:= thr_self
;
803 Self_ID
.Common
.LL
.LWP
:= lwp_self
;
805 if Self_ID
.Common
.Task_Info
/= null then
806 if Self_ID
.Common
.Task_Info
.New_LWP
807 and then Self_ID
.Common
.Task_Info
.CPU
/= CPU_UNCHANGED
809 Last_Proc
:= Num_Procs
- 1;
811 if Self_ID
.Common
.Task_Info
.CPU
= ANY_CPU
then
815 while Proc
< Last_Proc
loop
816 Result
:= p_online
(Proc
, PR_STATUS
);
817 exit when Result
= PR_ONLINE
;
821 Result
:= processor_bind
(P_LWPID
, P_MYID
, Proc
, null);
822 pragma Assert
(Result
= 0);
825 -- Use specified processor
827 if Self_ID
.Common
.Task_Info
.CPU
< 0
828 or else Self_ID
.Common
.Task_Info
.CPU
> Last_Proc
830 raise Invalid_CPU_Number
;
833 Result
:= processor_bind
834 (P_LWPID
, P_MYID
, Self_ID
.Common
.Task_Info
.CPU
, null);
835 pragma Assert
(Result
= 0);
840 Specific
.Set
(Self_ID
);
842 -- We need the above code even if we do direct fetch of Task_Id in Self
843 -- for the main task on Sun, x86 Solaris and for gcc 2.7.2.
847 for J
in Known_Tasks
'Range loop
848 if Known_Tasks
(J
) = null then
849 Known_Tasks
(J
) := Self_ID
;
850 Self_ID
.Known_Tasks_Index
:= J
;
862 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_Id
is
864 return new Ada_Task_Control_Block
(Entry_Num
);
871 function Is_Valid_Task
return Boolean renames Specific
.Is_Valid_Task
;
873 -----------------------------
874 -- Register_Foreign_Thread --
875 -----------------------------
877 function Register_Foreign_Thread
return Task_Id
is
879 if Is_Valid_Task
then
882 return Register_Foreign_Thread
(thr_self
);
884 end Register_Foreign_Thread
;
890 procedure Initialize_TCB
(Self_ID
: Task_Id
; Succeeded
: out Boolean) is
891 Result
: Interfaces
.C
.int
:= 0;
894 -- Give the task a unique serial number.
896 Self_ID
.Serial_Number
:= Next_Serial_Number
;
897 Next_Serial_Number
:= Next_Serial_Number
+ 1;
898 pragma Assert
(Next_Serial_Number
/= 0);
900 Self_ID
.Common
.LL
.Thread
:= To_thread_t
(-1);
902 if not Single_Lock
then
904 (Self_ID
.Common
.LL
.L
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
905 Self_ID
.Common
.LL
.L
.Level
:=
906 Private_Task_Serial_Number
(Self_ID
.Serial_Number
);
907 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
911 Result
:= cond_init
(Self_ID
.Common
.LL
.CV
'Access, USYNC_THREAD
, 0);
912 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
918 if not Single_Lock
then
919 Result
:= mutex_destroy
(Self_ID
.Common
.LL
.L
.L
'Access);
920 pragma Assert
(Result
= 0);
931 procedure Create_Task
933 Wrapper
: System
.Address
;
934 Stack_Size
: System
.Parameters
.Size_Type
;
935 Priority
: System
.Any_Priority
;
936 Succeeded
: out Boolean)
938 pragma Unreferenced
(Priority
);
940 Result
: Interfaces
.C
.int
;
941 Adjusted_Stack_Size
: Interfaces
.C
.size_t
;
942 Opts
: Interfaces
.C
.int
:= THR_DETACHED
;
944 Page_Size
: constant System
.Parameters
.Size_Type
:= 4096;
945 -- This constant is for reserving extra space at the
946 -- end of the stack, which can be used by the stack
947 -- checking as guard page. The idea is that we need
948 -- to have at least Stack_Size bytes available for
951 use System
.Task_Info
;
954 if Stack_Size
= System
.Parameters
.Unspecified_Size
then
955 Adjusted_Stack_Size
:=
956 Interfaces
.C
.size_t
(Default_Stack_Size
+ Page_Size
);
958 elsif Stack_Size
< Minimum_Stack_Size
then
959 Adjusted_Stack_Size
:=
960 Interfaces
.C
.size_t
(Minimum_Stack_Size
+ Page_Size
);
963 Adjusted_Stack_Size
:=
964 Interfaces
.C
.size_t
(Stack_Size
+ Page_Size
);
967 -- Since the initial signal mask of a thread is inherited from the
968 -- creator, and the Environment task has all its signals masked, we
969 -- do not need to manipulate caller's signal mask at this point.
970 -- All tasks in RTS will have All_Tasks_Mask initially.
972 if T
.Common
.Task_Info
/= null then
973 if T
.Common
.Task_Info
.New_LWP
then
974 Opts
:= Opts
+ THR_NEW_LWP
;
977 if T
.Common
.Task_Info
.Bound_To_LWP
then
978 Opts
:= Opts
+ THR_BOUND
;
982 Opts
:= THR_DETACHED
+ THR_BOUND
;
986 (System
.Null_Address
,
988 Thread_Body_Access
(Wrapper
),
991 T
.Common
.LL
.Thread
'Access);
993 Succeeded
:= Result
= 0;
996 or else Result
= ENOMEM
997 or else Result
= EAGAIN
);
1004 procedure Finalize_TCB
(T
: Task_Id
) is
1005 Result
: Interfaces
.C
.int
;
1007 Is_Self
: constant Boolean := T
= Self
;
1009 procedure Free
is new
1010 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_Id
);
1013 T
.Common
.LL
.Thread
:= To_thread_t
(0);
1015 if not Single_Lock
then
1016 Result
:= mutex_destroy
(T
.Common
.LL
.L
.L
'Access);
1017 pragma Assert
(Result
= 0);
1020 Result
:= cond_destroy
(T
.Common
.LL
.CV
'Access);
1021 pragma Assert
(Result
= 0);
1023 if T
.Known_Tasks_Index
/= -1 then
1024 Known_Tasks
(T
.Known_Tasks_Index
) := null;
1030 Specific
.Set
(null);
1038 -- This procedure must be called with abort deferred.
1039 -- It can no longer call Self or access
1040 -- the current task's ATCB, since the ATCB has been deallocated.
1042 procedure Exit_Task
is
1044 Specific
.Set
(null);
1051 procedure Abort_Task
(T
: Task_Id
) is
1052 Result
: Interfaces
.C
.int
;
1054 pragma Assert
(T
/= Self
);
1056 Result
:= thr_kill
(T
.Common
.LL
.Thread
,
1057 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
));
1058 pragma Assert
(Result
= 0);
1067 Reason
: Task_States
)
1069 Result
: Interfaces
.C
.int
;
1072 pragma Assert
(Check_Sleep
(Reason
));
1074 if Dynamic_Priority_Support
1075 and then Self_ID
.Pending_Priority_Change
1077 Self_ID
.Pending_Priority_Change
:= False;
1078 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
1079 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
1084 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
.L
'Access);
1087 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
.L
'Access);
1090 pragma Assert
(Record_Wakeup
1091 (To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access), Reason
));
1092 pragma Assert
(Result
= 0 or else Result
= EINTR
);
1095 -- Note that we are relying heaviliy here on the GNAT feature
1096 -- that Calendar.Time, System.Real_Time.Time, Duration, and
1097 -- System.Real_Time.Time_Span are all represented in the same
1098 -- way, i.e., as a 64-bit count of nanoseconds.
1100 -- This allows us to always pass the timeout value as a Duration.
1103 -- We are taking liberties here with the semantics of the delays.
1104 -- That is, we make no distinction between delays on the Calendar clock
1105 -- and delays on the Real_Time clock. That is technically incorrect, if
1106 -- the Calendar clock happens to be reset or adjusted.
1107 -- To solve this defect will require modification to the compiler
1108 -- interface, so that it can pass through more information, to tell
1109 -- us here which clock to use!
1111 -- cond_timedwait will return if any of the following happens:
1112 -- 1) some other task did cond_signal on this condition variable
1113 -- In this case, the return value is 0
1114 -- 2) the call just returned, for no good reason
1115 -- This is called a "spurious wakeup".
1116 -- In this case, the return value may also be 0.
1117 -- 3) the time delay expires
1118 -- In this case, the return value is ETIME
1119 -- 4) this task received a signal, which was handled by some
1120 -- handler procedure, and now the thread is resuming execution
1121 -- UNIX calls this an "interrupted" system call.
1122 -- In this case, the return value is EINTR
1124 -- If the cond_timedwait returns 0 or EINTR, it is still
1125 -- possible that the time has actually expired, and by chance
1126 -- a signal or cond_signal occurred at around the same time.
1128 -- We have also observed that on some OS's the value ETIME
1129 -- will be returned, but the clock will show that the full delay
1130 -- has not yet expired.
1132 -- For these reasons, we need to check the clock after return
1133 -- from cond_timedwait. If the time has expired, we will set
1136 -- This check might be omitted for systems on which the
1137 -- cond_timedwait() never returns early or wakes up spuriously.
1139 -- Annex D requires that completion of a delay cause the task
1140 -- to go to the end of its priority queue, regardless of whether
1141 -- the task actually was suspended by the delay. Since
1142 -- cond_timedwait does not do this on Solaris, we add a call
1143 -- to thr_yield at the end. We might do this at the beginning,
1144 -- instead, but then the round-robin effect would not be the
1145 -- same; the delayed task would be ahead of other tasks of the
1146 -- same priority that awoke while it was sleeping.
1148 -- For Timed_Sleep, we are expecting possible cond_signals
1149 -- to indicate other events (e.g., completion of a RV or
1150 -- completion of the abortable part of an async. select),
1151 -- we want to always return if interrupted. The caller will
1152 -- be responsible for checking the task state to see whether
1153 -- the wakeup was spurious, and to go back to sleep again
1154 -- in that case. We don't need to check for pending abort
1155 -- or priority change on the way in our out; that is the
1156 -- caller's responsibility.
1158 -- For Timed_Delay, we are not expecting any cond_signals or
1159 -- other interruptions, except for priority changes and aborts.
1160 -- Therefore, we don't want to return unless the delay has
1161 -- actually expired, or the call has been aborted. In this
1162 -- case, since we want to implement the entire delay statement
1163 -- semantics, we do need to check for pending abort and priority
1164 -- changes. We can quietly handle priority changes inside the
1165 -- procedure, since there is no entry-queue reordering involved.
1171 procedure Timed_Sleep
1174 Mode
: ST
.Delay_Modes
;
1175 Reason
: System
.Tasking
.Task_States
;
1176 Timedout
: out Boolean;
1177 Yielded
: out Boolean)
1179 Check_Time
: constant Duration := Monotonic_Clock
;
1180 Abs_Time
: Duration;
1181 Request
: aliased timespec
;
1182 Result
: Interfaces
.C
.int
;
1185 pragma Assert
(Check_Sleep
(Reason
));
1189 if Mode
= Relative
then
1190 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
1192 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
1195 if Abs_Time
> Check_Time
then
1196 Request
:= To_Timespec
(Abs_Time
);
1199 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
1200 or else (Dynamic_Priority_Support
and then
1201 Self_ID
.Pending_Priority_Change
);
1204 Result
:= cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
1205 Single_RTS_Lock
.L
'Access, Request
'Access);
1207 Result
:= cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
1208 Self_ID
.Common
.LL
.L
.L
'Access, Request
'Access);
1213 exit when Abs_Time
<= Monotonic_Clock
;
1215 if Result
= 0 or Result
= EINTR
then
1217 -- Somebody may have called Wakeup for us
1223 pragma Assert
(Result
= ETIME
);
1227 pragma Assert
(Record_Wakeup
1228 (To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access), Reason
));
1235 procedure Timed_Delay
1238 Mode
: ST
.Delay_Modes
)
1240 Check_Time
: constant Duration := Monotonic_Clock
;
1241 Abs_Time
: Duration;
1242 Request
: aliased timespec
;
1243 Result
: Interfaces
.C
.int
;
1244 Yielded
: Boolean := False;
1247 -- Only the little window between deferring abort and
1248 -- locking Self_ID is the reason we need to
1249 -- check for pending abort and priority change below!
1251 SSL
.Abort_Defer
.all;
1257 Write_Lock
(Self_ID
);
1259 if Mode
= Relative
then
1260 Abs_Time
:= Time
+ Check_Time
;
1262 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
1265 if Abs_Time
> Check_Time
then
1266 Request
:= To_Timespec
(Abs_Time
);
1267 Self_ID
.Common
.State
:= Delay_Sleep
;
1269 pragma Assert
(Check_Sleep
(Delay_Sleep
));
1272 if Dynamic_Priority_Support
and then
1273 Self_ID
.Pending_Priority_Change
then
1274 Self_ID
.Pending_Priority_Change
:= False;
1275 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
1276 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
1279 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
1282 Result
:= cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
1283 Single_RTS_Lock
.L
'Access, Request
'Access);
1285 Result
:= cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
1286 Self_ID
.Common
.LL
.L
.L
'Access, Request
'Access);
1291 exit when Abs_Time
<= Monotonic_Clock
;
1293 pragma Assert
(Result
= 0 or else
1294 Result
= ETIME
or else
1298 pragma Assert
(Record_Wakeup
1299 (To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access), Delay_Sleep
));
1301 Self_ID
.Common
.State
:= Runnable
;
1314 SSL
.Abort_Undefer
.all;
1323 Reason
: Task_States
)
1325 Result
: Interfaces
.C
.int
;
1328 pragma Assert
(Check_Wakeup
(T
, Reason
));
1329 Result
:= cond_signal
(T
.Common
.LL
.CV
'Access);
1330 pragma Assert
(Result
= 0);
1333 ---------------------------
1334 -- Check_Initialize_Lock --
1335 ---------------------------
1337 -- The following code is intended to check some of the invariant
1338 -- assertions related to lock usage, on which we depend.
1340 function Check_Initialize_Lock
1342 Level
: Lock_Level
) return Boolean
1344 Self_ID
: constant Task_Id
:= Self
;
1347 -- Check that caller is abort-deferred
1349 if Self_ID
.Deferral_Level
<= 0 then
1353 -- Check that the lock is not yet initialized
1355 if L
.Level
/= 0 then
1359 L
.Level
:= Lock_Level
'Pos (Level
) + 1;
1361 end Check_Initialize_Lock
;
1367 function Check_Lock
(L
: Lock_Ptr
) return Boolean is
1368 Self_ID
: constant Task_Id
:= Self
;
1372 -- Check that the argument is not null
1378 -- Check that L is not frozen
1384 -- Check that caller is abort-deferred
1386 if Self_ID
.Deferral_Level
<= 0 then
1390 -- Check that caller is not holding this lock already
1392 if L
.Owner
= To_Owner_ID
(To_Address
(Self_ID
)) then
1400 -- Check that TCB lock order rules are satisfied
1402 P
:= Self_ID
.Common
.LL
.Locks
;
1404 if P
.Level
>= L
.Level
1405 and then (P
.Level
> 2 or else L
.Level
> 2)
1418 function Record_Lock
(L
: Lock_Ptr
) return Boolean is
1419 Self_ID
: constant Task_Id
:= Self
;
1423 Lock_Count
:= Lock_Count
+ 1;
1425 -- There should be no owner for this lock at this point
1427 if L
.Owner
/= null then
1433 L
.Owner
:= To_Owner_ID
(To_Address
(Self_ID
));
1439 -- Check that TCB lock order rules are satisfied
1441 P
:= Self_ID
.Common
.LL
.Locks
;
1447 Self_ID
.Common
.LL
.Locking
:= null;
1448 Self_ID
.Common
.LL
.Locks
:= L
;
1456 function Check_Sleep
(Reason
: Task_States
) return Boolean is
1457 pragma Unreferenced
(Reason
);
1459 Self_ID
: constant Task_Id
:= Self
;
1463 -- Check that caller is abort-deferred
1465 if Self_ID
.Deferral_Level
<= 0 then
1473 -- Check that caller is holding own lock, on top of list
1475 if Self_ID
.Common
.LL
.Locks
/=
1476 To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access)
1481 -- Check that TCB lock order rules are satisfied
1483 if Self_ID
.Common
.LL
.Locks
.Next
/= null then
1487 Self_ID
.Common
.LL
.L
.Owner
:= null;
1488 P
:= Self_ID
.Common
.LL
.Locks
;
1489 Self_ID
.Common
.LL
.Locks
:= Self_ID
.Common
.LL
.Locks
.Next
;
1498 function Record_Wakeup
1500 Reason
: Task_States
) return Boolean
1502 pragma Unreferenced
(Reason
);
1504 Self_ID
: constant Task_Id
:= Self
;
1510 L
.Owner
:= To_Owner_ID
(To_Address
(Self_ID
));
1516 -- Check that TCB lock order rules are satisfied
1518 P
:= Self_ID
.Common
.LL
.Locks
;
1524 Self_ID
.Common
.LL
.Locking
:= null;
1525 Self_ID
.Common
.LL
.Locks
:= L
;
1533 function Check_Wakeup
1535 Reason
: Task_States
) return Boolean
1537 Self_ID
: constant Task_Id
:= Self
;
1540 -- Is caller holding T's lock?
1542 if T
.Common
.LL
.L
.Owner
/= To_Owner_ID
(To_Address
(Self_ID
)) then
1546 -- Are reasons for wakeup and sleep consistent?
1548 if T
.Common
.State
/= Reason
then
1559 function Check_Unlock
(L
: Lock_Ptr
) return Boolean is
1560 Self_ID
: constant Task_Id
:= Self
;
1564 Unlock_Count
:= Unlock_Count
+ 1;
1570 if L
.Buddy
/= null then
1575 Check_Count
:= Unlock_Count
;
1578 if Unlock_Count
- Check_Count
> 1000 then
1579 Check_Count
:= Unlock_Count
;
1582 -- Check that caller is abort-deferred
1584 if Self_ID
.Deferral_Level
<= 0 then
1588 -- Check that caller is holding this lock, on top of list
1590 if Self_ID
.Common
.LL
.Locks
/= L
then
1594 -- Record there is no owner now
1597 P
:= Self_ID
.Common
.LL
.Locks
;
1598 Self_ID
.Common
.LL
.Locks
:= Self_ID
.Common
.LL
.Locks
.Next
;
1603 --------------------
1604 -- Check_Finalize --
1605 --------------------
1607 function Check_Finalize_Lock
(L
: Lock_Ptr
) return Boolean is
1608 Self_ID
: constant Task_Id
:= Self
;
1611 -- Check that caller is abort-deferred
1613 if Self_ID
.Deferral_Level
<= 0 then
1617 -- Check that no one is holding this lock
1619 if L
.Owner
/= null then
1625 end Check_Finalize_Lock
;
1631 procedure Initialize
(S
: in out Suspension_Object
) is
1632 Result
: Interfaces
.C
.int
;
1634 -- Initialize internal state. It is always initialized to False (ARM
1640 -- Initialize internal mutex
1642 Result
:= mutex_init
(S
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
1643 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
1645 if Result
= ENOMEM
then
1646 Raise_Exception
(Storage_Error
'Identity, "Failed to allocate a lock");
1649 -- Initialize internal condition variable
1651 Result
:= cond_init
(S
.CV
'Access, USYNC_THREAD
, 0);
1652 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
1655 Result
:= mutex_destroy
(S
.L
'Access);
1656 pragma Assert
(Result
= 0);
1658 if Result
= ENOMEM
then
1659 raise Storage_Error
;
1668 procedure Finalize
(S
: in out Suspension_Object
) is
1669 Result
: Interfaces
.C
.int
;
1671 -- Destroy internal mutex
1673 Result
:= mutex_destroy
(S
.L
'Access);
1674 pragma Assert
(Result
= 0);
1676 -- Destroy internal condition variable
1678 Result
:= cond_destroy
(S
.CV
'Access);
1679 pragma Assert
(Result
= 0);
1686 function Current_State
(S
: Suspension_Object
) return Boolean is
1688 -- We do not want to use lock on this read operation. State is marked
1689 -- as Atomic so that we ensure that the value retrieved is correct.
1698 procedure Set_False
(S
: in out Suspension_Object
) is
1699 Result
: Interfaces
.C
.int
;
1701 Result
:= mutex_lock
(S
.L
'Access);
1702 pragma Assert
(Result
= 0);
1706 Result
:= mutex_unlock
(S
.L
'Access);
1707 pragma Assert
(Result
= 0);
1714 procedure Set_True
(S
: in out Suspension_Object
) is
1715 Result
: Interfaces
.C
.int
;
1717 Result
:= mutex_lock
(S
.L
'Access);
1718 pragma Assert
(Result
= 0);
1720 -- If there is already a task waiting on this suspension object then
1721 -- we resume it, leaving the state of the suspension object to False,
1722 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1723 -- the state to True.
1729 Result
:= cond_signal
(S
.CV
'Access);
1730 pragma Assert
(Result
= 0);
1735 Result
:= mutex_unlock
(S
.L
'Access);
1736 pragma Assert
(Result
= 0);
1739 ------------------------
1740 -- Suspend_Until_True --
1741 ------------------------
1743 procedure Suspend_Until_True
(S
: in out Suspension_Object
) is
1744 Result
: Interfaces
.C
.int
;
1746 Result
:= mutex_lock
(S
.L
'Access);
1747 pragma Assert
(Result
= 0);
1750 -- Program_Error must be raised upon calling Suspend_Until_True
1751 -- if another task is already waiting on that suspension object
1752 -- (ARM D.10 par. 10).
1754 Result
:= mutex_unlock
(S
.L
'Access);
1755 pragma Assert
(Result
= 0);
1757 raise Program_Error
;
1759 -- Suspend the task if the state is False. Otherwise, the task
1760 -- continues its execution, and the state of the suspension object
1761 -- is set to False (ARM D.10 par. 9).
1767 Result
:= cond_wait
(S
.CV
'Access, S
.L
'Access);
1771 Result
:= mutex_unlock
(S
.L
'Access);
1772 pragma Assert
(Result
= 0);
1773 end Suspend_Until_True
;
1779 function Check_Exit
(Self_ID
: Task_Id
) return Boolean is
1781 -- Check that caller is just holding Global_Task_Lock
1782 -- and no other locks
1784 if Self_ID
.Common
.LL
.Locks
= null then
1788 -- 2 = Global_Task_Level
1790 if Self_ID
.Common
.LL
.Locks
.Level
/= 2 then
1794 if Self_ID
.Common
.LL
.Locks
.Next
/= null then
1798 -- Check that caller is abort-deferred
1800 if Self_ID
.Deferral_Level
<= 0 then
1807 --------------------
1808 -- Check_No_Locks --
1809 --------------------
1811 function Check_No_Locks
(Self_ID
: Task_Id
) return Boolean is
1813 return Self_ID
.Common
.LL
.Locks
= null;
1816 ----------------------
1817 -- Environment_Task --
1818 ----------------------
1820 function Environment_Task
return Task_Id
is
1822 return Environment_Task_Id
;
1823 end Environment_Task
;
1829 procedure Lock_RTS
is
1831 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1838 procedure Unlock_RTS
is
1840 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1847 function Suspend_Task
1849 Thread_Self
: Thread_Id
) return Boolean
1852 if T
.Common
.LL
.Thread
/= Thread_Self
then
1853 return thr_suspend
(T
.Common
.LL
.Thread
) = 0;
1863 function Resume_Task
1865 Thread_Self
: Thread_Id
) return Boolean
1868 if T
.Common
.LL
.Thread
/= Thread_Self
then
1869 return thr_continue
(T
.Common
.LL
.Thread
) = 0;
1875 -- Package elaboration
1879 Result
: Interfaces
.C
.int
;
1881 -- Prepare the set of signals that should unblocked in all tasks
1883 Result
:= sigemptyset
(Unblocked_Signal_Mask
'Access);
1884 pragma Assert
(Result
= 0);
1886 for J
in Interrupt_Management
.Interrupt_ID
loop
1887 if System
.Interrupt_Management
.Keep_Unmasked
(J
) then
1888 Result
:= sigaddset
(Unblocked_Signal_Mask
'Access, Signal
(J
));
1889 pragma Assert
(Result
= 0);
1893 -- We need the following code to support automatic creation of fake
1894 -- ATCB's for C threads that call the Ada run-time system, even if
1895 -- we use a faster way of getting Self for real Ada tasks.
1897 Result
:= thr_keycreate
(ATCB_Key
'Access, System
.Null_Address
);
1898 pragma Assert
(Result
= 0);
1901 if Dispatching_Policy
= 'F' then
1903 Result
: Interfaces
.C
.long
;
1904 Class_Info
: aliased struct_pcinfo
;
1905 Secs
, Nsecs
: Interfaces
.C
.long
;
1908 -- If a pragma Time_Slice is specified, takes the value in account.
1910 if Time_Slice_Val
> 0 then
1911 -- Convert Time_Slice_Val (microseconds) into seconds and
1914 Secs
:= Time_Slice_Val
/ 1_000_000
;
1915 Nsecs
:= (Time_Slice_Val
rem 1_000_000
) * 1_000
;
1917 -- Otherwise, default to no time slicing (i.e run until blocked)
1924 -- Get the real time class id.
1926 Class_Info
.pc_clname
(1) := 'R';
1927 Class_Info
.pc_clname
(2) := 'T';
1928 Class_Info
.pc_clname
(3) := ASCII
.NUL
;
1930 Result
:= priocntl
(PC_VERSION
, P_LWPID
, P_MYID
, PC_GETCID
,
1931 Class_Info
'Address);
1933 -- Request the real time class
1935 Prio_Param
.pc_cid
:= Class_Info
.pc_cid
;
1936 Prio_Param
.rt_pri
:= pri_t
(Class_Info
.rt_maxpri
);
1937 Prio_Param
.rt_tqsecs
:= Secs
;
1938 Prio_Param
.rt_tqnsecs
:= Nsecs
;
1940 Result
:= priocntl
(PC_VERSION
, P_LWPID
, P_MYID
, PC_SETPARMS
,
1941 Prio_Param
'Address);
1943 Using_Real_Time_Class
:= Result
/= -1;
1946 end System
.Task_Primitives
.Operations
;