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-2006, 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
.Task_Info
;
65 -- to initialize Task_Info for a C thread, in function Self
67 with System
.Soft_Links
;
68 -- used for Defer/Undefer_Abort
70 -- We use System.Soft_Links instead of System.Tasking.Initialization
71 -- because the later is a higher level package that we shouldn't depend on.
72 -- For example when using the restricted run time, it is replaced by
73 -- System.Tasking.Restricted.Stages.
75 with Unchecked_Deallocation
;
77 package body System
.Task_Primitives
.Operations
is
79 package SSL
renames System
.Soft_Links
;
81 use System
.Tasking
.Debug
;
84 use System
.OS_Interface
;
85 use System
.Parameters
;
86 use System
.OS_Primitives
;
92 -- The following are logically constants, but need to be initialized
95 Environment_Task_Id
: Task_Id
;
96 -- A variable to hold Task_Id for the environment task.
97 -- If we use this variable to get the Task_Id, we need the following
98 -- ATCB_Key only for non-Ada threads.
100 Unblocked_Signal_Mask
: aliased sigset_t
;
101 -- The set of signals that should unblocked in all tasks
103 ATCB_Key
: aliased thread_key_t
;
104 -- Key used to find the Ada Task_Id associated with a thread,
105 -- at least for C threads unknown to the Ada run-time system.
107 Single_RTS_Lock
: aliased RTS_Lock
;
108 -- This is a lock to allow only one thread of control in the RTS at
109 -- a time; it is used to execute in mutual exclusion from all other tasks.
110 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
112 Next_Serial_Number
: Task_Serial_Number
:= 100;
113 -- We start at 100, to reserve some special values for
114 -- using in error checking.
115 -- The following are internal configuration constants needed.
117 ----------------------
118 -- Priority Support --
119 ----------------------
121 Priority_Ceiling_Emulation
: constant Boolean := True;
122 -- controls whether we emulate priority ceiling locking
124 -- To get a scheduling close to annex D requirements, we use the real-time
125 -- class provided for LWP's and map each task/thread to a specific and
126 -- unique LWP (there is 1 thread per LWP, and 1 LWP per thread).
128 -- The real time class can only be set when the process has root
129 -- priviledges, so in the other cases, we use the normal thread scheduling
130 -- and priority handling.
132 Using_Real_Time_Class
: Boolean := False;
133 -- indicates wether the real time class is being used (i.e the process
134 -- has root priviledges).
136 Prio_Param
: aliased struct_pcparms
;
137 -- Hold priority info (Real_Time) initialized during the package
140 -----------------------------------
141 -- External Configuration Values --
142 -----------------------------------
144 Time_Slice_Val
: Integer;
145 pragma Import
(C
, Time_Slice_Val
, "__gl_time_slice_val");
147 Locking_Policy
: Character;
148 pragma Import
(C
, Locking_Policy
, "__gl_locking_policy");
150 Dispatching_Policy
: Character;
151 pragma Import
(C
, Dispatching_Policy
, "__gl_task_dispatching_policy");
153 Foreign_Task_Elaborated
: aliased Boolean := True;
154 -- Used to identified fake tasks (i.e., non-Ada Threads)
156 -----------------------
157 -- Local Subprograms --
158 -----------------------
160 function sysconf
(name
: System
.OS_Interface
.int
) return processorid_t
;
161 pragma Import
(C
, sysconf
, "sysconf");
163 SC_NPROCESSORS_CONF
: constant System
.OS_Interface
.int
:= 14;
166 (name
: System
.OS_Interface
.int
:= SC_NPROCESSORS_CONF
)
167 return processorid_t
renames sysconf
;
169 procedure Abort_Handler
171 Code
: access siginfo_t
;
172 Context
: access ucontext_t
);
173 -- Target-dependent binding of inter-thread Abort signal to
174 -- the raising of the Abort_Signal exception.
175 -- See also comments in 7staprop.adb
181 function Check_Initialize_Lock
183 Level
: Lock_Level
) return Boolean;
184 pragma Inline
(Check_Initialize_Lock
);
186 function Check_Lock
(L
: Lock_Ptr
) return Boolean;
187 pragma Inline
(Check_Lock
);
189 function Record_Lock
(L
: Lock_Ptr
) return Boolean;
190 pragma Inline
(Record_Lock
);
192 function Check_Sleep
(Reason
: Task_States
) return Boolean;
193 pragma Inline
(Check_Sleep
);
195 function Record_Wakeup
197 Reason
: Task_States
) return Boolean;
198 pragma Inline
(Record_Wakeup
);
200 function Check_Wakeup
202 Reason
: Task_States
) return Boolean;
203 pragma Inline
(Check_Wakeup
);
205 function Check_Unlock
(L
: Lock_Ptr
) return Boolean;
206 pragma Inline
(Check_Unlock
);
208 function Check_Finalize_Lock
(L
: Lock_Ptr
) return Boolean;
209 pragma Inline
(Check_Finalize_Lock
);
217 procedure Initialize
(Environment_Task
: Task_Id
);
218 pragma Inline
(Initialize
);
219 -- Initialize various data needed by this package
221 function Is_Valid_Task
return Boolean;
222 pragma Inline
(Is_Valid_Task
);
223 -- Does executing thread have a TCB?
225 procedure Set
(Self_Id
: Task_Id
);
227 -- Set the self id for the current task
229 function Self
return Task_Id
;
230 pragma Inline
(Self
);
231 -- Return a pointer to the Ada Task Control Block of the calling task
235 package body Specific
is separate;
236 -- The body of this package is target specific
238 ---------------------------------
239 -- Support for foreign threads --
240 ---------------------------------
242 function Register_Foreign_Thread
(Thread
: Thread_Id
) return Task_Id
;
243 -- Allocate and Initialize a new ATCB for the current Thread
245 function Register_Foreign_Thread
246 (Thread
: Thread_Id
) return Task_Id
is separate;
252 Check_Count
: Integer := 0;
253 Lock_Count
: Integer := 0;
254 Unlock_Count
: Integer := 0;
260 procedure Abort_Handler
262 Code
: access siginfo_t
;
263 Context
: access ucontext_t
)
265 pragma Unreferenced
(Sig
);
266 pragma Unreferenced
(Code
);
267 pragma Unreferenced
(Context
);
269 Self_ID
: constant Task_Id
:= Self
;
270 Old_Set
: aliased sigset_t
;
272 Result
: Interfaces
.C
.int
;
275 -- It is not safe to raise an exception when using ZCX and the GCC
276 -- exception handling mechanism.
278 if ZCX_By_Default
and then GCC_ZCX_Support
then
282 if Self_ID
.Deferral_Level
= 0
283 and then Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
284 and then not Self_ID
.Aborting
286 Self_ID
.Aborting
:= True;
288 -- Make sure signals used for RTS internal purpose are unmasked
290 Result
:= thr_sigsetmask
(SIG_UNBLOCK
,
291 Unblocked_Signal_Mask
'Unchecked_Access, Old_Set
'Unchecked_Access);
292 pragma Assert
(Result
= 0);
294 raise Standard
'Abort_Signal;
302 -- The underlying thread system sets a guard page at the
303 -- bottom of a thread stack, so nothing is needed.
305 procedure Stack_Guard
(T
: ST
.Task_Id
; On
: Boolean) is
306 pragma Unreferenced
(T
);
307 pragma Unreferenced
(On
);
316 function Get_Thread_Id
(T
: ST
.Task_Id
) return OSI
.Thread_Id
is
318 return T
.Common
.LL
.Thread
;
325 procedure Initialize
(Environment_Task
: ST
.Task_Id
) is
326 act
: aliased struct_sigaction
;
327 old_act
: aliased struct_sigaction
;
328 Tmp_Set
: aliased sigset_t
;
329 Result
: Interfaces
.C
.int
;
331 procedure Configure_Processors
;
332 -- Processors configuration
333 -- The user can specify a processor which the program should run
334 -- on to emulate a single-processor system. This can be easily
335 -- done by setting environment variable GNAT_PROCESSOR to one of
338 -- -2 : use the default configuration (run the program on all
339 -- available processors) - this is the same as having
340 -- GNAT_PROCESSOR unset
341 -- -1 : let the RTS choose one processor and run the program on
343 -- 0 .. Last_Proc : run the program on the specified processor
345 -- Last_Proc is equal to the value of the system variable
346 -- _SC_NPROCESSORS_CONF, minus one.
348 procedure Configure_Processors
is
349 Proc_Acc
: constant GNAT
.OS_Lib
.String_Access
:=
350 GNAT
.OS_Lib
.Getenv
("GNAT_PROCESSOR");
351 Proc
: aliased processorid_t
; -- User processor #
352 Last_Proc
: processorid_t
; -- Last processor #
355 if Proc_Acc
.all'Length /= 0 then
357 -- Environment variable is defined
359 Last_Proc
:= Num_Procs
- 1;
361 if Last_Proc
/= -1 then
362 Proc
:= processorid_t
'Value (Proc_Acc
.all);
364 if Proc
<= -2 or else Proc
> Last_Proc
then
365 -- Use the default configuration
368 -- Choose a processor
372 while Proc
< Last_Proc
loop
374 Result
:= p_online
(Proc
, PR_STATUS
);
375 exit when Result
= PR_ONLINE
;
378 pragma Assert
(Result
= PR_ONLINE
);
379 Result
:= processor_bind
(P_PID
, P_MYID
, Proc
, null);
380 pragma Assert
(Result
= 0);
383 -- Use user processor
385 Result
:= processor_bind
(P_PID
, P_MYID
, Proc
, null);
386 pragma Assert
(Result
= 0);
392 when Constraint_Error
=>
394 -- Illegal environment variable GNAT_PROCESSOR - ignored
397 end Configure_Processors
;
400 (Int
: System
.Interrupt_Management
.Interrupt_ID
) return Character;
401 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
402 -- Get interrupt state. Defined in a-init.c
403 -- The input argument is the interrupt number,
404 -- and the result is one of the following:
406 Default
: constant Character := 's';
407 -- 'n' this interrupt not set by any Interrupt_State pragma
408 -- 'u' Interrupt_State pragma set state to User
409 -- 'r' Interrupt_State pragma set state to Runtime
410 -- 's' Interrupt_State pragma set state to System (use "default"
413 -- Start of processing for Initialize
416 Environment_Task_Id
:= Environment_Task
;
418 Interrupt_Management
.Initialize
;
420 -- Prepare the set of signals that should unblocked in all tasks
422 Result
:= sigemptyset
(Unblocked_Signal_Mask
'Access);
423 pragma Assert
(Result
= 0);
425 for J
in Interrupt_Management
.Interrupt_ID
loop
426 if System
.Interrupt_Management
.Keep_Unmasked
(J
) then
427 Result
:= sigaddset
(Unblocked_Signal_Mask
'Access, Signal
(J
));
428 pragma Assert
(Result
= 0);
432 if Dispatching_Policy
= 'F' then
434 Result
: Interfaces
.C
.long
;
435 Class_Info
: aliased struct_pcinfo
;
436 Secs
, Nsecs
: Interfaces
.C
.long
;
439 -- If a pragma Time_Slice is specified, takes the value in account
441 if Time_Slice_Val
> 0 then
443 -- Convert Time_Slice_Val (microseconds) into seconds and
446 Secs
:= Interfaces
.C
.long
(Time_Slice_Val
/ 1_000_000
);
448 Interfaces
.C
.long
((Time_Slice_Val
rem 1_000_000
) * 1_000
);
450 -- Otherwise, default to no time slicing (i.e run until blocked)
457 -- Get the real time class id
459 Class_Info
.pc_clname
(1) := 'R';
460 Class_Info
.pc_clname
(2) := 'T';
461 Class_Info
.pc_clname
(3) := ASCII
.NUL
;
463 Result
:= priocntl
(PC_VERSION
, P_LWPID
, P_MYID
, PC_GETCID
,
466 -- Request the real time class
468 Prio_Param
.pc_cid
:= Class_Info
.pc_cid
;
469 Prio_Param
.rt_pri
:= pri_t
(Class_Info
.rt_maxpri
);
470 Prio_Param
.rt_tqsecs
:= Secs
;
471 Prio_Param
.rt_tqnsecs
:= Nsecs
;
473 Result
:= priocntl
(PC_VERSION
, P_LWPID
, P_MYID
, PC_SETPARMS
,
476 Using_Real_Time_Class
:= Result
/= -1;
480 Specific
.Initialize
(Environment_Task
);
482 -- The following is done in Enter_Task, but this is too late for the
483 -- Environment Task, since we need to call Self in Check_Locks when
484 -- the run time is compiled with assertions on.
486 Specific
.Set
(Environment_Task
);
488 -- Initialize the lock used to synchronize chain of all ATCBs
490 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
492 Enter_Task
(Environment_Task
);
494 -- Install the abort-signal handler
496 if State
(System
.Interrupt_Management
.Abort_Task_Interrupt
)
499 -- Set sa_flags to SA_NODEFER so that during the handler execution
500 -- we do not change the Signal_Mask to be masked for the Abort_Signal
501 -- This is a temporary fix to the problem that the Signal_Mask is
502 -- not restored after the exception (longjmp) from the handler.
503 -- The right fix should be made in sigsetjmp so that we save
504 -- the Signal_Set and restore it after a longjmp.
505 -- In that case, this field should be changed back to 0. ???
509 act
.sa_handler
:= Abort_Handler
'Address;
510 Result
:= sigemptyset
(Tmp_Set
'Access);
511 pragma Assert
(Result
= 0);
512 act
.sa_mask
:= Tmp_Set
;
516 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
),
517 act
'Unchecked_Access,
518 old_act
'Unchecked_Access);
519 pragma Assert
(Result
= 0);
522 Configure_Processors
;
525 ---------------------
526 -- Initialize_Lock --
527 ---------------------
529 -- Note: mutexes and cond_variables needed per-task basis are
530 -- initialized in Initialize_TCB and the Storage_Error is
531 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
532 -- used in RTS is initialized before any status change of RTS.
533 -- Therefore rasing Storage_Error in the following routines
534 -- should be able to be handled safely.
536 procedure Initialize_Lock
537 (Prio
: System
.Any_Priority
;
540 Result
: Interfaces
.C
.int
;
543 pragma Assert
(Check_Initialize_Lock
(Lock_Ptr
(L
), PO_Level
));
545 if Priority_Ceiling_Emulation
then
549 Result
:= mutex_init
(L
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
550 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
552 if Result
= ENOMEM
then
553 raise Storage_Error
with "Failed to allocate a lock";
557 procedure Initialize_Lock
558 (L
: access RTS_Lock
;
561 Result
: Interfaces
.C
.int
;
564 pragma Assert
(Check_Initialize_Lock
565 (To_Lock_Ptr
(RTS_Lock_Ptr
(L
)), Level
));
566 Result
:= mutex_init
(L
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
567 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
569 if Result
= ENOMEM
then
570 raise Storage_Error
with "Failed to allocate a lock";
578 procedure Finalize_Lock
(L
: access Lock
) is
579 Result
: Interfaces
.C
.int
;
582 pragma Assert
(Check_Finalize_Lock
(Lock_Ptr
(L
)));
583 Result
:= mutex_destroy
(L
.L
'Access);
584 pragma Assert
(Result
= 0);
587 procedure Finalize_Lock
(L
: access RTS_Lock
) is
588 Result
: Interfaces
.C
.int
;
591 pragma Assert
(Check_Finalize_Lock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
592 Result
:= mutex_destroy
(L
.L
'Access);
593 pragma Assert
(Result
= 0);
600 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
601 Result
: Interfaces
.C
.int
;
604 pragma Assert
(Check_Lock
(Lock_Ptr
(L
)));
606 if Priority_Ceiling_Emulation
and then Locking_Policy
= 'C' then
608 Self_Id
: constant Task_Id
:= Self
;
609 Saved_Priority
: System
.Any_Priority
;
612 if Self_Id
.Common
.LL
.Active_Priority
> L
.Ceiling
then
613 Ceiling_Violation
:= True;
617 Saved_Priority
:= Self_Id
.Common
.LL
.Active_Priority
;
619 if Self_Id
.Common
.LL
.Active_Priority
< L
.Ceiling
then
620 Set_Priority
(Self_Id
, L
.Ceiling
);
623 Result
:= mutex_lock
(L
.L
'Access);
624 pragma Assert
(Result
= 0);
625 Ceiling_Violation
:= False;
627 L
.Saved_Priority
:= Saved_Priority
;
631 Result
:= mutex_lock
(L
.L
'Access);
632 pragma Assert
(Result
= 0);
633 Ceiling_Violation
:= False;
636 pragma Assert
(Record_Lock
(Lock_Ptr
(L
)));
640 (L
: access RTS_Lock
;
641 Global_Lock
: Boolean := False)
643 Result
: Interfaces
.C
.int
;
646 if not Single_Lock
or else Global_Lock
then
647 pragma Assert
(Check_Lock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
648 Result
:= mutex_lock
(L
.L
'Access);
649 pragma Assert
(Result
= 0);
650 pragma Assert
(Record_Lock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
654 procedure Write_Lock
(T
: Task_Id
) is
655 Result
: Interfaces
.C
.int
;
658 if not Single_Lock
then
659 pragma Assert
(Check_Lock
(To_Lock_Ptr
(T
.Common
.LL
.L
'Access)));
660 Result
:= mutex_lock
(T
.Common
.LL
.L
.L
'Access);
661 pragma Assert
(Result
= 0);
662 pragma Assert
(Record_Lock
(To_Lock_Ptr
(T
.Common
.LL
.L
'Access)));
670 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
672 Write_Lock
(L
, Ceiling_Violation
);
679 procedure Unlock
(L
: access Lock
) is
680 Result
: Interfaces
.C
.int
;
683 pragma Assert
(Check_Unlock
(Lock_Ptr
(L
)));
685 if Priority_Ceiling_Emulation
and then Locking_Policy
= 'C' then
687 Self_Id
: constant Task_Id
:= Self
;
690 Result
:= mutex_unlock
(L
.L
'Access);
691 pragma Assert
(Result
= 0);
693 if Self_Id
.Common
.LL
.Active_Priority
> L
.Saved_Priority
then
694 Set_Priority
(Self_Id
, L
.Saved_Priority
);
698 Result
:= mutex_unlock
(L
.L
'Access);
699 pragma Assert
(Result
= 0);
703 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
704 Result
: Interfaces
.C
.int
;
706 if not Single_Lock
or else Global_Lock
then
707 pragma Assert
(Check_Unlock
(To_Lock_Ptr
(RTS_Lock_Ptr
(L
))));
708 Result
:= mutex_unlock
(L
.L
'Access);
709 pragma Assert
(Result
= 0);
713 procedure Unlock
(T
: Task_Id
) is
714 Result
: Interfaces
.C
.int
;
716 if not Single_Lock
then
717 pragma Assert
(Check_Unlock
(To_Lock_Ptr
(T
.Common
.LL
.L
'Access)));
718 Result
:= mutex_unlock
(T
.Common
.LL
.L
.L
'Access);
719 pragma Assert
(Result
= 0);
723 -- For the time delay implementation, we need to make sure we
724 -- achieve following criteria:
726 -- 1) We have to delay at least for the amount requested.
727 -- 2) We have to give up CPU even though the actual delay does not
728 -- result in blocking.
729 -- 3) Except for restricted run-time systems that do not support
730 -- ATC or task abort, the delay must be interrupted by the
731 -- abort_task operation.
732 -- 4) The implementation has to be efficient so that the delay overhead
733 -- is relatively cheap.
734 -- (1)-(3) are Ada requirements. Even though (2) is an Annex-D
735 -- requirement we still want to provide the effect in all cases.
736 -- The reason is that users may want to use short delays to implement
737 -- their own scheduling effect in the absence of language provided
738 -- scheduling policies.
740 ---------------------
741 -- Monotonic_Clock --
742 ---------------------
744 function Monotonic_Clock
return Duration is
745 TS
: aliased timespec
;
746 Result
: Interfaces
.C
.int
;
748 Result
:= clock_gettime
(CLOCK_REALTIME
, TS
'Unchecked_Access);
749 pragma Assert
(Result
= 0);
750 return To_Duration
(TS
);
757 function RT_Resolution
return Duration is
766 procedure Yield
(Do_Yield
: Boolean := True) is
769 System
.OS_Interface
.thr_yield
;
777 function Self
return Task_Id
renames Specific
.Self
;
783 procedure Set_Priority
785 Prio
: System
.Any_Priority
;
786 Loss_Of_Inheritance
: Boolean := False)
788 pragma Unreferenced
(Loss_Of_Inheritance
);
790 Result
: Interfaces
.C
.int
;
791 pragma Unreferenced
(Result
);
793 Param
: aliased struct_pcparms
;
798 T
.Common
.Current_Priority
:= Prio
;
800 if Priority_Ceiling_Emulation
then
801 T
.Common
.LL
.Active_Priority
:= Prio
;
804 if Using_Real_Time_Class
then
805 Param
.pc_cid
:= Prio_Param
.pc_cid
;
806 Param
.rt_pri
:= pri_t
(Prio
);
807 Param
.rt_tqsecs
:= Prio_Param
.rt_tqsecs
;
808 Param
.rt_tqnsecs
:= Prio_Param
.rt_tqnsecs
;
810 Result
:= Interfaces
.C
.int
(
811 priocntl
(PC_VERSION
, P_LWPID
, T
.Common
.LL
.LWP
, PC_SETPARMS
,
815 if T
.Common
.Task_Info
/= null
816 and then not T
.Common
.Task_Info
.Bound_To_LWP
818 -- The task is not bound to a LWP, so use thr_setprio
821 thr_setprio
(T
.Common
.LL
.Thread
, Interfaces
.C
.int
(Prio
));
824 -- The task is bound to a LWP, use priocntl
836 function Get_Priority
(T
: Task_Id
) return System
.Any_Priority
is
838 return T
.Common
.Current_Priority
;
845 procedure Enter_Task
(Self_ID
: Task_Id
) is
846 Result
: Interfaces
.C
.int
;
847 Proc
: processorid_t
; -- User processor #
848 Last_Proc
: processorid_t
; -- Last processor #
850 use System
.Task_Info
;
852 Self_ID
.Common
.LL
.Thread
:= thr_self
;
854 Self_ID
.Common
.LL
.LWP
:= lwp_self
;
856 if Self_ID
.Common
.Task_Info
/= null then
857 if Self_ID
.Common
.Task_Info
.New_LWP
858 and then Self_ID
.Common
.Task_Info
.CPU
/= CPU_UNCHANGED
860 Last_Proc
:= Num_Procs
- 1;
862 if Self_ID
.Common
.Task_Info
.CPU
= ANY_CPU
then
866 while Proc
< Last_Proc
loop
867 Result
:= p_online
(Proc
, PR_STATUS
);
868 exit when Result
= PR_ONLINE
;
872 Result
:= processor_bind
(P_LWPID
, P_MYID
, Proc
, null);
873 pragma Assert
(Result
= 0);
876 -- Use specified processor
878 if Self_ID
.Common
.Task_Info
.CPU
< 0
879 or else Self_ID
.Common
.Task_Info
.CPU
> Last_Proc
881 raise Invalid_CPU_Number
;
884 Result
:= processor_bind
885 (P_LWPID
, P_MYID
, Self_ID
.Common
.Task_Info
.CPU
, null);
886 pragma Assert
(Result
= 0);
891 Specific
.Set
(Self_ID
);
893 -- We need the above code even if we do direct fetch of Task_Id in Self
894 -- for the main task on Sun, x86 Solaris and for gcc 2.7.2.
898 for J
in Known_Tasks
'Range loop
899 if Known_Tasks
(J
) = null then
900 Known_Tasks
(J
) := Self_ID
;
901 Self_ID
.Known_Tasks_Index
:= J
;
913 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_Id
is
915 return new Ada_Task_Control_Block
(Entry_Num
);
922 function Is_Valid_Task
return Boolean renames Specific
.Is_Valid_Task
;
924 -----------------------------
925 -- Register_Foreign_Thread --
926 -----------------------------
928 function Register_Foreign_Thread
return Task_Id
is
930 if Is_Valid_Task
then
933 return Register_Foreign_Thread
(thr_self
);
935 end Register_Foreign_Thread
;
941 procedure Initialize_TCB
(Self_ID
: Task_Id
; Succeeded
: out Boolean) is
942 Result
: Interfaces
.C
.int
:= 0;
945 -- Give the task a unique serial number
947 Self_ID
.Serial_Number
:= Next_Serial_Number
;
948 Next_Serial_Number
:= Next_Serial_Number
+ 1;
949 pragma Assert
(Next_Serial_Number
/= 0);
951 Self_ID
.Common
.LL
.Thread
:= To_thread_t
(-1);
953 if not Single_Lock
then
955 (Self_ID
.Common
.LL
.L
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
956 Self_ID
.Common
.LL
.L
.Level
:=
957 Private_Task_Serial_Number
(Self_ID
.Serial_Number
);
958 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
962 Result
:= cond_init
(Self_ID
.Common
.LL
.CV
'Access, USYNC_THREAD
, 0);
963 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
969 if not Single_Lock
then
970 Result
:= mutex_destroy
(Self_ID
.Common
.LL
.L
.L
'Access);
971 pragma Assert
(Result
= 0);
982 procedure Create_Task
984 Wrapper
: System
.Address
;
985 Stack_Size
: System
.Parameters
.Size_Type
;
986 Priority
: System
.Any_Priority
;
987 Succeeded
: out Boolean)
989 pragma Unreferenced
(Priority
);
991 Result
: Interfaces
.C
.int
;
992 Adjusted_Stack_Size
: Interfaces
.C
.size_t
;
993 Opts
: Interfaces
.C
.int
:= THR_DETACHED
;
995 Page_Size
: constant System
.Parameters
.Size_Type
:= 4096;
996 -- This constant is for reserving extra space at the
997 -- end of the stack, which can be used by the stack
998 -- checking as guard page. The idea is that we need
999 -- to have at least Stack_Size bytes available for
1002 use System
.Task_Info
;
1005 Adjusted_Stack_Size
:= Interfaces
.C
.size_t
(Stack_Size
+ Page_Size
);
1007 -- Since the initial signal mask of a thread is inherited from the
1008 -- creator, and the Environment task has all its signals masked, we
1009 -- do not need to manipulate caller's signal mask at this point.
1010 -- All tasks in RTS will have All_Tasks_Mask initially.
1012 if T
.Common
.Task_Info
/= null then
1013 if T
.Common
.Task_Info
.New_LWP
then
1014 Opts
:= Opts
+ THR_NEW_LWP
;
1017 if T
.Common
.Task_Info
.Bound_To_LWP
then
1018 Opts
:= Opts
+ THR_BOUND
;
1022 Opts
:= THR_DETACHED
+ THR_BOUND
;
1025 Result
:= thr_create
1026 (System
.Null_Address
,
1027 Adjusted_Stack_Size
,
1028 Thread_Body_Access
(Wrapper
),
1031 T
.Common
.LL
.Thread
'Access);
1033 Succeeded
:= Result
= 0;
1036 or else Result
= ENOMEM
1037 or else Result
= EAGAIN
);
1044 procedure Finalize_TCB
(T
: Task_Id
) is
1045 Result
: Interfaces
.C
.int
;
1047 Is_Self
: constant Boolean := T
= Self
;
1049 procedure Free
is new
1050 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_Id
);
1053 T
.Common
.LL
.Thread
:= To_thread_t
(0);
1055 if not Single_Lock
then
1056 Result
:= mutex_destroy
(T
.Common
.LL
.L
.L
'Access);
1057 pragma Assert
(Result
= 0);
1060 Result
:= cond_destroy
(T
.Common
.LL
.CV
'Access);
1061 pragma Assert
(Result
= 0);
1063 if T
.Known_Tasks_Index
/= -1 then
1064 Known_Tasks
(T
.Known_Tasks_Index
) := null;
1070 Specific
.Set
(null);
1078 -- This procedure must be called with abort deferred.
1079 -- It can no longer call Self or access
1080 -- the current task's ATCB, since the ATCB has been deallocated.
1082 procedure Exit_Task
is
1084 Specific
.Set
(null);
1091 procedure Abort_Task
(T
: Task_Id
) is
1092 Result
: Interfaces
.C
.int
;
1094 pragma Assert
(T
/= Self
);
1096 Result
:= thr_kill
(T
.Common
.LL
.Thread
,
1097 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
));
1098 pragma Assert
(Result
= 0);
1107 Reason
: Task_States
)
1109 Result
: Interfaces
.C
.int
;
1112 pragma Assert
(Check_Sleep
(Reason
));
1114 if Dynamic_Priority_Support
1115 and then Self_ID
.Pending_Priority_Change
1117 Self_ID
.Pending_Priority_Change
:= False;
1118 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
1119 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
1124 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
.L
'Access);
1127 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
.L
'Access);
1130 pragma Assert
(Record_Wakeup
1131 (To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access), Reason
));
1132 pragma Assert
(Result
= 0 or else Result
= EINTR
);
1135 -- Note that we are relying heaviliy here on GNAT represting Calendar.Time,
1136 -- System.Real_Time.Time, Duration, System.Real_Time.Time_Span in the same
1137 -- way, i.e., as a 64-bit count of nanoseconds.
1139 -- This allows us to always pass the timeout value as a Duration
1142 -- We are taking liberties here with the semantics of the delays. That is,
1143 -- we make no distinction between delays on the Calendar clock and delays
1144 -- on the Real_Time clock. That is technically incorrect, if the Calendar
1145 -- clock happens to be reset or adjusted. To solve this defect will require
1146 -- modification to the compiler interface, so that it can pass through more
1147 -- information, to tell us here which clock to use!
1149 -- cond_timedwait will return if any of the following happens:
1150 -- 1) some other task did cond_signal on this condition variable
1151 -- In this case, the return value is 0
1152 -- 2) the call just returned, for no good reason
1153 -- This is called a "spurious wakeup".
1154 -- In this case, the return value may also be 0.
1155 -- 3) the time delay expires
1156 -- In this case, the return value is ETIME
1157 -- 4) this task received a signal, which was handled by some
1158 -- handler procedure, and now the thread is resuming execution
1159 -- UNIX calls this an "interrupted" system call.
1160 -- In this case, the return value is EINTR
1162 -- If the cond_timedwait returns 0 or EINTR, it is still possible that the
1163 -- time has actually expired, and by chance a signal or cond_signal
1164 -- occurred at around the same time.
1166 -- We have also observed that on some OS's the value ETIME will be
1167 -- returned, but the clock will show that the full delay has not yet
1170 -- For these reasons, we need to check the clock after return from
1171 -- cond_timedwait. If the time has expired, we will set Timedout = True.
1173 -- This check might be omitted for systems on which the cond_timedwait()
1174 -- never returns early or wakes up spuriously.
1176 -- Annex D requires that completion of a delay cause the task to go to the
1177 -- end of its priority queue, regardless of whether the task actually was
1178 -- suspended by the delay. Since cond_timedwait does not do this on
1179 -- Solaris, we add a call to thr_yield at the end. We might do this at the
1180 -- beginning, instead, but then the round-robin effect would not be the
1181 -- same; the delayed task would be ahead of other tasks of the same
1182 -- priority that awoke while it was sleeping.
1184 -- For Timed_Sleep, we are expecting possible cond_signals to indicate
1185 -- other events (e.g., completion of a RV or completion of the abortable
1186 -- part of an async. select), we want to always return if interrupted. The
1187 -- caller will be responsible for checking the task state to see whether
1188 -- the wakeup was spurious, and to go back to sleep again in that case. We
1189 -- don't need to check for pending abort or priority change on the way in
1190 -- our out; that is the caller's responsibility.
1192 -- For Timed_Delay, we are not expecting any cond_signals or other
1193 -- interruptions, except for priority changes and aborts. Therefore, we
1194 -- don't want to return unless the delay has actually expired, or the call
1195 -- has been aborted. In this case, since we want to implement the entire
1196 -- delay statement semantics, we do need to check for pending abort and
1197 -- priority changes. We can quietly handle priority changes inside the
1198 -- procedure, since there is no entry-queue reordering involved.
1204 procedure Timed_Sleep
1207 Mode
: ST
.Delay_Modes
;
1208 Reason
: System
.Tasking
.Task_States
;
1209 Timedout
: out Boolean;
1210 Yielded
: out Boolean)
1212 Check_Time
: constant Duration := Monotonic_Clock
;
1213 Abs_Time
: Duration;
1214 Request
: aliased timespec
;
1215 Result
: Interfaces
.C
.int
;
1218 pragma Assert
(Check_Sleep
(Reason
));
1222 if Mode
= Relative
then
1223 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
1225 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
1228 if Abs_Time
> Check_Time
then
1229 Request
:= To_Timespec
(Abs_Time
);
1232 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
1233 or else (Dynamic_Priority_Support
and then
1234 Self_ID
.Pending_Priority_Change
);
1237 Result
:= cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
1238 Single_RTS_Lock
.L
'Access, Request
'Access);
1240 Result
:= cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
1241 Self_ID
.Common
.LL
.L
.L
'Access, Request
'Access);
1246 exit when Abs_Time
<= Monotonic_Clock
;
1248 if Result
= 0 or Result
= EINTR
then
1250 -- Somebody may have called Wakeup for us
1256 pragma Assert
(Result
= ETIME
);
1260 pragma Assert
(Record_Wakeup
1261 (To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access), Reason
));
1268 procedure Timed_Delay
1271 Mode
: ST
.Delay_Modes
)
1273 Check_Time
: constant Duration := Monotonic_Clock
;
1274 Abs_Time
: Duration;
1275 Request
: aliased timespec
;
1276 Result
: Interfaces
.C
.int
;
1277 Yielded
: Boolean := False;
1284 Write_Lock
(Self_ID
);
1286 if Mode
= Relative
then
1287 Abs_Time
:= Time
+ Check_Time
;
1289 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
1292 if Abs_Time
> Check_Time
then
1293 Request
:= To_Timespec
(Abs_Time
);
1294 Self_ID
.Common
.State
:= Delay_Sleep
;
1296 pragma Assert
(Check_Sleep
(Delay_Sleep
));
1299 if Dynamic_Priority_Support
and then
1300 Self_ID
.Pending_Priority_Change
then
1301 Self_ID
.Pending_Priority_Change
:= False;
1302 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
1303 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
1306 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
1309 Result
:= cond_timedwait
1310 (Self_ID
.Common
.LL
.CV
'Access,
1311 Single_RTS_Lock
.L
'Access,
1314 Result
:= cond_timedwait
1315 (Self_ID
.Common
.LL
.CV
'Access,
1316 Self_ID
.Common
.LL
.L
.L
'Access,
1322 exit when Abs_Time
<= Monotonic_Clock
;
1324 pragma Assert
(Result
= 0 or else
1325 Result
= ETIME
or else
1329 pragma Assert
(Record_Wakeup
1330 (To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access), Delay_Sleep
));
1332 Self_ID
.Common
.State
:= Runnable
;
1352 Reason
: Task_States
)
1354 Result
: Interfaces
.C
.int
;
1357 pragma Assert
(Check_Wakeup
(T
, Reason
));
1358 Result
:= cond_signal
(T
.Common
.LL
.CV
'Access);
1359 pragma Assert
(Result
= 0);
1362 ---------------------------
1363 -- Check_Initialize_Lock --
1364 ---------------------------
1366 -- The following code is intended to check some of the invariant
1367 -- assertions related to lock usage, on which we depend.
1369 function Check_Initialize_Lock
1371 Level
: Lock_Level
) return Boolean
1373 Self_ID
: constant Task_Id
:= Self
;
1376 -- Check that caller is abort-deferred
1378 if Self_ID
.Deferral_Level
= 0 then
1382 -- Check that the lock is not yet initialized
1384 if L
.Level
/= 0 then
1388 L
.Level
:= Lock_Level
'Pos (Level
) + 1;
1390 end Check_Initialize_Lock
;
1396 function Check_Lock
(L
: Lock_Ptr
) return Boolean is
1397 Self_ID
: constant Task_Id
:= Self
;
1401 -- Check that the argument is not null
1407 -- Check that L is not frozen
1413 -- Check that caller is abort-deferred
1415 if Self_ID
.Deferral_Level
= 0 then
1419 -- Check that caller is not holding this lock already
1421 if L
.Owner
= To_Owner_ID
(To_Address
(Self_ID
)) then
1429 -- Check that TCB lock order rules are satisfied
1431 P
:= Self_ID
.Common
.LL
.Locks
;
1433 if P
.Level
>= L
.Level
1434 and then (P
.Level
> 2 or else L
.Level
> 2)
1447 function Record_Lock
(L
: Lock_Ptr
) return Boolean is
1448 Self_ID
: constant Task_Id
:= Self
;
1452 Lock_Count
:= Lock_Count
+ 1;
1454 -- There should be no owner for this lock at this point
1456 if L
.Owner
/= null then
1462 L
.Owner
:= To_Owner_ID
(To_Address
(Self_ID
));
1468 -- Check that TCB lock order rules are satisfied
1470 P
:= Self_ID
.Common
.LL
.Locks
;
1476 Self_ID
.Common
.LL
.Locking
:= null;
1477 Self_ID
.Common
.LL
.Locks
:= L
;
1485 function Check_Sleep
(Reason
: Task_States
) return Boolean is
1486 pragma Unreferenced
(Reason
);
1488 Self_ID
: constant Task_Id
:= Self
;
1492 -- Check that caller is abort-deferred
1494 if Self_ID
.Deferral_Level
= 0 then
1502 -- Check that caller is holding own lock, on top of list
1504 if Self_ID
.Common
.LL
.Locks
/=
1505 To_Lock_Ptr
(Self_ID
.Common
.LL
.L
'Access)
1510 -- Check that TCB lock order rules are satisfied
1512 if Self_ID
.Common
.LL
.Locks
.Next
/= null then
1516 Self_ID
.Common
.LL
.L
.Owner
:= null;
1517 P
:= Self_ID
.Common
.LL
.Locks
;
1518 Self_ID
.Common
.LL
.Locks
:= Self_ID
.Common
.LL
.Locks
.Next
;
1527 function Record_Wakeup
1529 Reason
: Task_States
) return Boolean
1531 pragma Unreferenced
(Reason
);
1533 Self_ID
: constant Task_Id
:= Self
;
1539 L
.Owner
:= To_Owner_ID
(To_Address
(Self_ID
));
1545 -- Check that TCB lock order rules are satisfied
1547 P
:= Self_ID
.Common
.LL
.Locks
;
1553 Self_ID
.Common
.LL
.Locking
:= null;
1554 Self_ID
.Common
.LL
.Locks
:= L
;
1562 function Check_Wakeup
1564 Reason
: Task_States
) return Boolean
1566 Self_ID
: constant Task_Id
:= Self
;
1569 -- Is caller holding T's lock?
1571 if T
.Common
.LL
.L
.Owner
/= To_Owner_ID
(To_Address
(Self_ID
)) then
1575 -- Are reasons for wakeup and sleep consistent?
1577 if T
.Common
.State
/= Reason
then
1588 function Check_Unlock
(L
: Lock_Ptr
) return Boolean is
1589 Self_ID
: constant Task_Id
:= Self
;
1593 Unlock_Count
:= Unlock_Count
+ 1;
1599 if L
.Buddy
/= null then
1604 Check_Count
:= Unlock_Count
;
1607 if Unlock_Count
- Check_Count
> 1000 then
1608 Check_Count
:= Unlock_Count
;
1611 -- Check that caller is abort-deferred
1613 if Self_ID
.Deferral_Level
= 0 then
1617 -- Check that caller is holding this lock, on top of list
1619 if Self_ID
.Common
.LL
.Locks
/= L
then
1623 -- Record there is no owner now
1626 P
:= Self_ID
.Common
.LL
.Locks
;
1627 Self_ID
.Common
.LL
.Locks
:= Self_ID
.Common
.LL
.Locks
.Next
;
1632 --------------------
1633 -- Check_Finalize --
1634 --------------------
1636 function Check_Finalize_Lock
(L
: Lock_Ptr
) return Boolean is
1637 Self_ID
: constant Task_Id
:= Self
;
1640 -- Check that caller is abort-deferred
1642 if Self_ID
.Deferral_Level
= 0 then
1646 -- Check that no one is holding this lock
1648 if L
.Owner
/= null then
1654 end Check_Finalize_Lock
;
1660 procedure Initialize
(S
: in out Suspension_Object
) is
1661 Result
: Interfaces
.C
.int
;
1663 -- Initialize internal state. It is always initialized to False (ARM
1669 -- Initialize internal mutex
1671 Result
:= mutex_init
(S
.L
'Access, USYNC_THREAD
, System
.Null_Address
);
1672 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
1674 if Result
= ENOMEM
then
1675 raise Storage_Error
with "Failed to allocate a lock";
1678 -- Initialize internal condition variable
1680 Result
:= cond_init
(S
.CV
'Access, USYNC_THREAD
, 0);
1681 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
1684 Result
:= mutex_destroy
(S
.L
'Access);
1685 pragma Assert
(Result
= 0);
1687 if Result
= ENOMEM
then
1688 raise Storage_Error
;
1697 procedure Finalize
(S
: in out Suspension_Object
) is
1698 Result
: Interfaces
.C
.int
;
1700 -- Destroy internal mutex
1702 Result
:= mutex_destroy
(S
.L
'Access);
1703 pragma Assert
(Result
= 0);
1705 -- Destroy internal condition variable
1707 Result
:= cond_destroy
(S
.CV
'Access);
1708 pragma Assert
(Result
= 0);
1715 function Current_State
(S
: Suspension_Object
) return Boolean is
1717 -- We do not want to use lock on this read operation. State is marked
1718 -- as Atomic so that we ensure that the value retrieved is correct.
1727 procedure Set_False
(S
: in out Suspension_Object
) is
1728 Result
: Interfaces
.C
.int
;
1730 SSL
.Abort_Defer
.all;
1732 Result
:= mutex_lock
(S
.L
'Access);
1733 pragma Assert
(Result
= 0);
1737 Result
:= mutex_unlock
(S
.L
'Access);
1738 pragma Assert
(Result
= 0);
1740 SSL
.Abort_Undefer
.all;
1747 procedure Set_True
(S
: in out Suspension_Object
) is
1748 Result
: Interfaces
.C
.int
;
1750 SSL
.Abort_Defer
.all;
1752 Result
:= mutex_lock
(S
.L
'Access);
1753 pragma Assert
(Result
= 0);
1755 -- If there is already a task waiting on this suspension object then
1756 -- we resume it, leaving the state of the suspension object to False,
1757 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
1758 -- the state to True.
1764 Result
:= cond_signal
(S
.CV
'Access);
1765 pragma Assert
(Result
= 0);
1770 Result
:= mutex_unlock
(S
.L
'Access);
1771 pragma Assert
(Result
= 0);
1773 SSL
.Abort_Undefer
.all;
1776 ------------------------
1777 -- Suspend_Until_True --
1778 ------------------------
1780 procedure Suspend_Until_True
(S
: in out Suspension_Object
) is
1781 Result
: Interfaces
.C
.int
;
1783 SSL
.Abort_Defer
.all;
1785 Result
:= mutex_lock
(S
.L
'Access);
1786 pragma Assert
(Result
= 0);
1789 -- Program_Error must be raised upon calling Suspend_Until_True
1790 -- if another task is already waiting on that suspension object
1791 -- (ARM D.10 par. 10).
1793 Result
:= mutex_unlock
(S
.L
'Access);
1794 pragma Assert
(Result
= 0);
1796 SSL
.Abort_Undefer
.all;
1798 raise Program_Error
;
1800 -- Suspend the task if the state is False. Otherwise, the task
1801 -- continues its execution, and the state of the suspension object
1802 -- is set to False (ARM D.10 par. 9).
1808 Result
:= cond_wait
(S
.CV
'Access, S
.L
'Access);
1811 Result
:= mutex_unlock
(S
.L
'Access);
1812 pragma Assert
(Result
= 0);
1814 SSL
.Abort_Undefer
.all;
1816 end Suspend_Until_True
;
1822 function Check_Exit
(Self_ID
: Task_Id
) return Boolean is
1824 -- Check that caller is just holding Global_Task_Lock and no other locks
1826 if Self_ID
.Common
.LL
.Locks
= null then
1830 -- 2 = Global_Task_Level
1832 if Self_ID
.Common
.LL
.Locks
.Level
/= 2 then
1836 if Self_ID
.Common
.LL
.Locks
.Next
/= null then
1840 -- Check that caller is abort-deferred
1842 if Self_ID
.Deferral_Level
= 0 then
1849 --------------------
1850 -- Check_No_Locks --
1851 --------------------
1853 function Check_No_Locks
(Self_ID
: Task_Id
) return Boolean is
1855 return Self_ID
.Common
.LL
.Locks
= null;
1858 ----------------------
1859 -- Environment_Task --
1860 ----------------------
1862 function Environment_Task
return Task_Id
is
1864 return Environment_Task_Id
;
1865 end Environment_Task
;
1871 procedure Lock_RTS
is
1873 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1880 procedure Unlock_RTS
is
1882 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1889 function Suspend_Task
1891 Thread_Self
: Thread_Id
) return Boolean
1894 if T
.Common
.LL
.Thread
/= Thread_Self
then
1895 return thr_suspend
(T
.Common
.LL
.Thread
) = 0;
1905 function Resume_Task
1907 Thread_Self
: Thread_Id
) return Boolean
1910 if T
.Common
.LL
.Thread
/= Thread_Self
then
1911 return thr_continue
(T
.Common
.LL
.Thread
) = 0;
1917 end System
.Task_Primitives
.Operations
;