1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . G L O B A L _ L O C K S --
9 -- Copyright (C) 1999-2010, AdaCore --
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 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 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This implementation is specific to NT
34 with System
.OS_Interface
;
35 with System
.Task_Lock
;
38 with Interfaces
.C
.Strings
;
40 package body System
.Global_Locks
is
42 package TSL
renames System
.Task_Lock
;
43 package OSI
renames System
.OS_Interface
;
44 package ICS
renames Interfaces
.C
.Strings
;
46 subtype Lock_File_Entry
is Win32
.HANDLE
;
48 Last_Lock
: Lock_Type
:= Null_Lock
;
49 Lock_Table
: array (Lock_Type
range 1 .. 15) of Lock_File_Entry
;
55 procedure Create_Lock
(Lock
: out Lock_Type
; Name
: String) is
60 Last_Lock
:= Last_Lock
+ 1;
64 if L
> Lock_Table
'Last then
69 OSI
.CreateMutex
(null, Win32
.FALSE, ICS
.New_String
(Name
));
77 procedure Acquire_Lock
(Lock
: in out Lock_Type
) is
83 Res
:= OSI
.WaitForSingleObject
(Lock_Table
(Lock
), OSI
.Wait_Infinite
);
85 if Res
= OSI
.WAIT_FAILED
then
94 procedure Release_Lock
(Lock
: in out Lock_Type
) is
100 Res
:= OSI
.ReleaseMutex
(Lock_Table
(Lock
));
102 if Res
= Win32
.FALSE then
107 end System
.Global_Locks
;