1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME COMPONENTS --
5 -- A D A . S Y N C H R O N O U S _ T A S K _ C O N T R O L --
9 -- Copyright (C) 1992-2004 Free Software Foundation, Inc. --
11 -- GNAT 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. 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. 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 GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
36 package body Ada
.Synchronous_Task_Control
is
37 use System
.OS_Interface
;
38 use type Interfaces
.C
.int
;
44 function Current_State
(S
: Suspension_Object
) return Boolean is
46 Result
: Boolean := False;
49 -- Determine state by attempting to take the semaphore with
50 -- a 0 timeout value. Status = OK indicates the semaphore was
51 -- full, so reset it to the full state.
53 St
:= semTake
(S
.Sema
, NO_WAIT
);
55 -- If we took the semaphore, reset semaphore state to FULL
59 St
:= semGive
(S
.Sema
);
69 procedure Set_False
(S
: in out Suspension_Object
) is
73 -- Need to get the semaphore into the "empty" state.
74 -- On return, this task will have made the semaphore
75 -- empty (St = OK) or have left it empty.
77 St
:= semTake
(S
.Sema
, NO_WAIT
);
78 pragma Assert
(St
= OK
);
85 procedure Set_True
(S
: in out Suspension_Object
) is
87 pragma Unreferenced
(St
);
89 St
:= semGive
(S
.Sema
);
92 ------------------------
93 -- Suspend_Until_True --
94 ------------------------
96 procedure Suspend_Until_True
(S
: in out Suspension_Object
) is
100 -- Determine whether another task is pending on the suspension
101 -- object. Should never be called from an ISR. Therefore semTake can
102 -- be called on the mutex
104 St
:= semTake
(S
.Mutex
, NO_WAIT
);
108 -- Wait for suspension object
110 St
:= semTake
(S
.Sema
, WAIT_FOREVER
);
111 St
:= semGive
(S
.Mutex
);
114 -- Another task is pending on the suspension object
118 end Suspend_Until_True
;
124 procedure Initialize
(S
: in out Suspension_Object
) is
126 S
.Sema
:= semBCreate
(SEM_Q_FIFO
, SEM_EMPTY
);
128 -- Use simpler binary semaphore instead of VxWorks
129 -- mutual exclusion semaphore, because we don't need
130 -- the fancier semantics and their overhead.
132 S
.Mutex
:= semBCreate
(SEM_Q_FIFO
, SEM_FULL
);
139 procedure Finalize
(S
: in out Suspension_Object
) is
141 pragma Unreferenced
(St
);
143 St
:= semDelete
(S
.Sema
);
144 St
:= semDelete
(S
.Mutex
);
147 end Ada
.Synchronous_Task_Control
;