2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/kernel32/synch/wait.c
5 * PURPOSE: Wait functions
6 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
13 #include <ddk/ntddk.h>
18 LPSECURITY_ATTRIBUTES lpSemaphoreAttributes
,
24 WCHAR NameW
[MAX_PATH
];
27 while ((*lpName
)!=0 && i
< MAX_PATH
)
34 return CreateSemaphoreW(
35 lpSemaphoreAttributes
,
45 LPSECURITY_ATTRIBUTES lpSemaphoreAttributes
,
51 OBJECT_ATTRIBUTES ObjectAttributes
;
53 UNICODE_STRING NameString
;
54 HANDLE SemaphoreHandle
;
56 NameString
.Length
= lstrlenW(lpName
)*sizeof(WCHAR
);
57 NameString
.Buffer
= (WCHAR
*)lpName
;
58 NameString
.MaximumLength
= NameString
.Length
;
60 ObjectAttributes
.Length
= sizeof(OBJECT_ATTRIBUTES
);
61 ObjectAttributes
.RootDirectory
= NULL
;
62 ObjectAttributes
.ObjectName
= &NameString
;
63 ObjectAttributes
.Attributes
= OBJ_CASE_INSENSITIVE
;
64 ObjectAttributes
.SecurityDescriptor
= NULL
;
65 ObjectAttributes
.SecurityQualityOfService
= NULL
;
67 if ( lpSemaphoreAttributes
!= NULL
) {
68 ObjectAttributes
.SecurityDescriptor
= lpSemaphoreAttributes
->lpSecurityDescriptor
;
69 if ( lpSemaphoreAttributes
->bInheritHandle
== TRUE
)
70 ObjectAttributes
.Attributes
|= OBJ_INHERIT
;
74 errCode
= NtCreateSemaphore(
81 if (!NT_SUCCESS(errCode
))
83 SetLastError(RtlNtStatusToDosError(errCode
));
87 return SemaphoreHandle
;
93 LPSECURITY_ATTRIBUTES lpMutexAttributes
,
94 WINBOOL bInitialOwner
,
98 WCHAR NameW
[MAX_PATH
];
101 while ((*lpName
)!=0 && i
< MAX_PATH
)
119 LPSECURITY_ATTRIBUTES lpMutexAttributes
,
120 WINBOOL bInitialOwner
,
124 OBJECT_ATTRIBUTES ObjectAttributes
;
126 UNICODE_STRING NameString
;
129 NameString
.Length
= lstrlenW(lpName
)*sizeof(WCHAR
);
130 NameString
.Buffer
= (WCHAR
*)lpName
;
131 NameString
.MaximumLength
= NameString
.Length
;
133 ObjectAttributes
.Length
= sizeof(OBJECT_ATTRIBUTES
);
134 ObjectAttributes
.RootDirectory
= NULL
;
135 ObjectAttributes
.ObjectName
= &NameString
;
136 ObjectAttributes
.Attributes
= OBJ_CASE_INSENSITIVE
;
137 ObjectAttributes
.SecurityDescriptor
= NULL
;
138 ObjectAttributes
.SecurityQualityOfService
= NULL
;
140 if ( lpMutexAttributes
!= NULL
) {
141 ObjectAttributes
.SecurityDescriptor
= lpMutexAttributes
->lpSecurityDescriptor
;
142 if ( lpMutexAttributes
->bInheritHandle
== TRUE
)
143 ObjectAttributes
.Attributes
|= OBJ_INHERIT
;
147 errCode
= NtCreateMutant(&MutantHandle
,GENERIC_ALL
, &ObjectAttributes
,(BOOLEAN
)bInitialOwner
);
148 if (!NT_SUCCESS(errCode
))
150 SetLastError(RtlNtStatusToDosError(errCode
));
161 WaitForSingleObject(HANDLE hHandle
,
162 DWORD dwMilliseconds
)
164 return WaitForSingleObjectEx(hHandle
,dwMilliseconds
,FALSE
);
170 WaitForSingleObjectEx(HANDLE hHandle
,
171 DWORD dwMilliseconds
,
175 PLARGE_INTEGER TimePtr
;
179 if (dwMilliseconds
== INFINITE
)
185 Time
.QuadPart
= -10000 * dwMilliseconds
;
189 errCode
= NtWaitForSingleObject(hHandle
,
190 (BOOLEAN
) bAlertable
,
192 if (errCode
== STATUS_TIMEOUT
)
196 else if (errCode
== WAIT_OBJECT_0
)
198 return WAIT_OBJECT_0
;
201 retCode
= RtlNtStatusToDosError(errCode
);
202 SetLastError(retCode
);
210 WaitForMultipleObjects(DWORD nCount
,
211 CONST HANDLE
*lpHandles
,
213 DWORD dwMilliseconds
)
215 return WaitForMultipleObjectsEx(nCount
,lpHandles
,bWaitAll
,dwMilliseconds
,FALSE
);
221 WaitForMultipleObjectsEx(DWORD nCount
,
222 CONST HANDLE
*lpHandles
,
224 DWORD dwMilliseconds
,
229 PLARGE_INTEGER TimePtr
;
232 if (dwMilliseconds
== INFINITE
)
238 Time
.QuadPart
= -10000 * dwMilliseconds
;
242 errCode
= NtWaitForMultipleObjects (nCount
,
248 if (errCode
== STATUS_TIMEOUT
)
252 else if ((errCode
>= WAIT_OBJECT_0
) &&
253 (errCode
<= WAIT_OBJECT_0
+ nCount
- 1))
258 retCode
= RtlNtStatusToDosError(errCode
);
259 SetLastError(retCode
);