Refactor ExAcquireReadWriteLockShared to remove duplicate code.

This commit is contained in:
Fisherman166 2020-05-26 09:20:15 -07:00
parent a679073ec6
commit b72be80b88
1 changed files with 13 additions and 31 deletions

View File

@ -181,9 +181,11 @@ XBSYSAPI EXPORTNUM(13) xboxkrnl::VOID NTAPI xboxkrnl::ExAcquireReadWriteLockShar
LOG_FUNC_ONE_ARG(ReadWriteLock); LOG_FUNC_ONE_ARG(ReadWriteLock);
bool interrupt_mode = DisableInterrupts(); bool interrupt_mode = DisableInterrupts();
bool must_wait_on_active_write = ReadWriteLock->ReadersEntryCount == 0;
bool must_wait_on_queued_write = (ReadWriteLock->ReadersEntryCount != 0) && (ReadWriteLock->WritersWaitingCount != 0);
bool must_wait = must_wait_on_active_write || must_wait_on_queued_write;
ReadWriteLock->LockCount++; ReadWriteLock->LockCount++;
if (ReadWriteLock->LockCount != 0) { if ((ReadWriteLock->LockCount != 0) && must_wait) {
if (ReadWriteLock->ReadersEntryCount == 0) {
ReadWriteLock->ReadersWaitingCount++; ReadWriteLock->ReadersWaitingCount++;
RestoreInterruptMode(interrupt_mode); RestoreInterruptMode(interrupt_mode);
#if 0 //FIXME - Enable once KeReleaseSempahore is implemented (used in ExFreeReadWriteLock for Sharedlocks). #if 0 //FIXME - Enable once KeReleaseSempahore is implemented (used in ExFreeReadWriteLock for Sharedlocks).
@ -196,26 +198,6 @@ XBSYSAPI EXPORTNUM(13) xboxkrnl::VOID NTAPI xboxkrnl::ExAcquireReadWriteLockShar
); );
#endif #endif
} }
else {
if (ReadWriteLock->WritersWaitingCount == 0) {
ReadWriteLock->ReadersEntryCount++;
RestoreInterruptMode(interrupt_mode);
}
else {
ReadWriteLock->ReadersWaitingCount++;
RestoreInterruptMode(interrupt_mode);
#if 0 //FIXME - Enable once KeReleaseSempahore is implemented (used in ExFreeReadWriteLock for Sharedlocks).
KeWaitForSingleObject(
&ReadWriteLock->ReaderSemaphore,
Executive,
0,
0,
0
);
#endif
}
}
}
else { else {
ReadWriteLock->ReadersEntryCount++; ReadWriteLock->ReadersEntryCount++;
RestoreInterruptMode(interrupt_mode); RestoreInterruptMode(interrupt_mode);