sync with trunk head (34904)
[reactos.git] / reactos / subsystems / win32 / win32k / ntuser / ntuser.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 * $Id: painting.c 16320 2005-06-29 07:09:25Z navaraf $
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * PURPOSE: ntuser init. and main funcs.
24 * FILE: subsys/win32k/ntuser/ntuser.c
25 * REVISION HISTORY:
26 * 16 July 2005 Created (hardon)
27 */
28
29 /* INCLUDES ******************************************************************/
30
31 #include <w32k.h>
32
33 #define NDEBUG
34 #include <debug.h>
35
36 ERESOURCE UserLock;
37
38 /* FUNCTIONS **********************************************************/
39
40
41 NTSTATUS FASTCALL InitUserImpl(VOID)
42 {
43 NTSTATUS Status;
44
45 ExInitializeResourceLite(&UserLock);
46
47 if (!UserCreateHandleTable())
48 {
49 DPRINT1("Failed creating handle table\n");
50 return STATUS_INSUFFICIENT_RESOURCES;
51 }
52
53 Status = InitSessionImpl();
54 if (!NT_SUCCESS(Status))
55 {
56 DPRINT1("Error init session impl.\n");
57 return Status;
58 }
59
60 if (!gpsi)
61 {
62 gpsi = UserHeapAlloc(sizeof(SERVERINFO));
63 if (gpsi)
64 {
65 RtlZeroMemory(gpsi, sizeof(SERVERINFO));
66 DPRINT("Global Server Data -> %x\n", gpsi);
67 }
68 }
69 return STATUS_SUCCESS;
70 }
71
72 /*
73 RETURN
74 True if current thread owns the lock (possibly shared)
75 */
76 BOOL FASTCALL UserIsEntered()
77 {
78 return ExIsResourceAcquiredExclusiveLite(&UserLock)
79 || ExIsResourceAcquiredSharedLite(&UserLock);
80 }
81
82 BOOL FASTCALL UserIsEnteredExclusive()
83 {
84 return ExIsResourceAcquiredExclusiveLite(&UserLock);
85 }
86
87 VOID FASTCALL CleanupUserImpl(VOID)
88 {
89 ExDeleteResourceLite(&UserLock);
90 }
91
92 VOID FASTCALL UserEnterShared(VOID)
93 {
94 KeEnterCriticalRegion();
95 ExAcquireResourceSharedLite(&UserLock, TRUE);
96 }
97
98 VOID FASTCALL UserEnterExclusive(VOID)
99 {
100 KeEnterCriticalRegion();
101 ExAcquireResourceExclusiveLite(&UserLock, TRUE);
102 }
103
104 VOID FASTCALL UserLeave(VOID)
105 {
106 ExReleaseResourceLite(&UserLock);
107 KeLeaveCriticalRegion();
108 }