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 HP-UX DCE threads (HPUX 10) 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 pragma Warnings
(Off
);
52 with System
.Interrupt_Management
.Operations
;
53 -- used for Set_Interrupt_Mask
55 pragma Elaborate_All
(System
.Interrupt_Management
.Operations
);
59 with System
.OS_Primitives
;
60 -- used for Delay_Modes
66 with System
.Parameters
;
69 with System
.Task_Primitives
.Interrupt_Operations
;
70 -- used for Get_Interrupt_ID
72 with System
.Soft_Links
;
73 -- used for Defer/Undefer_Abort
75 -- We use System.Soft_Links instead of System.Tasking.Initialization
76 -- because the later is a higher level package that we shouldn't depend on.
77 -- For example when using the restricted run time, it is replaced by
78 -- System.Tasking.Restricted.Stages.
80 with Unchecked_Conversion
;
81 with Unchecked_Deallocation
;
83 package body System
.Task_Primitives
.Operations
is
85 package SSL
renames System
.Soft_Links
;
87 use System
.Tasking
.Debug
;
90 use System
.OS_Interface
;
91 use System
.Parameters
;
92 use System
.OS_Primitives
;
94 package PIO
renames System
.Task_Primitives
.Interrupt_Operations
;
100 -- The followings are logically constants, but need to be initialized
103 Single_RTS_Lock
: aliased RTS_Lock
;
104 -- This is a lock to allow only one thread of control in the RTS at
105 -- a time; it is used to execute in mutual exclusion from all other tasks.
106 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
108 ATCB_Key
: aliased pthread_key_t
;
109 -- Key used to find the Ada Task_Id associated with a thread
111 Environment_Task_Id
: Task_Id
;
112 -- A variable to hold Task_Id for the environment task
114 Unblocked_Signal_Mask
: aliased sigset_t
;
115 -- The set of signals that should unblocked in all tasks
117 Time_Slice_Val
: Integer;
118 pragma Import
(C
, Time_Slice_Val
, "__gl_time_slice_val");
120 Dispatching_Policy
: Character;
121 pragma Import
(C
, Dispatching_Policy
, "__gl_task_dispatching_policy");
123 -- Note: the reason that Locking_Policy is not needed is that this
124 -- is not implemented for DCE threads. The HPUX 10 port is at this
125 -- stage considered dead, and no further work is planned on it.
127 Foreign_Task_Elaborated
: aliased Boolean := True;
128 -- Used to identified fake tasks (i.e., non-Ada Threads)
136 procedure Initialize
(Environment_Task
: Task_Id
);
137 pragma Inline
(Initialize
);
138 -- Initialize various data needed by this package
140 function Is_Valid_Task
return Boolean;
141 pragma Inline
(Is_Valid_Task
);
142 -- Does the executing thread have a TCB?
144 procedure Set
(Self_Id
: Task_Id
);
146 -- Set the self id for the current task
148 function Self
return Task_Id
;
149 pragma Inline
(Self
);
150 -- Return a pointer to the Ada Task Control Block of the calling task
154 package body Specific
is separate;
155 -- The body of this package is target specific
157 ---------------------------------
158 -- Support for foreign threads --
159 ---------------------------------
161 function Register_Foreign_Thread
(Thread
: Thread_Id
) return Task_Id
;
162 -- Allocate and Initialize a new ATCB for the current Thread
164 function Register_Foreign_Thread
165 (Thread
: Thread_Id
) return Task_Id
is separate;
167 -----------------------
168 -- Local Subprograms --
169 -----------------------
171 procedure Abort_Handler
(Sig
: Signal
);
173 function To_Address
is new Unchecked_Conversion
(Task_Id
, System
.Address
);
179 procedure Abort_Handler
(Sig
: Signal
) is
180 pragma Unreferenced
(Sig
);
182 Self_Id
: constant Task_Id
:= Self
;
183 Result
: Interfaces
.C
.int
;
184 Old_Set
: aliased sigset_t
;
187 if Self_Id
.Deferral_Level
= 0
188 and then Self_Id
.Pending_ATC_Level
< Self_Id
.ATC_Nesting_Level
and then
191 Self_Id
.Aborting
:= True;
193 -- Make sure signals used for RTS internal purpose are unmasked
195 Result
:= pthread_sigmask
(SIG_UNBLOCK
,
196 Unblocked_Signal_Mask
'Unchecked_Access, Old_Set
'Unchecked_Access);
197 pragma Assert
(Result
= 0);
199 raise Standard
'Abort_Signal;
207 -- The underlying thread system sets a guard page at the
208 -- bottom of a thread stack, so nothing is needed.
209 -- ??? Check the comment above
211 procedure Stack_Guard
(T
: ST
.Task_Id
; On
: Boolean) is
212 pragma Unreferenced
(T
, On
);
221 function Get_Thread_Id
(T
: ST
.Task_Id
) return OSI
.Thread_Id
is
223 return T
.Common
.LL
.Thread
;
230 function Self
return Task_Id
renames Specific
.Self
;
232 ---------------------
233 -- Initialize_Lock --
234 ---------------------
236 -- Note: mutexes and cond_variables needed per-task basis are
237 -- initialized in Initialize_TCB and the Storage_Error is
238 -- handled. Other mutexes (such as RTS_Lock, Memory_Lock...)
239 -- used in RTS is initialized before any status change of RTS.
240 -- Therefore rasing Storage_Error in the following routines
241 -- should be able to be handled safely.
243 procedure Initialize_Lock
244 (Prio
: System
.Any_Priority
;
247 Attributes
: aliased pthread_mutexattr_t
;
248 Result
: Interfaces
.C
.int
;
251 Result
:= pthread_mutexattr_init
(Attributes
'Access);
252 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
254 if Result
= ENOMEM
then
260 Result
:= pthread_mutex_init
(L
.L
'Access, Attributes
'Access);
261 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
263 if Result
= ENOMEM
then
267 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
268 pragma Assert
(Result
= 0);
271 procedure Initialize_Lock
(L
: access RTS_Lock
; Level
: Lock_Level
) is
272 pragma Unreferenced
(Level
);
274 Attributes
: aliased pthread_mutexattr_t
;
275 Result
: Interfaces
.C
.int
;
278 Result
:= pthread_mutexattr_init
(Attributes
'Access);
279 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
281 if Result
= ENOMEM
then
285 Result
:= pthread_mutex_init
(L
, Attributes
'Access);
287 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
289 if Result
= ENOMEM
then
293 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
294 pragma Assert
(Result
= 0);
301 procedure Finalize_Lock
(L
: access Lock
) is
302 Result
: Interfaces
.C
.int
;
304 Result
:= pthread_mutex_destroy
(L
.L
'Access);
305 pragma Assert
(Result
= 0);
308 procedure Finalize_Lock
(L
: access RTS_Lock
) is
309 Result
: Interfaces
.C
.int
;
311 Result
:= pthread_mutex_destroy
(L
);
312 pragma Assert
(Result
= 0);
319 procedure Write_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
320 Result
: Interfaces
.C
.int
;
323 L
.Owner_Priority
:= Get_Priority
(Self
);
325 if L
.Priority
< L
.Owner_Priority
then
326 Ceiling_Violation
:= True;
330 Result
:= pthread_mutex_lock
(L
.L
'Access);
331 pragma Assert
(Result
= 0);
332 Ceiling_Violation
:= False;
336 (L
: access RTS_Lock
; Global_Lock
: Boolean := False)
338 Result
: Interfaces
.C
.int
;
340 if not Single_Lock
or else Global_Lock
then
341 Result
:= pthread_mutex_lock
(L
);
342 pragma Assert
(Result
= 0);
346 procedure Write_Lock
(T
: Task_Id
) is
347 Result
: Interfaces
.C
.int
;
349 if not Single_Lock
then
350 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
351 pragma Assert
(Result
= 0);
359 procedure Read_Lock
(L
: access Lock
; Ceiling_Violation
: out Boolean) is
361 Write_Lock
(L
, Ceiling_Violation
);
368 procedure Unlock
(L
: access Lock
) is
369 Result
: Interfaces
.C
.int
;
371 Result
:= pthread_mutex_unlock
(L
.L
'Access);
372 pragma Assert
(Result
= 0);
375 procedure Unlock
(L
: access RTS_Lock
; Global_Lock
: Boolean := False) is
376 Result
: Interfaces
.C
.int
;
378 if not Single_Lock
or else Global_Lock
then
379 Result
:= pthread_mutex_unlock
(L
);
380 pragma Assert
(Result
= 0);
384 procedure Unlock
(T
: Task_Id
) is
385 Result
: Interfaces
.C
.int
;
387 if not Single_Lock
then
388 Result
:= pthread_mutex_unlock
(T
.Common
.LL
.L
'Access);
389 pragma Assert
(Result
= 0);
399 Reason
: System
.Tasking
.Task_States
)
401 pragma Unreferenced
(Reason
);
403 Result
: Interfaces
.C
.int
;
406 Result
:= pthread_cond_wait
407 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access);
409 Result
:= pthread_cond_wait
410 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access);
413 -- EINTR is not considered a failure
415 pragma Assert
(Result
= 0 or else Result
= EINTR
);
422 procedure Timed_Sleep
425 Mode
: ST
.Delay_Modes
;
426 Reason
: System
.Tasking
.Task_States
;
427 Timedout
: out Boolean;
428 Yielded
: out Boolean)
430 pragma Unreferenced
(Reason
);
432 Check_Time
: constant Duration := Monotonic_Clock
;
434 Request
: aliased timespec
;
435 Result
: Interfaces
.C
.int
;
441 if Mode
= Relative
then
442 Abs_Time
:= Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
;
444 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
447 if Abs_Time
> Check_Time
then
448 Request
:= To_Timespec
(Abs_Time
);
451 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
452 or else Self_ID
.Pending_Priority_Change
;
455 Result
:= pthread_cond_timedwait
456 (Self_ID
.Common
.LL
.CV
'Access, Single_RTS_Lock
'Access,
460 Result
:= pthread_cond_timedwait
461 (Self_ID
.Common
.LL
.CV
'Access, Self_ID
.Common
.LL
.L
'Access,
465 exit when Abs_Time
<= Monotonic_Clock
;
467 if Result
= 0 or Result
= EINTR
then
469 -- Somebody may have called Wakeup for us
475 pragma Assert
(Result
= ETIMEDOUT
);
484 procedure Timed_Delay
487 Mode
: ST
.Delay_Modes
)
489 Check_Time
: constant Duration := Monotonic_Clock
;
491 Request
: aliased timespec
;
492 Result
: Interfaces
.C
.int
;
499 Write_Lock
(Self_ID
);
501 if Mode
= Relative
then
502 Abs_Time
:= Time
+ Check_Time
;
504 Abs_Time
:= Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
);
507 if Abs_Time
> Check_Time
then
508 Request
:= To_Timespec
(Abs_Time
);
509 Self_ID
.Common
.State
:= Delay_Sleep
;
512 if Self_ID
.Pending_Priority_Change
then
513 Self_ID
.Pending_Priority_Change
:= False;
514 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
515 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
518 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
521 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
522 Single_RTS_Lock
'Access, Request
'Access);
524 Result
:= pthread_cond_timedwait
(Self_ID
.Common
.LL
.CV
'Access,
525 Self_ID
.Common
.LL
.L
'Access, Request
'Access);
528 exit when Abs_Time
<= Monotonic_Clock
;
530 pragma Assert
(Result
= 0 or else
531 Result
= ETIMEDOUT
or else
535 Self_ID
.Common
.State
:= Runnable
;
544 Result
:= sched_yield
;
547 ---------------------
548 -- Monotonic_Clock --
549 ---------------------
551 function Monotonic_Clock
return Duration is
552 TS
: aliased timespec
;
553 Result
: Interfaces
.C
.int
;
555 Result
:= Clock_Gettime
(CLOCK_REALTIME
, TS
'Unchecked_Access);
556 pragma Assert
(Result
= 0);
557 return To_Duration
(TS
);
564 function RT_Resolution
return Duration is
573 procedure Wakeup
(T
: Task_Id
; Reason
: System
.Tasking
.Task_States
) is
574 pragma Unreferenced
(Reason
);
576 Result
: Interfaces
.C
.int
;
579 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
580 pragma Assert
(Result
= 0);
587 procedure Yield
(Do_Yield
: Boolean := True) is
588 Result
: Interfaces
.C
.int
;
589 pragma Unreferenced
(Result
);
592 Result
:= sched_yield
;
600 type Prio_Array_Type
is array (System
.Any_Priority
) of Integer;
601 pragma Atomic_Components
(Prio_Array_Type
);
603 Prio_Array
: Prio_Array_Type
;
604 -- Global array containing the id of the currently running task for
607 -- Note: we assume that we are on a single processor with run-til-blocked
610 procedure Set_Priority
612 Prio
: System
.Any_Priority
;
613 Loss_Of_Inheritance
: Boolean := False)
615 Result
: Interfaces
.C
.int
;
616 Array_Item
: Integer;
617 Param
: aliased struct_sched_param
;
620 Param
.sched_priority
:= Interfaces
.C
.int
(Underlying_Priorities
(Prio
));
622 if Time_Slice_Val
> 0 then
623 Result
:= pthread_setschedparam
624 (T
.Common
.LL
.Thread
, SCHED_RR
, Param
'Access);
626 elsif Dispatching_Policy
= 'F' or else Time_Slice_Val
= 0 then
627 Result
:= pthread_setschedparam
628 (T
.Common
.LL
.Thread
, SCHED_FIFO
, Param
'Access);
631 Result
:= pthread_setschedparam
632 (T
.Common
.LL
.Thread
, SCHED_OTHER
, Param
'Access);
635 pragma Assert
(Result
= 0);
637 if Dispatching_Policy
= 'F' then
639 -- Annex D requirement [RM D.2.2 par. 9]:
640 -- If the task drops its priority due to the loss of inherited
641 -- priority, it is added at the head of the ready queue for its
642 -- new active priority.
644 if Loss_Of_Inheritance
645 and then Prio
< T
.Common
.Current_Priority
647 Array_Item
:= Prio_Array
(T
.Common
.Base_Priority
) + 1;
648 Prio_Array
(T
.Common
.Base_Priority
) := Array_Item
;
651 -- Let some processes a chance to arrive
655 -- Then wait for our turn to proceed
657 exit when Array_Item
= Prio_Array
(T
.Common
.Base_Priority
)
658 or else Prio_Array
(T
.Common
.Base_Priority
) = 1;
661 Prio_Array
(T
.Common
.Base_Priority
) :=
662 Prio_Array
(T
.Common
.Base_Priority
) - 1;
666 T
.Common
.Current_Priority
:= Prio
;
673 function Get_Priority
(T
: Task_Id
) return System
.Any_Priority
is
675 return T
.Common
.Current_Priority
;
682 procedure Enter_Task
(Self_ID
: Task_Id
) is
684 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
685 Specific
.Set
(Self_ID
);
689 for J
in Known_Tasks
'Range loop
690 if Known_Tasks
(J
) = null then
691 Known_Tasks
(J
) := Self_ID
;
692 Self_ID
.Known_Tasks_Index
:= J
;
704 function New_ATCB
(Entry_Num
: Task_Entry_Index
) return Task_Id
is
706 return new Ada_Task_Control_Block
(Entry_Num
);
713 function Is_Valid_Task
return Boolean renames Specific
.Is_Valid_Task
;
715 -----------------------------
716 -- Register_Foreign_Thread --
717 -----------------------------
719 function Register_Foreign_Thread
return Task_Id
is
721 if Is_Valid_Task
then
724 return Register_Foreign_Thread
(pthread_self
);
726 end Register_Foreign_Thread
;
732 procedure Initialize_TCB
(Self_ID
: Task_Id
; Succeeded
: out Boolean) is
733 Mutex_Attr
: aliased pthread_mutexattr_t
;
734 Result
: Interfaces
.C
.int
;
735 Cond_Attr
: aliased pthread_condattr_t
;
738 if not Single_Lock
then
739 Result
:= pthread_mutexattr_init
(Mutex_Attr
'Access);
740 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
743 Result
:= pthread_mutex_init
(Self_ID
.Common
.LL
.L
'Access,
745 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
753 Result
:= pthread_mutexattr_destroy
(Mutex_Attr
'Access);
754 pragma Assert
(Result
= 0);
757 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
758 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
761 Result
:= pthread_cond_init
(Self_ID
.Common
.LL
.CV
'Access,
763 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
769 if not Single_Lock
then
770 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
771 pragma Assert
(Result
= 0);
777 Result
:= pthread_condattr_destroy
(Cond_Attr
'Access);
778 pragma Assert
(Result
= 0);
785 procedure Create_Task
787 Wrapper
: System
.Address
;
788 Stack_Size
: System
.Parameters
.Size_Type
;
789 Priority
: System
.Any_Priority
;
790 Succeeded
: out Boolean)
792 Attributes
: aliased pthread_attr_t
;
793 Result
: Interfaces
.C
.int
;
795 function Thread_Body_Access
is new
796 Unchecked_Conversion
(System
.Address
, Thread_Body
);
799 Result
:= pthread_attr_init
(Attributes
'Access);
800 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
807 Result
:= pthread_attr_setstacksize
808 (Attributes
'Access, Interfaces
.C
.size_t
(Stack_Size
));
809 pragma Assert
(Result
= 0);
811 -- Since the initial signal mask of a thread is inherited from the
812 -- creator, and the Environment task has all its signals masked, we
813 -- do not need to manipulate caller's signal mask at this point.
814 -- All tasks in RTS will have All_Tasks_Mask initially.
816 Result
:= pthread_create
817 (T
.Common
.LL
.Thread
'Access,
819 Thread_Body_Access
(Wrapper
),
821 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
823 Succeeded
:= Result
= 0;
825 pthread_detach
(T
.Common
.LL
.Thread
'Access);
826 -- Detach the thread using pthread_detach, sinc DCE threads do not have
827 -- pthread_attr_set_detachstate.
829 Result
:= pthread_attr_destroy
(Attributes
'Access);
830 pragma Assert
(Result
= 0);
832 Set_Priority
(T
, Priority
);
839 procedure Finalize_TCB
(T
: Task_Id
) is
840 Result
: Interfaces
.C
.int
;
842 Is_Self
: constant Boolean := T
= Self
;
844 procedure Free
is new
845 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_Id
);
848 if not Single_Lock
then
849 Result
:= pthread_mutex_destroy
(T
.Common
.LL
.L
'Access);
850 pragma Assert
(Result
= 0);
853 Result
:= pthread_cond_destroy
(T
.Common
.LL
.CV
'Access);
854 pragma Assert
(Result
= 0);
856 if T
.Known_Tasks_Index
/= -1 then
857 Known_Tasks
(T
.Known_Tasks_Index
) := null;
871 procedure Exit_Task
is
880 procedure Abort_Task
(T
: Task_Id
) is
883 -- Interrupt Server_Tasks may be waiting on an "event" flag (signal)
885 if T
.Common
.State
= Interrupt_Server_Blocked_On_Event_Flag
then
886 System
.Interrupt_Management
.Operations
.Interrupt_Self_Process
887 (System
.Interrupt_Management
.Interrupt_ID
888 (PIO
.Get_Interrupt_ID
(T
)));
896 procedure Initialize
(S
: in out Suspension_Object
) is
897 Mutex_Attr
: aliased pthread_mutexattr_t
;
898 Cond_Attr
: aliased pthread_condattr_t
;
899 Result
: Interfaces
.C
.int
;
901 -- Initialize internal state. It is always initialized to False (ARM
907 -- Initialize internal mutex
909 Result
:= pthread_mutex_init
(S
.L
'Access, Mutex_Attr
'Access);
910 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
912 if Result
= ENOMEM
then
916 -- Initialize internal condition variable
918 Result
:= pthread_cond_init
(S
.CV
'Access, Cond_Attr
'Access);
919 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
922 Result
:= pthread_mutex_destroy
(S
.L
'Access);
923 pragma Assert
(Result
= 0);
925 if Result
= ENOMEM
then
935 procedure Finalize
(S
: in out Suspension_Object
) is
936 Result
: Interfaces
.C
.int
;
938 -- Destroy internal mutex
940 Result
:= pthread_mutex_destroy
(S
.L
'Access);
941 pragma Assert
(Result
= 0);
943 -- Destroy internal condition variable
945 Result
:= pthread_cond_destroy
(S
.CV
'Access);
946 pragma Assert
(Result
= 0);
953 function Current_State
(S
: Suspension_Object
) return Boolean is
955 -- We do not want to use lock on this read operation. State is marked
956 -- as Atomic so that we ensure that the value retrieved is correct.
965 procedure Set_False
(S
: in out Suspension_Object
) is
966 Result
: Interfaces
.C
.int
;
970 Result
:= pthread_mutex_lock
(S
.L
'Access);
971 pragma Assert
(Result
= 0);
975 Result
:= pthread_mutex_unlock
(S
.L
'Access);
976 pragma Assert
(Result
= 0);
978 SSL
.Abort_Undefer
.all;
985 procedure Set_True
(S
: in out Suspension_Object
) is
986 Result
: Interfaces
.C
.int
;
990 Result
:= pthread_mutex_lock
(S
.L
'Access);
991 pragma Assert
(Result
= 0);
993 -- If there is already a task waiting on this suspension object then
994 -- we resume it, leaving the state of the suspension object to False,
995 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
996 -- the state to True.
1002 Result
:= pthread_cond_signal
(S
.CV
'Access);
1003 pragma Assert
(Result
= 0);
1008 Result
:= pthread_mutex_unlock
(S
.L
'Access);
1009 pragma Assert
(Result
= 0);
1011 SSL
.Abort_Undefer
.all;
1014 ------------------------
1015 -- Suspend_Until_True --
1016 ------------------------
1018 procedure Suspend_Until_True
(S
: in out Suspension_Object
) is
1019 Result
: Interfaces
.C
.int
;
1021 SSL
.Abort_Defer
.all;
1023 Result
:= pthread_mutex_lock
(S
.L
'Access);
1024 pragma Assert
(Result
= 0);
1027 -- Program_Error must be raised upon calling Suspend_Until_True
1028 -- if another task is already waiting on that suspension object
1029 -- (ARM D.10 par. 10).
1031 Result
:= pthread_mutex_unlock
(S
.L
'Access);
1032 pragma Assert
(Result
= 0);
1034 SSL
.Abort_Undefer
.all;
1036 raise Program_Error
;
1038 -- Suspend the task if the state is False. Otherwise, the task
1039 -- continues its execution, and the state of the suspension object
1040 -- is set to False (ARM D.10 par. 9).
1046 Result
:= pthread_cond_wait
(S
.CV
'Access, S
.L
'Access);
1049 Result
:= pthread_mutex_unlock
(S
.L
'Access);
1050 pragma Assert
(Result
= 0);
1052 SSL
.Abort_Undefer
.all;
1054 end Suspend_Until_True
;
1062 function Check_Exit
(Self_ID
: ST
.Task_Id
) return Boolean is
1063 pragma Unreferenced
(Self_ID
);
1068 --------------------
1069 -- Check_No_Locks --
1070 --------------------
1072 function Check_No_Locks
(Self_ID
: ST
.Task_Id
) return Boolean is
1073 pragma Unreferenced
(Self_ID
);
1078 ----------------------
1079 -- Environment_Task --
1080 ----------------------
1082 function Environment_Task
return Task_Id
is
1084 return Environment_Task_Id
;
1085 end Environment_Task
;
1091 procedure Lock_RTS
is
1093 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1100 procedure Unlock_RTS
is
1102 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1109 function Suspend_Task
1111 Thread_Self
: Thread_Id
) return Boolean
1113 pragma Unreferenced
(T
);
1114 pragma Unreferenced
(Thread_Self
);
1123 function Resume_Task
1125 Thread_Self
: Thread_Id
) return Boolean
1127 pragma Unreferenced
(T
);
1128 pragma Unreferenced
(Thread_Self
);
1137 procedure Initialize
(Environment_Task
: Task_Id
) is
1138 act
: aliased struct_sigaction
;
1139 old_act
: aliased struct_sigaction
;
1140 Tmp_Set
: aliased sigset_t
;
1141 Result
: Interfaces
.C
.int
;
1144 (Int
: System
.Interrupt_Management
.Interrupt_ID
) return Character;
1145 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
1146 -- Get interrupt state. Defined in a-init.c. The input argument is
1147 -- the interrupt number, and the result is one of the following:
1149 Default
: constant Character := 's';
1150 -- 'n' this interrupt not set by any Interrupt_State pragma
1151 -- 'u' Interrupt_State pragma set state to User
1152 -- 'r' Interrupt_State pragma set state to Runtime
1153 -- 's' Interrupt_State pragma set state to System (use "default"
1157 Environment_Task_Id
:= Environment_Task
;
1159 Interrupt_Management
.Initialize
;
1161 -- Initialize the lock used to synchronize chain of all ATCBs
1163 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
1165 Specific
.Initialize
(Environment_Task
);
1167 Enter_Task
(Environment_Task
);
1169 -- Install the abort-signal handler
1171 if State
(System
.Interrupt_Management
.Abort_Task_Interrupt
)
1175 act
.sa_handler
:= Abort_Handler
'Address;
1177 Result
:= sigemptyset
(Tmp_Set
'Access);
1178 pragma Assert
(Result
= 0);
1179 act
.sa_mask
:= Tmp_Set
;
1183 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
),
1184 act
'Unchecked_Access,
1185 old_act
'Unchecked_Access);
1186 pragma Assert
(Result
= 0);
1190 -- NOTE: Unlike other pthread implementations, we do *not* mask all
1191 -- signals here since we handle signals using the process-wide primitive
1192 -- signal, rather than using sigthreadmask and sigwait. The reason of
1193 -- this difference is that sigwait doesn't work when some critical
1194 -- signals (SIGABRT, SIGPIPE) are masked.
1196 end System
.Task_Primitives
.Operations
;