Commit a0050be1 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Use the default keyed event when the handle is null.

parent 7c430f5b
......@@ -1189,6 +1189,7 @@ NTSTATUS WINAPI NtWaitForKeyedEvent( HANDLE handle, const void *key,
select_op_t select_op;
UINT flags = SELECT_INTERRUPTIBLE;
if (!handle) handle = keyed_event;
if ((ULONG_PTR)key & 1) return STATUS_INVALID_PARAMETER_1;
if (alertable) flags |= SELECT_ALERTABLE;
select_op.keyed_event.op = SELECT_KEYED_EVENT_WAIT;
......@@ -1206,6 +1207,7 @@ NTSTATUS WINAPI NtReleaseKeyedEvent( HANDLE handle, const void *key,
select_op_t select_op;
UINT flags = SELECT_INTERRUPTIBLE;
if (!handle) handle = keyed_event;
if ((ULONG_PTR)key & 1) return STATUS_INVALID_PARAMETER_1;
if (alertable) flags |= SELECT_ALERTABLE;
select_op.keyed_event.op = SELECT_KEYED_EVENT_RELEASE;
......@@ -1524,7 +1526,7 @@ DWORD WINAPI RtlRunOnceBeginInitialize( RTL_RUN_ONCE *once, ULONG flags, void **
next = val & ~3;
if (interlocked_cmpxchg_ptr( &once->Ptr, (void *)((ULONG_PTR)&next | 1),
(void *)val ) == (void *)val)
NtWaitForKeyedEvent( keyed_event, &next, FALSE, NULL );
NtWaitForKeyedEvent( 0, &next, FALSE, NULL );
break;
case 2: /* done */
......@@ -1564,7 +1566,7 @@ DWORD WINAPI RtlRunOnceComplete( RTL_RUN_ONCE *once, ULONG flags, void *context
while (val)
{
ULONG_PTR next = *(ULONG_PTR *)val;
NtReleaseKeyedEvent( keyed_event, (void *)val, FALSE, NULL );
NtReleaseKeyedEvent( 0, (void *)val, FALSE, NULL );
val = next;
}
return STATUS_SUCCESS;
......@@ -1704,12 +1706,12 @@ static inline void srwlock_leave_exclusive( RTL_SRWLOCK *lock, unsigned int val
* exclusive access threads they are processed first, followed by
* the shared waiters. */
if (val & SRWLOCK_MASK_EXCLUSIVE_QUEUE)
NtReleaseKeyedEvent( keyed_event, srwlock_key_exclusive(lock), FALSE, NULL );
NtReleaseKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
else
{
val &= SRWLOCK_MASK_SHARED_QUEUE; /* remove SRWLOCK_MASK_IN_EXCLUSIVE */
while (val--)
NtReleaseKeyedEvent( keyed_event, srwlock_key_shared(lock), FALSE, NULL );
NtReleaseKeyedEvent( 0, srwlock_key_shared(lock), FALSE, NULL );
}
}
......@@ -1718,7 +1720,7 @@ static inline void srwlock_leave_shared( RTL_SRWLOCK *lock, unsigned int val )
/* Wake up one exclusive thread as soon as the last shared access thread
* has left. */
if ((val & SRWLOCK_MASK_EXCLUSIVE_QUEUE) && !(val & SRWLOCK_MASK_SHARED_QUEUE))
NtReleaseKeyedEvent( keyed_event, srwlock_key_exclusive(lock), FALSE, NULL );
NtReleaseKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
}
/***********************************************************************
......@@ -1747,7 +1749,7 @@ void WINAPI RtlInitializeSRWLock( RTL_SRWLOCK *lock )
void WINAPI RtlAcquireSRWLockExclusive( RTL_SRWLOCK *lock )
{
if (srwlock_lock_exclusive( (unsigned int *)&lock->Ptr, SRWLOCK_RES_EXCLUSIVE ))
NtWaitForKeyedEvent( keyed_event, srwlock_key_exclusive(lock), FALSE, NULL );
NtWaitForKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
}
/***********************************************************************
......@@ -1775,14 +1777,14 @@ void WINAPI RtlAcquireSRWLockShared( RTL_SRWLOCK *lock )
/* Drop exclusive access again and instead requeue for shared access. */
if ((val & SRWLOCK_MASK_EXCLUSIVE_QUEUE) && !(val & SRWLOCK_MASK_IN_EXCLUSIVE))
{
NtWaitForKeyedEvent( keyed_event, srwlock_key_exclusive(lock), FALSE, NULL );
NtWaitForKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
val = srwlock_unlock_exclusive( (unsigned int *)&lock->Ptr, (SRWLOCK_RES_SHARED
- SRWLOCK_RES_EXCLUSIVE) ) - SRWLOCK_RES_EXCLUSIVE;
srwlock_leave_exclusive( lock, val );
}
if (val & SRWLOCK_MASK_EXCLUSIVE_QUEUE)
NtWaitForKeyedEvent( keyed_event, srwlock_key_shared(lock), FALSE, NULL );
NtWaitForKeyedEvent( 0, srwlock_key_shared(lock), FALSE, NULL );
}
/***********************************************************************
......@@ -1866,7 +1868,7 @@ void WINAPI RtlInitializeConditionVariable( RTL_CONDITION_VARIABLE *variable )
void WINAPI RtlWakeConditionVariable( RTL_CONDITION_VARIABLE *variable )
{
if (interlocked_dec_if_nonzero( (int *)&variable->Ptr ))
NtReleaseKeyedEvent( keyed_event, &variable->Ptr, FALSE, NULL );
NtReleaseKeyedEvent( 0, &variable->Ptr, FALSE, NULL );
}
/***********************************************************************
......@@ -1878,7 +1880,7 @@ void WINAPI RtlWakeAllConditionVariable( RTL_CONDITION_VARIABLE *variable )
{
int val = interlocked_xchg( (int *)&variable->Ptr, 0 );
while (val-- > 0)
NtReleaseKeyedEvent( keyed_event, &variable->Ptr, FALSE, NULL );
NtReleaseKeyedEvent( 0, &variable->Ptr, FALSE, NULL );
}
/***********************************************************************
......@@ -1903,11 +1905,11 @@ NTSTATUS WINAPI RtlSleepConditionVariableCS( RTL_CONDITION_VARIABLE *variable, R
interlocked_xchg_add( (int *)&variable->Ptr, 1 );
RtlLeaveCriticalSection( crit );
status = NtWaitForKeyedEvent( keyed_event, &variable->Ptr, FALSE, timeout );
status = NtWaitForKeyedEvent( 0, &variable->Ptr, FALSE, timeout );
if (status != STATUS_SUCCESS)
{
if (!interlocked_dec_if_nonzero( (int *)&variable->Ptr ))
status = NtWaitForKeyedEvent( keyed_event, &variable->Ptr, FALSE, NULL );
status = NtWaitForKeyedEvent( 0, &variable->Ptr, FALSE, NULL );
}
RtlEnterCriticalSection( crit );
......@@ -1944,11 +1946,11 @@ NTSTATUS WINAPI RtlSleepConditionVariableSRW( RTL_CONDITION_VARIABLE *variable,
else
RtlReleaseSRWLockExclusive( lock );
status = NtWaitForKeyedEvent( keyed_event, &variable->Ptr, FALSE, timeout );
status = NtWaitForKeyedEvent( 0, &variable->Ptr, FALSE, timeout );
if (status != STATUS_SUCCESS)
{
if (!interlocked_dec_if_nonzero( (int *)&variable->Ptr ))
status = NtWaitForKeyedEvent( keyed_event, &variable->Ptr, FALSE, NULL );
status = NtWaitForKeyedEvent( 0, &variable->Ptr, FALSE, NULL );
}
if (flags & RTL_CONDITION_VARIABLE_LOCKMODE_SHARED)
......@@ -1986,7 +1988,7 @@ NTSTATUS WINAPI RtlWaitOnAddress( const void *addr, const void *cmp, SIZE_T size
return STATUS_INVALID_PARAMETER;
}
return NtWaitForKeyedEvent( keyed_event, addr, 0, timeout );
return NtWaitForKeyedEvent( 0, addr, 0, timeout );
}
/***********************************************************************
......@@ -1994,7 +1996,7 @@ NTSTATUS WINAPI RtlWaitOnAddress( const void *addr, const void *cmp, SIZE_T size
*/
void WINAPI RtlWakeAddressAll( const void *addr )
{
while (NtReleaseKeyedEvent( keyed_event, addr, 0, &zero_timeout ) == STATUS_SUCCESS) {}
while (NtReleaseKeyedEvent( 0, addr, 0, &zero_timeout ) == STATUS_SUCCESS) {}
}
/***********************************************************************
......@@ -2002,5 +2004,5 @@ void WINAPI RtlWakeAddressAll( const void *addr )
*/
void WINAPI RtlWakeAddressSingle( const void *addr )
{
NtReleaseKeyedEvent( keyed_event, addr, 0, &zero_timeout );
NtReleaseKeyedEvent( 0, addr, 0, &zero_timeout );
}
......@@ -1760,10 +1760,10 @@ static void test_keyed_events(void)
ok( status == STATUS_TIMEOUT, "NtReleaseKeyedEvent %x\n", status );
status = pNtWaitForKeyedEvent( NULL, (void *)8, 0, &timeout );
todo_wine ok( status == STATUS_TIMEOUT || broken(status == STATUS_INVALID_HANDLE), /* XP/2003 */
ok( status == STATUS_TIMEOUT || broken(status == STATUS_INVALID_HANDLE), /* XP/2003 */
"NtWaitForKeyedEvent %x\n", status );
status = pNtReleaseKeyedEvent( NULL, (void *)8, 0, &timeout );
todo_wine ok( status == STATUS_TIMEOUT || broken(status == STATUS_INVALID_HANDLE), /* XP/2003 */
ok( status == STATUS_TIMEOUT || broken(status == STATUS_INVALID_HANDLE), /* XP/2003 */
"NtReleaseKeyedEvent %x\n", status );
status = pNtWaitForKeyedEvent( (HANDLE)0xdeadbeef, (void *)9, 0, &timeout );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment