X-Git-Url: http://git.jankratochvil.net/?p=reactos.git;a=blobdiff_plain;f=subsys%2Fwin32k%2Fntuser%2Fwinlock.c;fp=subsys%2Fwin32k%2Fntuser%2Fwinlock.c;h=225e56cbcd5791cae53cd517e11f96abe0f1b0cc;hp=0000000000000000000000000000000000000000;hb=a3df8bf1429570e0bd6c6428f6ed80073578cf4b;hpb=7c0db166f81fbe8c8b913d7f26048e337d383605 diff --git a/subsys/win32k/ntuser/winlock.c b/subsys/win32k/ntuser/winlock.c new file mode 100644 index 0000000..225e56c --- /dev/null +++ b/subsys/win32k/ntuser/winlock.c @@ -0,0 +1,123 @@ +/* + * ReactOS W32 Subsystem + * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/* + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Windows++ locking + * FILE: subsys/win32k/ntuser/winlock.c + * PROGRAMER: Gunnar + * REVISION HISTORY: + * + */ +/* INCLUDES ******************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define NDEBUG +#include +#include + +/* GLOBALS *****************************************************************/ + +static ERESOURCE WinLock; + +/* FUNCTIONS *****************************************************************/ + +BOOL FASTCALL IntVerifyWinLock(WINLOCK_TYPE Type) +{ + switch (Type) + { + case None: + return !ExIsResourceAcquiredSharedLite(&WinLock); + case Shared: /* NOTE: an exclusive lock is also a shared lock */ + case Any: + return ExIsResourceAcquiredSharedLite(&WinLock); + case Exclusive: + return ExIsResourceAcquiredExclusiveLite(&WinLock); + } + + KEBUGCHECK(0); + return FALSE; +} + +WINLOCK_TYPE FASTCALL IntSuspendWinLock() +{ + ASSERT_WINLOCK(Any); + + if (ExIsResourceAcquiredExclusiveLite(&WinLock)) return Exclusive; + + return Shared; +} + +VOID FASTCALL IntRestoreWinLock(WINLOCK_TYPE Type) +{ + switch (Type) + { + case Exclusive: + return IntAcquireWinLockExclusive(&WinLock); + case Shared: + return IntAcquireWinLockShared(&WinLock); + /* silence warnings */ + case None: + case Any: + break; + } + + KEBUGCHECK(0); +} + +inline VOID IntAcquireWinLockShared() +{ + ExAcquireResourceExclusiveLite(&WinLock, TRUE /*Wait*/ ); +} + +inline VOID IntAcquireWinLockExclusive() +{ + ExAcquireResourceSharedLite(&WinLock, TRUE /*Wait*/ ); +} + +inline VOID IntReleaseWinLock() +{ + ExReleaseResourceLite(&WinLock ); +} + +inline BOOL IntInitializeWinLock() +{ + ExInitializeResourceLite(&WinLock ); + return TRUE; +} + +inline VOID IntDeleteWinLock() +{ + ExDeleteResourceLite(&WinLock ); +} + +/* EOF */