This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / subsys / win32k / ntuser / winlock.c
1 /*
2  *  ReactOS W32 Subsystem
3  *  Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /*
20  *
21  * COPYRIGHT:        See COPYING in the top level directory
22  * PROJECT:          ReactOS kernel
23  * PURPOSE:          Windows++ locking
24  * FILE:             subsys/win32k/ntuser/winlock.c
25  * PROGRAMER:        Gunnar
26  * REVISION HISTORY:
27  *
28  */
29 /* INCLUDES ******************************************************************/
30
31 #include <ddk/ntddk.h>
32 #include <win32k/win32k.h>
33 #include <include/object.h>
34 #include <include/guicheck.h>
35 #include <include/window.h>
36 #include <include/class.h>
37 #include <include/error.h>
38 #include <include/winsta.h>
39 #include <include/winpos.h>
40 #include <include/callback.h>
41 #include <include/msgqueue.h>
42 #include <include/rect.h>
43
44 #define NDEBUG
45 #include <win32k/debug1.h>
46 #include <debug.h>
47
48 /* GLOBALS *****************************************************************/
49
50 static ERESOURCE WinLock;
51
52 /* FUNCTIONS *****************************************************************/
53
54 BOOL FASTCALL IntVerifyWinLock(WINLOCK_TYPE Type)
55 {
56   switch (Type)
57   {
58     case None:
59       return !ExIsResourceAcquiredSharedLite(&WinLock);
60     case Shared: /* NOTE: an exclusive lock is also a shared lock */
61     case Any: 
62       return ExIsResourceAcquiredSharedLite(&WinLock);
63     case Exclusive:
64       return ExIsResourceAcquiredExclusiveLite(&WinLock);
65   }
66
67   KEBUGCHECK(0);
68   return FALSE;
69 }
70
71 WINLOCK_TYPE FASTCALL IntSuspendWinLock()
72 {
73   ASSERT_WINLOCK(Any);
74
75   if (ExIsResourceAcquiredExclusiveLite(&WinLock)) return Exclusive;
76   
77   return Shared;
78 }
79
80 VOID FASTCALL IntRestoreWinLock(WINLOCK_TYPE Type)
81 {
82   switch (Type)
83   {
84     case Exclusive:
85       return IntAcquireWinLockExclusive(&WinLock);
86     case Shared:
87       return IntAcquireWinLockShared(&WinLock);
88     /* silence warnings */
89     case None:
90     case Any:
91       break;
92   }
93
94   KEBUGCHECK(0);
95 }
96
97 inline VOID IntAcquireWinLockShared()
98 {
99   ExAcquireResourceExclusiveLite(&WinLock, TRUE /*Wait*/ );
100 }
101
102 inline VOID IntAcquireWinLockExclusive()
103 {
104   ExAcquireResourceSharedLite(&WinLock, TRUE /*Wait*/  );
105 }
106
107 inline VOID IntReleaseWinLock()
108 {
109   ExReleaseResourceLite(&WinLock ); 
110 }
111
112 inline BOOL IntInitializeWinLock()
113 {
114   ExInitializeResourceLite(&WinLock );
115   return TRUE;
116 }
117
118 inline VOID IntDeleteWinLock()
119 {
120   ExDeleteResourceLite(&WinLock );  
121 }
122
123 /* EOF */