[xboxkrnl] ExReleaseReadWriteLock fixes.

[xboxkrnl] ExReleaseReadWriteLock fixes:
- Don't unncessarily double-load lock members.
- Reset readers entry count when lock count becomes negative.
- Properly decrease writers waiting count when writer event fired.
This commit is contained in:
gibbed 2022-01-07 09:18:10 -06:00 committed by Rick Gibbed
parent b4f35635c5
commit e795337071
1 changed files with 13 additions and 8 deletions

View File

@ -1201,9 +1201,11 @@ DECLARE_XBOXKRNL_EXPORT2(ExAcquireReadWriteLockExclusive, kThreading,
void ExReleaseReadWriteLock(pointer_t<X_ERWLOCK> lock_ptr) {
auto old_irql = xeKeKfAcquireSpinLock(&lock_ptr->spin_lock);
lock_ptr->lock_count--;
if (lock_ptr->lock_count < 0) {
int32_t lock_count = --lock_ptr->lock_count;
if (lock_count < 0) {
lock_ptr->readers_entry_count = 0;
xeKeKfReleaseSpinLock(&lock_ptr->spin_lock, old_irql);
return;
}
@ -1220,14 +1222,17 @@ void ExReleaseReadWriteLock(pointer_t<X_ERWLOCK> lock_ptr) {
}
}
auto count = lock_ptr->readers_entry_count--;
auto readers_entry_count = --lock_ptr->readers_entry_count;
if (readers_entry_count) {
xeKeKfReleaseSpinLock(&lock_ptr->spin_lock, old_irql);
return;
}
lock_ptr->writers_waiting_count--;
xeKeKfReleaseSpinLock(&lock_ptr->spin_lock, old_irql);
if (!count) {
xeKeSetEvent(&lock_ptr->writer_event, 1, 0);
}
}
DECLARE_XBOXKRNL_EXPORT2(ExReleaseReadWriteLock, kThreading, kImplemented,
kSketchy);
DECLARE_XBOXKRNL_EXPORT1(ExReleaseReadWriteLock, kThreading, kImplemented);
// NOTE: This function is very commonly inlined, and probably won't be called!
pointer_result_t InterlockedPushEntrySList(