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
46 with System
.Interrupt_Management
;
47 -- used for Keep_Unmasked
48 -- Abort_Task_Interrupt
51 with System
.OS_Primitives
;
52 -- used for Delay_Modes
54 pragma Warnings
(Off
);
56 -- used for String_Access, Getenv
64 with System
.Parameters
;
67 with System
.Task_Info
;
68 -- to initialize Task_Info for a C thread, in function Self
70 with Unchecked_Deallocation
;
72 package body System
.Task_Primitives
.Operations
is
74 use System
.Tasking
.Debug
;
77 use System
.OS_Interface
;
78 use System
.Parameters
;
79 use System
.OS_Primitives
;
85 -- The following are logically constants, but need to be initialized
88 Environment_Task_Id
: Task_Id
;
89 -- A variable to hold Task_Id for the environment task.
90 -- If we use this variable to get the Task_Id, we need the following
91 -- ATCB_Key only for non-Ada threads.
93 Unblocked_Signal_Mask
: aliased sigset_t
;
94 -- The set of signals that should unblocked in all tasks
96 ATCB_Key
: aliased thread_key_t
;
97 -- Key used to find the Ada Task_Id associated with a thread,
98 -- at least for C threads unknown to the Ada run-time system.
100 Single_RTS_Lock
: aliased RTS_Lock
;
101 -- This is a lock to allow only one thread of control in the RTS at
102 -- a time; it is used to execute in mutual exclusion from all other tasks.
103 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
105 Next_Serial_Number
: Task_Serial_Number
:= 100;
106 -- We start at 100, to reserve some special values for
107 -- using in error checking.
108 -- The following are internal configuration constants needed.
110 ----------------------
111 -- Priority Support --
112 ----------------------
114 Priority_Ceiling_Emulation
: constant Boolean := True;
115 -- controls whether we emulate priority ceiling locking
117 -- To get a scheduling close to annex D requirements, we use the real-time
118 -- class provided for LWP's and map each task/thread to a specific and
119 -- unique LWP (there is 1 thread per LWP, and 1 LWP per thread).
121 -- The real time class can only be set when the process has root
122 -- priviledges, so in the other cases, we use the normal thread scheduling
123 -- and priority handling.
125 Using_Real_Time_Class
: Boolean := False;
126 -- indicates wether the real time class is being used (i.e the process
127 -- has root priviledges).
129 Prio_Param
: aliased struct_pcparms
;
130 -- Hold priority info (Real_Time) initialized during the package
133 -----------------------------------
134 -- External Configuration Values --
135 -----------------------------------
137 Time_Slice_Val
: Interfaces
.C
.long
;
138 pragma Import
(C
, Time_Slice_Val
, "__gl_time_slice_val");
140 Locking_Policy
: Character;
141 pragma Import
(C
, Locking_Policy
, "__gl_locking_policy");
143 Dispatching_Policy
: Character;
144 pragma Import
(C
, Dispatching_Policy
, "__gl_task_dispatching_policy");
146 Foreign_Task_Elaborated
: aliased Boolean := True;
147 -- Used to identified fake tasks (i.e., non-Ada Threads).
149 -----------------------
150 -- Local Subprograms --
151 -----------------------
153 function sysconf
(name
: System
.OS_Interface
.int
) return processorid_t
;
154 pragma Import
(C
, sysconf
, "sysconf");
156 SC_NPROCESSORS_CONF
: constant System
.OS_Interface
.int
:= 14;
159 (name
: System
.OS_Interface
.int
:= SC_NPROCESSORS_CONF
)
160 return processorid_t
renames sysconf
;
162 procedure Abort_Handler
164 Code
: access siginfo_t
;
165 Context
: access ucontext_t
);
166 -- Target-dependent binding of inter-thread Abort signal to
167 -- the raising of the Abort_Signal exception.
168 -- See also comments in 7staprop.adb
174 function Check_Initialize_Lock
176 Level
: Lock_Level
) return Boolean;
177 pragma Inline
(Check_Initialize_Lock
);
179 function Check_Lock
(L
: Lock_Ptr
) return Boolean;
180 pragma Inline
(Check_Lock
);
182 function Record_Lock
(L
: Lock_Ptr
) return Boolean;
183 pragma Inline
(Record_Lock
);
185 function Check_Sleep
(Reason
: Task_States
) return Boolean;
186 pragma Inline
(Check_Sleep
);
188 function Record_Wakeup
190 Reason
: Task_States
) return Boolean;
191 pragma Inline
(Record_Wakeup
);
193 function Check_Wakeup
195 Reason
: Task_States
) return Boolean;
196 pragma Inline
(Check_Wakeup
);
198 function Check_Unlock
(L
: Lock_Ptr
) return Boolean;
199 pragma Inline
(Check_Unlock
);
201 function Check_Finalize_Lock
(L
: Lock_Ptr
) return Boolean;
202 pragma Inline
(Check_Finalize_Lock
);
210 procedure Initialize
(Environment_Task
: Task_Id
);
211 pragma Inline
(Initialize
);
212 -- Initialize various data needed by this package.
214 function Is_Valid_Task
return Boolean;
215 pragma Inline
(Is_Valid_Task
);
216 -- Does executing thread have a TCB?
218 procedure Set
(Self_Id
: Task_Id
);
220 -- Set the self id for the current task.
222 function Self
return Task_Id
;
223 pragma Inline
(Self
);
224 -- Return a pointer to the Ada Task Control Block of the calling task.
228 package body Specific
is separate;
229 -- The body of this package is target specific.
231 ---------------------------------
232 -- Support for foreign threads --
233 ---------------------------------
235 function Register_Foreign_Thread
(Thread
: Thread_Id
) return Task_Id
;
236 -- Allocate and Initialize a new ATCB for the current Thread.
238 function Register_Foreign_Thread
239 (Thread
: Thread_Id
) return Task_Id
is separate;
245 Check_Count
: Integer := 0;
246 Lock_Count
: Integer := 0;
247 Unlock_Count
: Integer := 0;
253 procedure Abort_Handler
255 Code
: access siginfo_t
;
256 Context
: access ucontext_t
)
258 pragma Unreferenced
(Sig
);
259 pragma Unreferenced
(Code
);
260 pragma Unreferenced
(Context
);
262 Self_ID
: constant Task_Id
:= Self
;
263 Old_Set
: aliased sigset_t
;
265 Result
: Interfaces
.C
.int
;
268 -- It is not safe to raise an exception when using ZCX and the GCC
269 -- exception handling mechanism.
271 if ZCX_By_Default
and then GCC_ZCX_Support
then
275 if Self_ID
.Deferral_Level
= 0
276 and then Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
277 and then not Self_ID
.Aborting
279 Self_ID
.Aborting
:= True;
281 -- Make sure signals used for RTS internal purpose are unmasked
283 Result
:= thr_sigsetmask
(SIG_UNBLOCK
,
284 Unblocked_Signal_Mask
'Unchecked_Access, Old_Set
'Unchecked_Access);
285 pragma Assert
(Result
= 0);
287 raise Standard
'Abort_Signal;
295 -- The underlying thread system sets a guard page at the
296 -- bottom of a thread stack, so nothing is needed.
298 procedure Stack_Guard
(T
: ST
.Task_Id
; On
: Boolean) is
299 pragma Unreferenced
(T
);
300 pragma Unreferenced
(On
);
309 function Get_Thread_Id
(T
: ST
.Task_Id
) return OSI
.Thread_Id
is
311 return T
.Common
.LL
.Thread
;
318 procedure Initialize
(Environment_Task
: ST
.Task_Id
) is
319 act
: aliased struct_sigaction
;
320 old_act
: aliased struct_sigaction
;
321 Tmp_Set
: aliased sigset_t
;
322 Result
: Interfaces
.C
.int
;
324 procedure Configure_Processors
;
325 -- Processors configuration
326 -- The user can specify a processor which the program should run
327 -- on to emulate a single-processor system. This can be easily
328 -- done by setting environment variable GNAT_PROCESSOR to one of
331 -- -2 : use the default configuration (run the program on all
332 -- available processors) - this is the same as having
333 -- GNAT_PROCESSOR unset
334 -- -1 : let the RTS choose one processor and run the program on
336 -- 0 .. Last_Proc : run the program on the specified processor
338 -- Last_Proc is equal to the value of the system variable
339 -- _SC_NPROCESSORS_CONF, minus one.
341 procedure Configure_Processors
is
342 Proc_Acc
: constant GNAT
.OS_Lib
.String_Access
:=
343 GNAT
.OS_Lib
.Getenv
("GNAT_PROCESSOR");
344 Proc
: aliased processorid_t
; -- User processor #
345 Last_Proc
: processorid_t
; -- Last processor #
348 if Proc_Acc
.all'Length /= 0 then
349 -- Environment variable is defined
351 Last_Proc
:= Num_Procs
- 1;
353 if Last_Proc
/= -1 then
354 Proc
:= processorid_t
'Value (Proc_Acc
.all);
356 if Proc
<= -2 or else Proc
> Last_Proc
then
357 -- Use the default configuration
360 -- Choose a processor
364 while Proc
< Last_Proc
loop
366 Result
:= p_online
(Proc
, PR_STATUS
);
367 exit when Result
= PR_ONLINE
;
370 pragma Assert
(Result
= PR_ONLINE
);
371 Result
:= processor_bind
(P_PID
, P_MYID
, Proc
, null);
372 pragma Assert
(Result
= 0);
375 -- Use user processor
377 Result
:= processor_bind
(P_PID
, P_MYID
, Proc
, null);
378 pragma Assert
(Result
= 0);
384 when Constraint_Error
=>
386 -- Illegal environment variable GNAT_PROCESSOR - ignored
389 end Configure_Processors
;
392 (Int
: System
.Interrupt_Management
.Interrupt_ID
) return Character;
393 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
394 -- Get interrupt state. Defined in a-init.c
395 -- The input argument is the interrupt number,
396 -- and the result is one of the following:
398 Default
: constant Character := 's';
399 -- 'n' this interrupt not set by any Interrupt_State pragma
400 -- 'u' Interrupt_State pragma set state to User
401 -- 'r' Interrupt_State pragma set state to Runtime
402 -- 's' Interrupt_State pragma set state to System (use "default"
405 -- Start of processing for Initialize
408 Environment_Task_Id
:= Environment_Task
;
410 Interrupt_Management
.Initialize
;
412 -- Prepare the set of signals that should unblocked in all tasks
414 Result
:= sigemptyset
(Unblocked_Signal_Mask
'Access);
415 pragma Assert
(Result
= 0);
417 for J
in Interrupt_Management
.Interrupt_ID
loop
418 if System
.Interrupt_Management
.Keep_Unmasked
(J
) then
419 Result
:= sigaddset
(Unblocked_Signal_Mask
'Access, Signal
(J
));
420 pragma Assert
(Result
= 0);
424 if Dispatching_Policy
= 'F' then
426 Result
: Interfaces
.C
.long
;
427 Class_Info
: aliased struct_pcinfo
;
428 Secs
, Nsecs
: Interfaces
.C
.long
;
431 -- If a pragma Time_Slice is specified, takes the value in account
433 if Time_Slice_Val
> 0 then
434 -- Convert Time_Slice_Val (microseconds) into seconds and
437 Secs
:= Time_Slice_Val
/ 1_000_000
;
438 Nsecs
:= (Time_Slice_Val
rem 1_000_000
) * 1_000
;
440 -- Otherwise, default to no time slicing (i.e run until blocked)
447 -- Get the real time class id.
449 Class_Info
.pc_clname
(1) := 'R';
450 Class_Info
.pc_clname
(2) := 'T';
451 Class_Info
.pc_clname
(3) := ASCII
.NUL
;
453 Result
:= priocntl
(PC_VERSION
, P_LWPID
, P_MYID
, PC_GETCID
,
456 -- Request the real time class
458 Prio_Param
.pc_cid
:= Class_Info
.pc_cid
;
459 Prio_Param
.rt_pri
:= pri_t
(Class_Info
.rt_maxpri
);
460 Prio_Param
.rt_tqsecs
:= Secs
;
461 Prio_Param
.rt_tqnsecs
:= Nsecs
;
463 Result
:= priocntl
(PC_VERSION
, P_LWPID
, P_MYID
, PC_SETPARMS
,
466 Using_Real_Time_Class
:= Result
/= -1;
470 Specific
.Initialize
(Environment_Task
);
472 -- The following is done in Enter_Task, but this is too late for the
473 -- Environment Task, since we need to call Self in Check_Locks when
474 -- the run time is compiled with assertions on.
476 Specific
.Set
(Environment_Task
);
478 -- Initialize the lock used to synchronize chain of all ATCBs.
480 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
482 Enter_Task
(Environment_Task
);
484 -- Install the abort-signal handler
486 if State
(System
.Interrupt_Management
.Abort_Task_Interrupt
)
489 -- Set sa_flags to SA_NODEFER so that during the handler execution
490 -- we do not change the Signal_Mask to be masked for the Abort_Signal
491 -- This is a temporary fix to the problem that the Signal_Mask is
492 -- not restored after the exception (longjmp) from the handler.
493 -- The right fix should be made in sigsetjmp so that we save
494 -- the Signal_Set and restore it after a longjmp.
495 -- In that case, this field should be changed back to 0. ???
499 act
.sa_handler
:= Abort_Handler
'Address;
500 Result
:= sigemptyset
(Tmp_Set
'Access);
501 pragma Assert
(Result
= 0);
502 act
.sa_mask
:= Tmp_Set
;
506 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
),
507 act
'Unchecked_Access,
508 old_act
'Unchecked_Access);
509 pragma Assert
(Result
= 0);
512 Configure_Processors
;
515 ---------------------
516 -- Initialize_Lock --
517 ---------------------
519 -- Note: mutexes and cond_variables needed per-task basis are
520 -- initialized in Initialize_TCB and the Storage_Error is
521 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
522 -- used in RTS is initialized before any status change of RTS.
523 -- Therefore rasing Storage_Error in the following routines
524 -- should be able to be handled safely.
526 procedure Initialize_Lock
527 (Prio
: System
.Any_Priority
;
530 Result
: Interfaces
.C
.int
;
533 pragma Assert
(Check_Initialize_Lock
(Lock_Ptr
(L
), PO_Level
));
535 if Priority_Ceiling_Emulation
then
539 Result
:= mutex_init
(L
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
540 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
542 if Result
= ENOMEM
then
543 raise Storage_Error
with "Failed to allocate a lock";
547 procedure Initialize_Lock
548 (L
: access RTS_Lock
;
551 Result
: Interfaces
.C
.int
;
554 pragma Assert
(Check_Initialize_Lock
555 (To_Lock_Ptr
(RTS_Lock_Ptr
(L
)), Level
));
556 Result
:= mutex_init
(L
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
557 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
559 if Result
= ENOMEM
then
560 raise Storage_Error
with "Failed to allocate a lock";
568 procedure Finalize_Lock
(L
: access Lock
) is
569 Result
: Interfaces
.C
.int
;
572 pragma Assert
(Check_Finalize_Lock
(Lock_Ptr
(L
)));
573 Result
:= mutex_destroy
(L
.L
'Access);
574 pragma Assert
(Result
= 0);
577 procedure Finalize_Lock
(L
: access RTS_Lock
) is
578 Result
: Interfaces
.C
.int
;
581 pragma Assert
(Check_Finalize_Lock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
582 Result
:= mutex_destroy
(L
.L
'Access);
583 pragma Assert
(Result
= 0);
590 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
591 Result
: Interfaces
.C
.int
;
594 pragma Assert
(Check_Lock
(Lock_Ptr
(L
)));
596 if Priority_Ceiling_Emulation
and then Locking_Policy
= 'C' then
598 Self_Id
: constant Task_Id
:= Self
;
599 Saved_Priority
: System
.Any_Priority
;
602 if Self_Id
.Common
.LL
.Active_Priority
> L
.Ceiling
then
603 Ceiling_Violation
:= True;
607 Saved_Priority
:= Self_Id
.Common
.LL
.Active_Priority
;
609 if Self_Id
.Common
.LL
.Active_Priority
< L
.Ceiling
then
610 Set_Priority
(Self_Id
, L
.Ceiling
);
613 Result
:= mutex_lock
(L
.L
'Access);
614 pragma Assert
(Result
= 0);
615 Ceiling_Violation
:= False;
617 L
.Saved_Priority
:= Saved_Priority
;
621 Result
:= mutex_lock
(L
.L
'Access);
622 pragma Assert
(Result
= 0);
623 Ceiling_Violation
:= False;
626 pragma Assert
(Record_Lock
(Lock_Ptr
(L
)));
630 (L
: access RTS_Lock
;
631 Global_Lock
: Boolean := False)
633 Result
: Interfaces
.C
.int
;
636 if not Single_Lock
or else Global_Lock
then
637 pragma Assert
(Check_Lock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
638 Result
:= mutex_lock
(L
.L
'Access);
639 pragma Assert
(Result
= 0);
640 pragma Assert
(Record_Lock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
644 procedure Write_Lock
(T
: Task_Id
) is
645 Result
: Interfaces
.C
.int
;
648 if not Single_Lock
then
649 pragma Assert
(Check_Lock
(To_Lock_Ptr
(T
.Common
.LL
.L
'Access)));
650 Result
:= mutex_lock
(T
.Common
.LL
.L
.L
'Access);
651 pragma Assert
(Result
= 0);
652 pragma Assert
(Record_Lock
(To_Lock_Ptr
(T
.Common
.LL
.L
'Access)));
660 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
662 Write_Lock
(L
, Ceiling_Violation
);
669 procedure Unlock
(L
: access Lock
) is
670 Result
: Interfaces
.C
.int
;
673 pragma Assert
(Check_Unlock
(Lock_Ptr
(L
)));
675 if Priority_Ceiling_Emulation
and then Locking_Policy
= 'C' then
677 Self_Id
: constant Task_Id
:= Self
;
680 Result
:= mutex_unlock
(L
.L
'Access);
681 pragma Assert
(Result
= 0);
683 if Self_Id
.Common
.LL
.Active_Priority
> L
.Saved_Priority
then
684 Set_Priority
(Self_Id
, L
.Saved_Priority
);
688 Result
:= mutex_unlock
(L
.L
'Access);
689 pragma Assert
(Result
= 0);
693 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
694 Result
: Interfaces
.C
.int
;
697 if not Single_Lock
or else Global_Lock
then
698 pragma Assert
(Check_Unlock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
699 Result
:= mutex_unlock
(L
.L
'Access);
700 pragma Assert
(Result
= 0);
704 procedure Unlock
(T
: Task_Id
) is
705 Result
: Interfaces
.C
.int
;
708 if not Single_Lock
then
709 pragma Assert
(Check_Unlock
(To_Lock_Ptr
(T
.Common
.LL
.L
'Access)));
710 Result
:= mutex_unlock
(T
.Common
.LL
.L
.L
'Access);
711 pragma Assert
(Result
= 0);
715 -- For the time delay implementation, we need to make sure we
716 -- achieve following criteria:
718 -- 1) We have to delay at least for the amount requested.
719 -- 2) We have to give up CPU even though the actual delay does not
720 -- result in blocking.
721 -- 3) Except for restricted run-time systems that do not support
722 -- ATC or task abort, the delay must be interrupted by the
723 -- abort_task operation.
724 -- 4) The implementation has to be efficient so that the delay overhead
725 -- is relatively cheap.
726 -- (1)-(3) are Ada requirements. Even though (2) is an Annex-D
727 -- requirement we still want to provide the effect in all cases.
728 -- The reason is that users may want to use short delays to implement
729 -- their own scheduling effect in the absence of language provided
730 -- scheduling policies.
732 ---------------------
733 -- Monotonic_Clock --
734 ---------------------
736 function Monotonic_Clock
return Duration is
737 TS
: aliased timespec
;
738 Result
: Interfaces
.C
.int
;
740 Result
:= clock_gettime
(CLOCK_REALTIME
, TS
'Unchecked_Access);
741 pragma Assert
(Result
= 0);
742 return To_Duration
(TS
);
749 function RT_Resolution
return Duration is
758 procedure Yield
(Do_Yield
: Boolean := True) is
761 System
.OS_Interface
.thr_yield
;
769 function Self
return Task_Id
renames Specific
.Self
;
775 procedure Set_Priority
777 Prio
: System
.Any_Priority
;
778 Loss_Of_Inheritance
: Boolean := False)
780 pragma Unreferenced
(Loss_Of_Inheritance
);
782 Result
: Interfaces
.C
.int
;
783 pragma Unreferenced
(Result
);
785 Param
: aliased struct_pcparms
;
790 T
.Common
.Current_Priority
:= Prio
;
792 if Priority_Ceiling_Emulation
then
793 T
.Common
.LL
.Active_Priority
:= Prio
;
796 if Using_Real_Time_Class
then
797 Param
.pc_cid
:= Prio_Param
.pc_cid
;
798 Param
.rt_pri
:= pri_t
(Prio
);
799 Param
.rt_tqsecs
:= Prio_Param
.rt_tqsecs
;
800 Param
.rt_tqnsecs
:= Prio_Param
.rt_tqnsecs
;
802 Result
:= Interfaces
.C
.int
(
803 priocntl
(PC_VERSION
, P_LWPID
, T
.Common
.LL
.LWP
, PC_SETPARMS
,
807 if T
.Common
.Task_Info
/= null
808 and then not T
.Common
.Task_Info
.Bound_To_LWP
810 -- The task is not bound to a LWP, so use thr_setprio
813 thr_setprio
(T
.Common
.LL
.Thread
, Interfaces
.C
.int
(Prio
));
817 -- The task is bound to a LWP, use priocntl
829 function Get_Priority
(T
: Task_Id
) return System
.Any_Priority
is
831 return T
.Common
.Current_Priority
;
838 procedure Enter_Task
(Self_ID
: Task_Id
) is
839 Result
: Interfaces
.C
.int
;
840 Proc
: processorid_t
; -- User processor #
841 Last_Proc
: processorid_t
; -- Last processor #
843 use System
.Task_Info
;
845 Self_ID
.Common
.LL
.Thread
:= thr_self
;
847 Self_ID
.Common
.LL
.LWP
:= lwp_self
;
849 if Self_ID
.Common
.Task_Info
/= null then
850 if Self_ID
.Common
.Task_Info
.New_LWP
851 and then Self_ID
.Common
.Task_Info
.CPU
/= CPU_UNCHANGED
853 Last_Proc
:= Num_Procs
- 1;
855 if Self_ID
.Common
.Task_Info
.CPU
= ANY_CPU
then
859 while Proc
< Last_Proc
loop
860 Result
:= p_online
(Proc
, PR_STATUS
);
861 exit when Result
= PR_ONLINE
;
865 Result
:= processor_bind
(P_LWPID
, P_MYID
, Proc
, null);
866 pragma Assert
(Result
= 0);
869 -- Use specified processor
871 if Self_ID
.Common
.Task_Info
.CPU
< 0
872 or else Self_ID
.Common
.Task_Info
.CPU
> Last_Proc
874 raise Invalid_CPU_Number
;
877 Result
:= processor_bind
878 (P_LWPID
, P_MYID
, Self_ID
.Common
.Task_Info
.CPU
, null);
879 pragma Assert
(Result
= 0);
884 Specific
.Set
(Self_ID
);
886 -- We need the above code even if we do direct fetch of Task_Id in Self
887 -- for the main task on Sun, x86 Solaris and for gcc 2.7.2.
891 for J
in Known_Tasks
'Range loop
892 if Known_Tasks
(J
) = null then
893 Known_Tasks
(J
) := Self_ID
;
894 Self_ID
.Known_Tasks_Index
:= J
;
906 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_Id
is
908 return new Ada_Task_Control_Block
(Entry_Num
);
915 function Is_Valid_Task
return Boolean renames Specific
.Is_Valid_Task
;
917 -----------------------------
918 -- Register_Foreign_Thread --
919 -----------------------------
921 function Register_Foreign_Thread
return Task_Id
is
923 if Is_Valid_Task
then
926 return Register_Foreign_Thread
(thr_self
);
928 end Register_Foreign_Thread
;
934 procedure Initialize_TCB
(Self_ID
: Task_Id
; Succeeded
: out Boolean) is
935 Result
: Interfaces
.C
.int
:= 0;
938 -- Give the task a unique serial number.
940 Self_ID
.Serial_Number
:= Next_Serial_Number
;
941 Next_Serial_Number
:= Next_Serial_Number
+ 1;
942 pragma Assert
(Next_Serial_Number
/= 0);
944 Self_ID
.Common
.LL
.Thread
:= To_thread_t
(-1);
946 if not Single_Lock
then
948 (Self_ID
.Common
.LL
.L
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
949 Self_ID
.Common
.LL
.L
.Level
:=
950 Private_Task_Serial_Number
(Self_ID
.Serial_Number
);
951 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
955 Result
:= cond_init
(Self_ID
.Common
.LL
.CV
'Access, USYNC_THREAD
, 0);
956 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
962 if not Single_Lock
then
963 Result
:= mutex_destroy
(Self_ID
.Common
.LL
.L
.L
'Access);
964 pragma Assert
(Result
= 0);
975 procedure Create_Task
977 Wrapper
: System
.Address
;
978 Stack_Size
: System
.Parameters
.Size_Type
;
979 Priority
: System
.Any_Priority
;
980 Succeeded
: out Boolean)
982 pragma Unreferenced
(Priority
);
984 Result
: Interfaces
.C
.int
;
985 Adjusted_Stack_Size
: Interfaces
.C
.size_t
;
986 Opts
: Interfaces
.C
.int
:= THR_DETACHED
;
988 Page_Size
: constant System
.Parameters
.Size_Type
:= 4096;
989 -- This constant is for reserving extra space at the
990 -- end of the stack, which can be used by the stack
991 -- checking as guard page. The idea is that we need
992 -- to have at least Stack_Size bytes available for
995 use System
.Task_Info
;
998 if Stack_Size
= System
.Parameters
.Unspecified_Size
then
999 Adjusted_Stack_Size
:=
1000 Interfaces
.C
.size_t
(Default_Stack_Size
+ Page_Size
);
1002 elsif Stack_Size
< Minimum_Stack_Size
then
1003 Adjusted_Stack_Size
:=
1004 Interfaces
.C
.size_t
(Minimum_Stack_Size
+ Page_Size
);
1007 Adjusted_Stack_Size
:=
1008 Interfaces
.C
.size_t
(Stack_Size
+ Page_Size
);
1011 -- Since the initial signal mask of a thread is inherited from the
1012 -- creator, and the Environment task has all its signals masked, we
1013 -- do not need to manipulate caller's signal mask at this point.
1014 -- All tasks in RTS will have All_Tasks_Mask initially.
1016 if T
.Common
.Task_Info
/= null then
1017 if T
.Common
.Task_Info
.New_LWP
then
1018 Opts
:= Opts
+ THR_NEW_LWP
;
1021 if T
.Common
.Task_Info
.Bound_To_LWP
then
1022 Opts
:= Opts
+ THR_BOUND
;
1026 Opts
:= THR_DETACHED
+ THR_BOUND
;
1029 Result
:= thr_create
1030 (System
.Null_Address
,
1031 Adjusted_Stack_Size
,
1032 Thread_Body_Access
(Wrapper
),
1035 T
.Common
.LL
.Thread
'Access);
1037 Succeeded
:= Result
= 0;
1040 or else Result
= ENOMEM
1041 or else Result
= EAGAIN
);
1048 procedure Finalize_TCB
(T
: Task_Id
) is
1049 Result
: Interfaces
.C
.int
;
1051 Is_Self
: constant Boolean := T
= Self
;
1053 procedure Free
is new
1054 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_Id
);
1057 T
.Common
.LL
.Thread
:= To_thread_t
(0);
1059 if not Single_Lock
then
1060 Result
:= mutex_destroy
(T
.Common
.LL
.L
.L
'Access);
1061 pragma Assert
(Result
= 0);
1064 Result
:= cond_destroy
(T
.Common
.LL
.CV
'Access);
1065 pragma Assert
(Result
= 0);
1067 if T
.Known_Tasks_Index
/= -1 then
1068 Known_Tasks
(T
.Known_Tasks_Index
) := null;
1074 Specific
.Set
(null);
1082 -- This procedure must be called with abort deferred.
1083 -- It can no longer call Self or access
1084 -- the current task's ATCB, since the ATCB has been deallocated.
1086 procedure Exit_Task
is
1088 Specific
.Set
(null);
1095 procedure Abort_Task
(T
: Task_Id
) is
1096 Result
: Interfaces
.C
.int
;
1098 pragma Assert
(T
/= Self
);
1100 Result
:= thr_kill
(T
.Common
.LL
.Thread
,
1101 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
));
1102 pragma Assert
(Result
= 0);
1111 Reason
: Task_States
)
1113 Result
: Interfaces
.C
.int
;
1116 pragma Assert
(Check_Sleep
(Reason
));
1118 if Dynamic_Priority_Support
1119 and then Self_ID
.Pending_Priority_Change
1121 Self_ID
.Pending_Priority_Change
:= False;
1122 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
1123 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
1128 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
.L
'Access);
1131 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
.L
'Access);
1134 pragma Assert
(Record_Wakeup
1135 (To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access), Reason
));
1136 pragma Assert
(Result
= 0 or else Result
= EINTR
);
1139 -- Note that we are relying heaviliy here on the GNAT feature
1140 -- that Calendar.Time, System.Real_Time.Time, Duration, and
1141 -- System.Real_Time.Time_Span are all represented in the same
1142 -- way, i.e., as a 64-bit count of nanoseconds.
1144 -- This allows us to always pass the timeout value as a Duration.
1147 -- We are taking liberties here with the semantics of the delays.
1148 -- That is, we make no distinction between delays on the Calendar clock
1149 -- and delays on the Real_Time clock. That is technically incorrect, if
1150 -- the Calendar clock happens to be reset or adjusted.
1151 -- To solve this defect will require modification to the compiler
1152 -- interface, so that it can pass through more information, to tell
1153 -- us here which clock to use!
1155 -- cond_timedwait will return if any of the following happens:
1156 -- 1) some other task did cond_signal on this condition variable
1157 -- In this case, the return value is 0
1158 -- 2) the call just returned, for no good reason
1159 -- This is called a "spurious wakeup".
1160 -- In this case, the return value may also be 0.
1161 -- 3) the time delay expires
1162 -- In this case, the return value is ETIME
1163 -- 4) this task received a signal, which was handled by some
1164 -- handler procedure, and now the thread is resuming execution
1165 -- UNIX calls this an "interrupted" system call.
1166 -- In this case, the return value is EINTR
1168 -- If the cond_timedwait returns 0 or EINTR, it is still
1169 -- possible that the time has actually expired, and by chance
1170 -- a signal or cond_signal occurred at around the same time.
1172 -- We have also observed that on some OS's the value ETIME
1173 -- will be returned, but the clock will show that the full delay
1174 -- has not yet expired.
1176 -- For these reasons, we need to check the clock after return
1177 -- from cond_timedwait. If the time has expired, we will set
1180 -- This check might be omitted for systems on which the
1181 -- cond_timedwait() never returns early or wakes up spuriously.
1183 -- Annex D requires that completion of a delay cause the task
1184 -- to go to the end of its priority queue, regardless of whether
1185 -- the task actually was suspended by the delay. Since
1186 -- cond_timedwait does not do this on Solaris, we add a call
1187 -- to thr_yield at the end. We might do this at the beginning,
1188 -- instead, but then the round-robin effect would not be the
1189 -- same; the delayed task would be ahead of other tasks of the
1190 -- same priority that awoke while it was sleeping.
1192 -- For Timed_Sleep, we are expecting possible cond_signals
1193 -- to indicate other events (e.g., completion of a RV or
1194 -- completion of the abortable part of an async. select),
1195 -- we want to always return if interrupted. The caller will
1196 -- be responsible for checking the task state to see whether
1197 -- the wakeup was spurious, and to go back to sleep again
1198 -- in that case. We don't need to check for pending abort
1199 -- or priority change on the way in our out; that is the
1200 -- caller's responsibility.
1202 -- For Timed_Delay, we are not expecting any cond_signals or
1203 -- other interruptions, except for priority changes and aborts.
1204 -- Therefore, we don't want to return unless the delay has
1205 -- actually expired, or the call has been aborted. In this
1206 -- case, since we want to implement the entire delay statement
1207 -- semantics, we do need to check for pending abort and priority
1208 -- changes. We can quietly handle priority changes inside the
1209 -- procedure, since there is no entry-queue reordering involved.
1215 procedure Timed_Sleep
1218 Mode
: ST
.Delay_Modes
;
1219 Reason
: System
.Tasking
.Task_States
;
1220 Timedout
: out Boolean;
1221 Yielded
: out Boolean)
1223 Check_Time
: constant Duration := Monotonic_Clock
;
1224 Abs_Time
: Duration;
1225 Request
: aliased timespec
;
1226 Result
: Interfaces
.C
.int
;
1229 pragma Assert
(Check_Sleep
(Reason
));
1233 if Mode
= Relative
then
1234 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
1236 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
1239 if Abs_Time
> Check_Time
then
1240 Request
:= To_Timespec
(Abs_Time
);
1243 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
1244 or else (Dynamic_Priority_Support
and then
1245 Self_ID
.Pending_Priority_Change
);
1248 Result
:= cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
1249 Single_RTS_Lock
.L
'Access, Request
'Access);
1251 Result
:= cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
1252 Self_ID
.Common
.LL
.L
.L
'Access, Request
'Access);
1257 exit when Abs_Time
<= Monotonic_Clock
;
1259 if Result
= 0 or Result
= EINTR
then
1261 -- Somebody may have called Wakeup for us
1267 pragma Assert
(Result
= ETIME
);
1271 pragma Assert
(Record_Wakeup
1272 (To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access), Reason
));
1279 procedure Timed_Delay
1282 Mode
: ST
.Delay_Modes
)
1284 Check_Time
: constant Duration := Monotonic_Clock
;
1285 Abs_Time
: Duration;
1286 Request
: aliased timespec
;
1287 Result
: Interfaces
.C
.int
;
1288 Yielded
: Boolean := False;
1295 Write_Lock
(Self_ID
);
1297 if Mode
= Relative
then
1298 Abs_Time
:= Time
+ Check_Time
;
1300 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
1303 if Abs_Time
> Check_Time
then
1304 Request
:= To_Timespec
(Abs_Time
);
1305 Self_ID
.Common
.State
:= Delay_Sleep
;
1307 pragma Assert
(Check_Sleep
(Delay_Sleep
));
1310 if Dynamic_Priority_Support
and then
1311 Self_ID
.Pending_Priority_Change
then
1312 Self_ID
.Pending_Priority_Change
:= False;
1313 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
1314 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
1317 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
1320 Result
:= cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
1321 Single_RTS_Lock
.L
'Access, Request
'Access);
1323 Result
:= cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
1324 Self_ID
.Common
.LL
.L
.L
'Access, Request
'Access);
1329 exit when Abs_Time
<= Monotonic_Clock
;
1331 pragma Assert
(Result
= 0 or else
1332 Result
= ETIME
or else
1336 pragma Assert
(Record_Wakeup
1337 (To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access), Delay_Sleep
));
1339 Self_ID
.Common
.State
:= Runnable
;
1359 Reason
: Task_States
)
1361 Result
: Interfaces
.C
.int
;
1364 pragma Assert
(Check_Wakeup
(T
, Reason
));
1365 Result
:= cond_signal
(T
.Common
.LL
.CV
'Access);
1366 pragma Assert
(Result
= 0);
1369 ---------------------------
1370 -- Check_Initialize_Lock --
1371 ---------------------------
1373 -- The following code is intended to check some of the invariant
1374 -- assertions related to lock usage, on which we depend.
1376 function Check_Initialize_Lock
1378 Level
: Lock_Level
) return Boolean
1380 Self_ID
: constant Task_Id
:= Self
;
1383 -- Check that caller is abort-deferred
1385 if Self_ID
.Deferral_Level
= 0 then
1389 -- Check that the lock is not yet initialized
1391 if L
.Level
/= 0 then
1395 L
.Level
:= Lock_Level
'Pos (Level
) + 1;
1397 end Check_Initialize_Lock
;
1403 function Check_Lock
(L
: Lock_Ptr
) return Boolean is
1404 Self_ID
: constant Task_Id
:= Self
;
1408 -- Check that the argument is not null
1414 -- Check that L is not frozen
1420 -- Check that caller is abort-deferred
1422 if Self_ID
.Deferral_Level
= 0 then
1426 -- Check that caller is not holding this lock already
1428 if L
.Owner
= To_Owner_ID
(To_Address
(Self_ID
)) then
1436 -- Check that TCB lock order rules are satisfied
1438 P
:= Self_ID
.Common
.LL
.Locks
;
1440 if P
.Level
>= L
.Level
1441 and then (P
.Level
> 2 or else L
.Level
> 2)
1454 function Record_Lock
(L
: Lock_Ptr
) return Boolean is
1455 Self_ID
: constant Task_Id
:= Self
;
1459 Lock_Count
:= Lock_Count
+ 1;
1461 -- There should be no owner for this lock at this point
1463 if L
.Owner
/= null then
1469 L
.Owner
:= To_Owner_ID
(To_Address
(Self_ID
));
1475 -- Check that TCB lock order rules are satisfied
1477 P
:= Self_ID
.Common
.LL
.Locks
;
1483 Self_ID
.Common
.LL
.Locking
:= null;
1484 Self_ID
.Common
.LL
.Locks
:= L
;
1492 function Check_Sleep
(Reason
: Task_States
) return Boolean is
1493 pragma Unreferenced
(Reason
);
1495 Self_ID
: constant Task_Id
:= Self
;
1499 -- Check that caller is abort-deferred
1501 if Self_ID
.Deferral_Level
= 0 then
1509 -- Check that caller is holding own lock, on top of list
1511 if Self_ID
.Common
.LL
.Locks
/=
1512 To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access)
1517 -- Check that TCB lock order rules are satisfied
1519 if Self_ID
.Common
.LL
.Locks
.Next
/= null then
1523 Self_ID
.Common
.LL
.L
.Owner
:= null;
1524 P
:= Self_ID
.Common
.LL
.Locks
;
1525 Self_ID
.Common
.LL
.Locks
:= Self_ID
.Common
.LL
.Locks
.Next
;
1534 function Record_Wakeup
1536 Reason
: Task_States
) return Boolean
1538 pragma Unreferenced
(Reason
);
1540 Self_ID
: constant Task_Id
:= Self
;
1546 L
.Owner
:= To_Owner_ID
(To_Address
(Self_ID
));
1552 -- Check that TCB lock order rules are satisfied
1554 P
:= Self_ID
.Common
.LL
.Locks
;
1560 Self_ID
.Common
.LL
.Locking
:= null;
1561 Self_ID
.Common
.LL
.Locks
:= L
;
1569 function Check_Wakeup
1571 Reason
: Task_States
) return Boolean
1573 Self_ID
: constant Task_Id
:= Self
;
1576 -- Is caller holding T's lock?
1578 if T
.Common
.LL
.L
.Owner
/= To_Owner_ID
(To_Address
(Self_ID
)) then
1582 -- Are reasons for wakeup and sleep consistent?
1584 if T
.Common
.State
/= Reason
then
1595 function Check_Unlock
(L
: Lock_Ptr
) return Boolean is
1596 Self_ID
: constant Task_Id
:= Self
;
1600 Unlock_Count
:= Unlock_Count
+ 1;
1606 if L
.Buddy
/= null then
1611 Check_Count
:= Unlock_Count
;
1614 if Unlock_Count
- Check_Count
> 1000 then
1615 Check_Count
:= Unlock_Count
;
1618 -- Check that caller is abort-deferred
1620 if Self_ID
.Deferral_Level
= 0 then
1624 -- Check that caller is holding this lock, on top of list
1626 if Self_ID
.Common
.LL
.Locks
/= L
then
1630 -- Record there is no owner now
1633 P
:= Self_ID
.Common
.LL
.Locks
;
1634 Self_ID
.Common
.LL
.Locks
:= Self_ID
.Common
.LL
.Locks
.Next
;
1639 --------------------
1640 -- Check_Finalize --
1641 --------------------
1643 function Check_Finalize_Lock
(L
: Lock_Ptr
) return Boolean is
1644 Self_ID
: constant Task_Id
:= Self
;
1647 -- Check that caller is abort-deferred
1649 if Self_ID
.Deferral_Level
= 0 then
1653 -- Check that no one is holding this lock
1655 if L
.Owner
/= null then
1661 end Check_Finalize_Lock
;
1667 procedure Initialize
(S
: in out Suspension_Object
) is
1668 Result
: Interfaces
.C
.int
;
1670 -- Initialize internal state. It is always initialized to False (ARM
1676 -- Initialize internal mutex
1678 Result
:= mutex_init
(S
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
1679 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
1681 if Result
= ENOMEM
then
1682 raise Storage_Error
with "Failed to allocate a lock";
1685 -- Initialize internal condition variable
1687 Result
:= cond_init
(S
.CV
'Access, USYNC_THREAD
, 0);
1688 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
1691 Result
:= mutex_destroy
(S
.L
'Access);
1692 pragma Assert
(Result
= 0);
1694 if Result
= ENOMEM
then
1695 raise Storage_Error
;
1704 procedure Finalize
(S
: in out Suspension_Object
) is
1705 Result
: Interfaces
.C
.int
;
1707 -- Destroy internal mutex
1709 Result
:= mutex_destroy
(S
.L
'Access);
1710 pragma Assert
(Result
= 0);
1712 -- Destroy internal condition variable
1714 Result
:= cond_destroy
(S
.CV
'Access);
1715 pragma Assert
(Result
= 0);
1722 function Current_State
(S
: Suspension_Object
) return Boolean is
1724 -- We do not want to use lock on this read operation. State is marked
1725 -- as Atomic so that we ensure that the value retrieved is correct.
1734 procedure Set_False
(S
: in out Suspension_Object
) is
1735 Result
: Interfaces
.C
.int
;
1737 Result
:= mutex_lock
(S
.L
'Access);
1738 pragma Assert
(Result
= 0);
1742 Result
:= mutex_unlock
(S
.L
'Access);
1743 pragma Assert
(Result
= 0);
1750 procedure Set_True
(S
: in out Suspension_Object
) is
1751 Result
: Interfaces
.C
.int
;
1753 Result
:= mutex_lock
(S
.L
'Access);
1754 pragma Assert
(Result
= 0);
1756 -- If there is already a task waiting on this suspension object then
1757 -- we resume it, leaving the state of the suspension object to False,
1758 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1759 -- the state to True.
1765 Result
:= cond_signal
(S
.CV
'Access);
1766 pragma Assert
(Result
= 0);
1771 Result
:= mutex_unlock
(S
.L
'Access);
1772 pragma Assert
(Result
= 0);
1775 ------------------------
1776 -- Suspend_Until_True --
1777 ------------------------
1779 procedure Suspend_Until_True
(S
: in out Suspension_Object
) is
1780 Result
: Interfaces
.C
.int
;
1782 Result
:= mutex_lock
(S
.L
'Access);
1783 pragma Assert
(Result
= 0);
1786 -- Program_Error must be raised upon calling Suspend_Until_True
1787 -- if another task is already waiting on that suspension object
1788 -- (ARM D.10 par. 10).
1790 Result
:= mutex_unlock
(S
.L
'Access);
1791 pragma Assert
(Result
= 0);
1793 raise Program_Error
;
1795 -- Suspend the task if the state is False. Otherwise, the task
1796 -- continues its execution, and the state of the suspension object
1797 -- is set to False (ARM D.10 par. 9).
1803 Result
:= cond_wait
(S
.CV
'Access, S
.L
'Access);
1807 Result
:= mutex_unlock
(S
.L
'Access);
1808 pragma Assert
(Result
= 0);
1809 end Suspend_Until_True
;
1815 function Check_Exit
(Self_ID
: Task_Id
) return Boolean is
1817 -- Check that caller is just holding Global_Task_Lock
1818 -- and no other locks
1820 if Self_ID
.Common
.LL
.Locks
= null then
1824 -- 2 = Global_Task_Level
1826 if Self_ID
.Common
.LL
.Locks
.Level
/= 2 then
1830 if Self_ID
.Common
.LL
.Locks
.Next
/= null then
1834 -- Check that caller is abort-deferred
1836 if Self_ID
.Deferral_Level
= 0 then
1843 --------------------
1844 -- Check_No_Locks --
1845 --------------------
1847 function Check_No_Locks
(Self_ID
: Task_Id
) return Boolean is
1849 return Self_ID
.Common
.LL
.Locks
= null;
1852 ----------------------
1853 -- Environment_Task --
1854 ----------------------
1856 function Environment_Task
return Task_Id
is
1858 return Environment_Task_Id
;
1859 end Environment_Task
;
1865 procedure Lock_RTS
is
1867 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1874 procedure Unlock_RTS
is
1876 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1883 function Suspend_Task
1885 Thread_Self
: Thread_Id
) return Boolean
1888 if T
.Common
.LL
.Thread
/= Thread_Self
then
1889 return thr_suspend
(T
.Common
.LL
.Thread
) = 0;
1899 function Resume_Task
1901 Thread_Self
: Thread_Id
) return Boolean
1904 if T
.Common
.LL
.Thread
/= Thread_Self
then
1905 return thr_continue
(T
.Common
.LL
.Thread
) = 0;
1911 end System
.Task_Primitives
.Operations
;