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-2011, 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 3, or (at your option) any later ver- --
14 -- sion. GNAT 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 -- This is a HP-UX DCE threads (HPUX 10) version of this package
34 -- This package contains all the GNULL primitives that interface directly with
38 -- Turn off polling, we do not want ATC polling to take place during tasking
39 -- operations. It causes infinite loops and other problems.
41 with Ada
.Unchecked_Conversion
;
45 with System
.Tasking
.Debug
;
46 with System
.Interrupt_Management
;
47 with System
.OS_Constants
;
48 with System
.OS_Primitives
;
49 with System
.Task_Primitives
.Interrupt_Operations
;
51 pragma Warnings
(Off
);
52 with System
.Interrupt_Management
.Operations
;
53 pragma Elaborate_All
(System
.Interrupt_Management
.Operations
);
56 with System
.Soft_Links
;
57 -- We use System.Soft_Links instead of System.Tasking.Initialization
58 -- because the later is a higher level package that we shouldn't depend on.
59 -- For example when using the restricted run time, it is replaced by
60 -- System.Tasking.Restricted.Stages.
62 package body System
.Task_Primitives
.Operations
is
64 package OSC
renames System
.OS_Constants
;
65 package SSL
renames System
.Soft_Links
;
67 use System
.Tasking
.Debug
;
70 use System
.OS_Interface
;
71 use System
.Parameters
;
72 use System
.OS_Primitives
;
74 package PIO
renames System
.Task_Primitives
.Interrupt_Operations
;
80 -- The followings are logically constants, but need to be initialized
83 Single_RTS_Lock
: aliased RTS_Lock
;
84 -- This is a lock to allow only one thread of control in the RTS at
85 -- a time; it is used to execute in mutual exclusion from all other tasks.
86 -- Used mainly in Single_Lock mode, but also to protect All_Tasks_List
88 Environment_Task_Id
: Task_Id
;
89 -- A variable to hold Task_Id for the environment task
91 Unblocked_Signal_Mask
: aliased sigset_t
;
92 -- The set of signals that should unblocked in all tasks
94 Time_Slice_Val
: Integer;
95 pragma Import
(C
, Time_Slice_Val
, "__gl_time_slice_val");
97 Dispatching_Policy
: Character;
98 pragma Import
(C
, Dispatching_Policy
, "__gl_task_dispatching_policy");
100 -- Note: the reason that Locking_Policy is not needed is that this
101 -- is not implemented for DCE threads. The HPUX 10 port is at this
102 -- stage considered dead, and no further work is planned on it.
104 Foreign_Task_Elaborated
: aliased Boolean := True;
105 -- Used to identified fake tasks (i.e., non-Ada Threads)
113 procedure Initialize
(Environment_Task
: Task_Id
);
114 pragma Inline
(Initialize
);
115 -- Initialize various data needed by this package
117 function Is_Valid_Task
return Boolean;
118 pragma Inline
(Is_Valid_Task
);
119 -- Does the executing thread have a TCB?
121 procedure Set
(Self_Id
: Task_Id
);
123 -- Set the self id for the current task
125 function Self
return Task_Id
;
126 pragma Inline
(Self
);
127 -- Return a pointer to the Ada Task Control Block of the calling task
131 package body Specific
is separate;
132 -- The body of this package is target specific
134 ----------------------------------
135 -- ATCB allocation/deallocation --
136 ----------------------------------
138 package body ATCB_Allocation
is separate;
139 -- The body of this package is shared across several targets
141 ---------------------------------
142 -- Support for foreign threads --
143 ---------------------------------
145 function Register_Foreign_Thread
(Thread
: Thread_Id
) return Task_Id
;
146 -- Allocate and Initialize a new ATCB for the current Thread
148 function Register_Foreign_Thread
149 (Thread
: Thread_Id
) return Task_Id
is separate;
151 -----------------------
152 -- Local Subprograms --
153 -----------------------
155 procedure Abort_Handler
(Sig
: Signal
);
157 function To_Address
is
158 new Ada
.Unchecked_Conversion
(Task_Id
, System
.Address
);
164 procedure Abort_Handler
(Sig
: Signal
) is
165 pragma Unreferenced
(Sig
);
167 Self_Id
: constant Task_Id
:= Self
;
168 Result
: Interfaces
.C
.int
;
169 Old_Set
: aliased sigset_t
;
172 if Self_Id
.Deferral_Level
= 0
173 and then Self_Id
.Pending_ATC_Level
< Self_Id
.ATC_Nesting_Level
174 and then not Self_Id
.Aborting
176 Self_Id
.Aborting
:= True;
178 -- Make sure signals used for RTS internal purpose are unmasked
183 Unblocked_Signal_Mask
'Access,
185 pragma Assert
(Result
= 0);
187 raise Standard
'Abort_Signal;
195 -- The underlying thread system sets a guard page at the bottom of a thread
196 -- stack, so nothing is needed.
197 -- ??? Check the comment above
199 procedure Stack_Guard
(T
: ST
.Task_Id
; On
: Boolean) is
200 pragma Unreferenced
(T
, On
);
209 function Get_Thread_Id
(T
: ST
.Task_Id
) return OSI
.Thread_Id
is
211 return T
.Common
.LL
.Thread
;
218 function Self
return Task_Id
renames Specific
.Self
;
220 ---------------------
221 -- Initialize_Lock --
222 ---------------------
224 -- Note: mutexes and cond_variables needed per-task basis are initialized
225 -- in Initialize_TCB and the Storage_Error is handled. Other mutexes (such
226 -- as RTS_Lock, Memory_Lock...) used in RTS is initialized before any
227 -- status change of RTS. Therefore raising Storage_Error in the following
228 -- routines should be able to be handled safely.
230 procedure Initialize_Lock
231 (Prio
: System
.Any_Priority
;
232 L
: not null access Lock
)
234 Attributes
: aliased pthread_mutexattr_t
;
235 Result
: Interfaces
.C
.int
;
238 Result
:= pthread_mutexattr_init
(Attributes
'Access);
239 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
241 if Result
= ENOMEM
then
247 Result
:= pthread_mutex_init
(L
.L
'Access, Attributes
'Access);
248 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
250 if Result
= ENOMEM
then
254 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
255 pragma Assert
(Result
= 0);
258 procedure Initialize_Lock
259 (L
: not null access RTS_Lock
;
262 pragma Unreferenced
(Level
);
264 Attributes
: aliased pthread_mutexattr_t
;
265 Result
: Interfaces
.C
.int
;
268 Result
:= pthread_mutexattr_init
(Attributes
'Access);
269 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
271 if Result
= ENOMEM
then
275 Result
:= pthread_mutex_init
(L
, Attributes
'Access);
277 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
279 if Result
= ENOMEM
then
283 Result
:= pthread_mutexattr_destroy
(Attributes
'Access);
284 pragma Assert
(Result
= 0);
291 procedure Finalize_Lock
(L
: not null access Lock
) is
292 Result
: Interfaces
.C
.int
;
294 Result
:= pthread_mutex_destroy
(L
.L
'Access);
295 pragma Assert
(Result
= 0);
298 procedure Finalize_Lock
(L
: not null access RTS_Lock
) is
299 Result
: Interfaces
.C
.int
;
301 Result
:= pthread_mutex_destroy
(L
);
302 pragma Assert
(Result
= 0);
310 (L
: not null access Lock
;
311 Ceiling_Violation
: out Boolean)
313 Result
: Interfaces
.C
.int
;
316 L
.Owner_Priority
:= Get_Priority
(Self
);
318 if L
.Priority
< L
.Owner_Priority
then
319 Ceiling_Violation
:= True;
323 Result
:= pthread_mutex_lock
(L
.L
'Access);
324 pragma Assert
(Result
= 0);
325 Ceiling_Violation
:= False;
329 (L
: not null access RTS_Lock
;
330 Global_Lock
: Boolean := False)
332 Result
: Interfaces
.C
.int
;
334 if not Single_Lock
or else Global_Lock
then
335 Result
:= pthread_mutex_lock
(L
);
336 pragma Assert
(Result
= 0);
340 procedure Write_Lock
(T
: Task_Id
) is
341 Result
: Interfaces
.C
.int
;
343 if not Single_Lock
then
344 Result
:= pthread_mutex_lock
(T
.Common
.LL
.L
'Access);
345 pragma Assert
(Result
= 0);
354 (L
: not null access Lock
;
355 Ceiling_Violation
: out Boolean)
358 Write_Lock
(L
, Ceiling_Violation
);
365 procedure Unlock
(L
: not null access Lock
) is
366 Result
: Interfaces
.C
.int
;
368 Result
:= pthread_mutex_unlock
(L
.L
'Access);
369 pragma Assert
(Result
= 0);
373 (L
: not null access RTS_Lock
;
374 Global_Lock
: Boolean := False)
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);
397 -- Dynamic priority ceilings are not supported by the underlying system
399 procedure Set_Ceiling
400 (L
: not null access Lock
;
401 Prio
: System
.Any_Priority
)
403 pragma Unreferenced
(L
, Prio
);
414 Reason
: System
.Tasking
.Task_States
)
416 pragma Unreferenced
(Reason
);
418 Result
: Interfaces
.C
.int
;
423 (cond
=> Self_ID
.Common
.LL
.CV
'Access,
424 mutex
=> (if Single_Lock
425 then Single_RTS_Lock
'Access
426 else Self_ID
.Common
.LL
.L
'Access));
428 -- EINTR is not considered a failure
430 pragma Assert
(Result
= 0 or else Result
= EINTR
);
437 procedure Timed_Sleep
440 Mode
: ST
.Delay_Modes
;
441 Reason
: System
.Tasking
.Task_States
;
442 Timedout
: out Boolean;
443 Yielded
: out Boolean)
445 pragma Unreferenced
(Reason
);
447 Check_Time
: constant Duration := Monotonic_Clock
;
449 Request
: aliased timespec
;
450 Result
: Interfaces
.C
.int
;
458 then Duration'Min (Time
, Max_Sensible_Delay
) + Check_Time
459 else Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
));
461 if Abs_Time
> Check_Time
then
462 Request
:= To_Timespec
(Abs_Time
);
465 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
468 pthread_cond_timedwait
469 (cond
=> Self_ID
.Common
.LL
.CV
'Access,
470 mutex
=> (if Single_Lock
471 then Single_RTS_Lock
'Access
472 else Self_ID
.Common
.LL
.L
'Access),
473 abstime
=> Request
'Access);
475 exit when Abs_Time
<= Monotonic_Clock
;
477 if Result
= 0 or Result
= EINTR
then
479 -- Somebody may have called Wakeup for us
485 pragma Assert
(Result
= ETIMEDOUT
);
494 procedure Timed_Delay
497 Mode
: ST
.Delay_Modes
)
499 Check_Time
: constant Duration := Monotonic_Clock
;
501 Request
: aliased timespec
;
503 Result
: Interfaces
.C
.int
;
504 pragma Warnings
(Off
, Result
);
511 Write_Lock
(Self_ID
);
515 then Time
+ Check_Time
516 else Duration'Min (Check_Time
+ Max_Sensible_Delay
, Time
));
518 if Abs_Time
> Check_Time
then
519 Request
:= To_Timespec
(Abs_Time
);
520 Self_ID
.Common
.State
:= Delay_Sleep
;
523 exit when Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
;
526 pthread_cond_timedwait
527 (cond
=> Self_ID
.Common
.LL
.CV
'Access,
528 mutex
=> (if Single_Lock
529 then Single_RTS_Lock
'Access
530 else Self_ID
.Common
.LL
.L
'Access),
531 abstime
=> Request
'Access);
533 exit when Abs_Time
<= Monotonic_Clock
;
535 pragma Assert
(Result
= 0 or else
536 Result
= ETIMEDOUT
or else
540 Self_ID
.Common
.State
:= Runnable
;
549 Result
:= sched_yield
;
552 ---------------------
553 -- Monotonic_Clock --
554 ---------------------
556 function Monotonic_Clock
return Duration is
557 TS
: aliased timespec
;
558 Result
: Interfaces
.C
.int
;
560 Result
:= Clock_Gettime
(OSC
.CLOCK_RT_Ada
, TS
'Unchecked_Access);
561 pragma Assert
(Result
= 0);
562 return To_Duration
(TS
);
569 function RT_Resolution
return Duration is
578 procedure Wakeup
(T
: Task_Id
; Reason
: System
.Tasking
.Task_States
) is
579 pragma Unreferenced
(Reason
);
580 Result
: Interfaces
.C
.int
;
582 Result
:= pthread_cond_signal
(T
.Common
.LL
.CV
'Access);
583 pragma Assert
(Result
= 0);
590 procedure Yield
(Do_Yield
: Boolean := True) is
591 Result
: Interfaces
.C
.int
;
592 pragma Unreferenced
(Result
);
595 Result
:= sched_yield
;
603 type Prio_Array_Type
is array (System
.Any_Priority
) of Integer;
604 pragma Atomic_Components
(Prio_Array_Type
);
606 Prio_Array
: Prio_Array_Type
;
607 -- Global array containing the id of the currently running task for
610 -- Note: assume we are on single processor with run-til-blocked scheduling
612 procedure Set_Priority
614 Prio
: System
.Any_Priority
;
615 Loss_Of_Inheritance
: Boolean := False)
617 Result
: Interfaces
.C
.int
;
618 Array_Item
: Integer;
619 Param
: aliased struct_sched_param
;
621 function Get_Policy
(Prio
: System
.Any_Priority
) return Character;
622 pragma Import
(C
, Get_Policy
, "__gnat_get_specific_dispatching");
623 -- Get priority specific dispatching policy
625 Priority_Specific_Policy
: constant Character := Get_Policy
(Prio
);
626 -- Upper case first character of the policy name corresponding to the
627 -- task as set by a Priority_Specific_Dispatching pragma.
630 Param
.sched_priority
:= Interfaces
.C
.int
(Underlying_Priorities
(Prio
));
632 if Dispatching_Policy
= 'R'
633 or else Priority_Specific_Policy
= 'R'
634 or else Time_Slice_Val
> 0
637 pthread_setschedparam
638 (T
.Common
.LL
.Thread
, SCHED_RR
, Param
'Access);
640 elsif Dispatching_Policy
= 'F'
641 or else Priority_Specific_Policy
= 'F'
642 or else Time_Slice_Val
= 0
645 pthread_setschedparam
646 (T
.Common
.LL
.Thread
, SCHED_FIFO
, Param
'Access);
650 pthread_setschedparam
651 (T
.Common
.LL
.Thread
, SCHED_OTHER
, Param
'Access);
654 pragma Assert
(Result
= 0);
656 if Dispatching_Policy
= 'F' or else Priority_Specific_Policy
= 'F' then
658 -- Annex D requirement [RM D.2.2 par. 9]:
659 -- If the task drops its priority due to the loss of inherited
660 -- priority, it is added at the head of the ready queue for its
661 -- new active priority.
663 if Loss_Of_Inheritance
664 and then Prio
< T
.Common
.Current_Priority
666 Array_Item
:= Prio_Array
(T
.Common
.Base_Priority
) + 1;
667 Prio_Array
(T
.Common
.Base_Priority
) := Array_Item
;
670 -- Let some processes a chance to arrive
674 -- Then wait for our turn to proceed
676 exit when Array_Item
= Prio_Array
(T
.Common
.Base_Priority
)
677 or else Prio_Array
(T
.Common
.Base_Priority
) = 1;
680 Prio_Array
(T
.Common
.Base_Priority
) :=
681 Prio_Array
(T
.Common
.Base_Priority
) - 1;
685 T
.Common
.Current_Priority
:= Prio
;
692 function Get_Priority
(T
: Task_Id
) return System
.Any_Priority
is
694 return T
.Common
.Current_Priority
;
701 procedure Enter_Task
(Self_ID
: Task_Id
) is
703 Self_ID
.Common
.LL
.Thread
:= pthread_self
;
704 Specific
.Set
(Self_ID
);
711 function Is_Valid_Task
return Boolean renames Specific
.Is_Valid_Task
;
713 -----------------------------
714 -- Register_Foreign_Thread --
715 -----------------------------
717 function Register_Foreign_Thread
return Task_Id
is
719 if Is_Valid_Task
then
722 return Register_Foreign_Thread
(pthread_self
);
724 end Register_Foreign_Thread
;
730 procedure Initialize_TCB
(Self_ID
: Task_Id
; Succeeded
: out Boolean) is
731 Mutex_Attr
: aliased pthread_mutexattr_t
;
732 Result
: Interfaces
.C
.int
;
733 Cond_Attr
: aliased pthread_condattr_t
;
736 if not Single_Lock
then
737 Result
:= pthread_mutexattr_init
(Mutex_Attr
'Access);
738 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
743 (Self_ID
.Common
.LL
.L
'Access, Mutex_Attr
'Access);
744 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
752 Result
:= pthread_mutexattr_destroy
(Mutex_Attr
'Access);
753 pragma Assert
(Result
= 0);
756 Result
:= pthread_condattr_init
(Cond_Attr
'Access);
757 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
762 (Self_ID
.Common
.LL
.CV
'Access,
764 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
770 if not Single_Lock
then
771 Result
:= pthread_mutex_destroy
(Self_ID
.Common
.LL
.L
'Access);
772 pragma Assert
(Result
= 0);
778 Result
:= pthread_condattr_destroy
(Cond_Attr
'Access);
779 pragma Assert
(Result
= 0);
786 procedure Create_Task
788 Wrapper
: System
.Address
;
789 Stack_Size
: System
.Parameters
.Size_Type
;
790 Priority
: System
.Any_Priority
;
791 Succeeded
: out Boolean)
793 Attributes
: aliased pthread_attr_t
;
794 Result
: Interfaces
.C
.int
;
796 function Thread_Body_Access
is new
797 Ada
.Unchecked_Conversion
(System
.Address
, Thread_Body
);
800 Result
:= pthread_attr_init
(Attributes
'Access);
801 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
808 Result
:= pthread_attr_setstacksize
809 (Attributes
'Access, Interfaces
.C
.size_t
(Stack_Size
));
810 pragma Assert
(Result
= 0);
812 -- Since the initial signal mask of a thread is inherited from the
813 -- creator, and the Environment task has all its signals masked, we
814 -- do not need to manipulate caller's signal mask at this point.
815 -- All tasks in RTS will have All_Tasks_Mask initially.
817 Result
:= pthread_create
818 (T
.Common
.LL
.Thread
'Access,
820 Thread_Body_Access
(Wrapper
),
822 pragma Assert
(Result
= 0 or else Result
= EAGAIN
);
824 Succeeded
:= Result
= 0;
826 pthread_detach
(T
.Common
.LL
.Thread
'Access);
827 -- Detach the thread using pthread_detach, since DCE threads do not have
828 -- pthread_attr_set_detachstate.
830 Result
:= pthread_attr_destroy
(Attributes
'Access);
831 pragma Assert
(Result
= 0);
833 Set_Priority
(T
, Priority
);
840 procedure Finalize_TCB
(T
: Task_Id
) is
841 Result
: Interfaces
.C
.int
;
844 if not Single_Lock
then
845 Result
:= pthread_mutex_destroy
(T
.Common
.LL
.L
'Access);
846 pragma Assert
(Result
= 0);
849 Result
:= pthread_cond_destroy
(T
.Common
.LL
.CV
'Access);
850 pragma Assert
(Result
= 0);
852 if T
.Known_Tasks_Index
/= -1 then
853 Known_Tasks
(T
.Known_Tasks_Index
) := null;
856 ATCB_Allocation
.Free_ATCB
(T
);
863 procedure Exit_Task
is
872 procedure Abort_Task
(T
: Task_Id
) is
874 -- Interrupt Server_Tasks may be waiting on an "event" flag (signal)
876 if T
.Common
.State
= Interrupt_Server_Blocked_On_Event_Flag
then
877 System
.Interrupt_Management
.Operations
.Interrupt_Self_Process
878 (PIO
.Get_Interrupt_ID
(T
));
886 procedure Initialize
(S
: in out Suspension_Object
) is
887 Mutex_Attr
: aliased pthread_mutexattr_t
;
888 Cond_Attr
: aliased pthread_condattr_t
;
889 Result
: Interfaces
.C
.int
;
891 -- Initialize internal state (always to False (ARM D.10(6)))
896 -- Initialize internal mutex
898 Result
:= pthread_mutex_init
(S
.L
'Access, Mutex_Attr
'Access);
899 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
901 if Result
= ENOMEM
then
905 -- Initialize internal condition variable
907 Result
:= pthread_cond_init
(S
.CV
'Access, Cond_Attr
'Access);
908 pragma Assert
(Result
= 0 or else Result
= ENOMEM
);
911 Result
:= pthread_mutex_destroy
(S
.L
'Access);
912 pragma Assert
(Result
= 0);
914 if Result
= ENOMEM
then
924 procedure Finalize
(S
: in out Suspension_Object
) is
925 Result
: Interfaces
.C
.int
;
928 -- Destroy internal mutex
930 Result
:= pthread_mutex_destroy
(S
.L
'Access);
931 pragma Assert
(Result
= 0);
933 -- Destroy internal condition variable
935 Result
:= pthread_cond_destroy
(S
.CV
'Access);
936 pragma Assert
(Result
= 0);
943 function Current_State
(S
: Suspension_Object
) return Boolean is
945 -- We do not want to use lock on this read operation. State is marked
946 -- as Atomic so that we ensure that the value retrieved is correct.
955 procedure Set_False
(S
: in out Suspension_Object
) is
956 Result
: Interfaces
.C
.int
;
961 Result
:= pthread_mutex_lock
(S
.L
'Access);
962 pragma Assert
(Result
= 0);
966 Result
:= pthread_mutex_unlock
(S
.L
'Access);
967 pragma Assert
(Result
= 0);
969 SSL
.Abort_Undefer
.all;
976 procedure Set_True
(S
: in out Suspension_Object
) is
977 Result
: Interfaces
.C
.int
;
982 Result
:= pthread_mutex_lock
(S
.L
'Access);
983 pragma Assert
(Result
= 0);
985 -- If there is already a task waiting on this suspension object then
986 -- we resume it, leaving the state of the suspension object to False,
987 -- as it is specified in ARM D.10 par. 9. Otherwise, it just leaves
988 -- the state to True.
994 Result
:= pthread_cond_signal
(S
.CV
'Access);
995 pragma Assert
(Result
= 0);
1001 Result
:= pthread_mutex_unlock
(S
.L
'Access);
1002 pragma Assert
(Result
= 0);
1004 SSL
.Abort_Undefer
.all;
1007 ------------------------
1008 -- Suspend_Until_True --
1009 ------------------------
1011 procedure Suspend_Until_True
(S
: in out Suspension_Object
) is
1012 Result
: Interfaces
.C
.int
;
1015 SSL
.Abort_Defer
.all;
1017 Result
:= pthread_mutex_lock
(S
.L
'Access);
1018 pragma Assert
(Result
= 0);
1021 -- Program_Error must be raised upon calling Suspend_Until_True
1022 -- if another task is already waiting on that suspension object
1023 -- (ARM D.10 par. 10).
1025 Result
:= pthread_mutex_unlock
(S
.L
'Access);
1026 pragma Assert
(Result
= 0);
1028 SSL
.Abort_Undefer
.all;
1030 raise Program_Error
;
1032 -- Suspend the task if the state is False. Otherwise, the task
1033 -- continues its execution, and the state of the suspension object
1034 -- is set to False (ARM D.10 par. 9).
1042 -- Loop in case pthread_cond_wait returns earlier than expected
1043 -- (e.g. in case of EINTR caused by a signal).
1045 Result
:= pthread_cond_wait
(S
.CV
'Access, S
.L
'Access);
1046 pragma Assert
(Result
= 0 or else Result
= EINTR
);
1048 exit when not S
.Waiting
;
1052 Result
:= pthread_mutex_unlock
(S
.L
'Access);
1053 pragma Assert
(Result
= 0);
1055 SSL
.Abort_Undefer
.all;
1057 end Suspend_Until_True
;
1065 function Check_Exit
(Self_ID
: ST
.Task_Id
) return Boolean is
1066 pragma Unreferenced
(Self_ID
);
1071 --------------------
1072 -- Check_No_Locks --
1073 --------------------
1075 function Check_No_Locks
(Self_ID
: ST
.Task_Id
) return Boolean is
1076 pragma Unreferenced
(Self_ID
);
1081 ----------------------
1082 -- Environment_Task --
1083 ----------------------
1085 function Environment_Task
return Task_Id
is
1087 return Environment_Task_Id
;
1088 end Environment_Task
;
1094 procedure Lock_RTS
is
1096 Write_Lock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1103 procedure Unlock_RTS
is
1105 Unlock
(Single_RTS_Lock
'Access, Global_Lock
=> True);
1112 function Suspend_Task
1114 Thread_Self
: Thread_Id
) return Boolean
1116 pragma Unreferenced
(T
);
1117 pragma Unreferenced
(Thread_Self
);
1126 function Resume_Task
1128 Thread_Self
: Thread_Id
) return Boolean
1130 pragma Unreferenced
(T
);
1131 pragma Unreferenced
(Thread_Self
);
1136 --------------------
1137 -- Stop_All_Tasks --
1138 --------------------
1140 procedure Stop_All_Tasks
is
1149 function Stop_Task
(T
: ST
.Task_Id
) return Boolean is
1150 pragma Unreferenced
(T
);
1159 function Continue_Task
(T
: ST
.Task_Id
) return Boolean is
1160 pragma Unreferenced
(T
);
1169 procedure Initialize
(Environment_Task
: Task_Id
) is
1170 act
: aliased struct_sigaction
;
1171 old_act
: aliased struct_sigaction
;
1172 Tmp_Set
: aliased sigset_t
;
1173 Result
: Interfaces
.C
.int
;
1176 (Int
: System
.Interrupt_Management
.Interrupt_ID
) return Character;
1177 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
1178 -- Get interrupt state. Defined in a-init.c. The input argument is
1179 -- the interrupt number, and the result is one of the following:
1181 Default
: constant Character := 's';
1182 -- 'n' this interrupt not set by any Interrupt_State pragma
1183 -- 'u' Interrupt_State pragma set state to User
1184 -- 'r' Interrupt_State pragma set state to Runtime
1185 -- 's' Interrupt_State pragma set state to System (use "default"
1189 Environment_Task_Id
:= Environment_Task
;
1191 Interrupt_Management
.Initialize
;
1193 -- Initialize the lock used to synchronize chain of all ATCBs
1195 Initialize_Lock
(Single_RTS_Lock
'Access, RTS_Lock_Level
);
1197 Specific
.Initialize
(Environment_Task
);
1199 -- Make environment task known here because it doesn't go through
1200 -- Activate_Tasks, which does it for all other tasks.
1202 Known_Tasks
(Known_Tasks
'First) := Environment_Task
;
1203 Environment_Task
.Known_Tasks_Index
:= Known_Tasks
'First;
1205 Enter_Task
(Environment_Task
);
1207 -- Install the abort-signal handler
1209 if State
(System
.Interrupt_Management
.Abort_Task_Interrupt
)
1213 act
.sa_handler
:= Abort_Handler
'Address;
1215 Result
:= sigemptyset
(Tmp_Set
'Access);
1216 pragma Assert
(Result
= 0);
1217 act
.sa_mask
:= Tmp_Set
;
1221 Signal
(System
.Interrupt_Management
.Abort_Task_Interrupt
),
1222 act
'Unchecked_Access,
1223 old_act
'Unchecked_Access);
1224 pragma Assert
(Result
= 0);
1228 -- NOTE: Unlike other pthread implementations, we do *not* mask all
1229 -- signals here since we handle signals using the process-wide primitive
1230 -- signal, rather than using sigthreadmask and sigwait. The reason of
1231 -- this difference is that sigwait doesn't work when some critical
1232 -- signals (SIGABRT, SIGPIPE) are masked.
1234 -----------------------
1235 -- Set_Task_Affinity --
1236 -----------------------
1238 procedure Set_Task_Affinity
(T
: ST
.Task_Id
) is
1239 pragma Unreferenced
(T
);
1242 -- Setting task affinity is not supported by the underlying system
1245 end Set_Task_Affinity
;
1247 end System
.Task_Primitives
.Operations
;