[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:
parent
b4f35635c5
commit
e795337071
|
@ -1201,9 +1201,11 @@ DECLARE_XBOXKRNL_EXPORT2(ExAcquireReadWriteLockExclusive, kThreading,
|
||||||
|
|
||||||
void ExReleaseReadWriteLock(pointer_t<X_ERWLOCK> lock_ptr) {
|
void ExReleaseReadWriteLock(pointer_t<X_ERWLOCK> lock_ptr) {
|
||||||
auto old_irql = xeKeKfAcquireSpinLock(&lock_ptr->spin_lock);
|
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);
|
xeKeKfReleaseSpinLock(&lock_ptr->spin_lock, old_irql);
|
||||||
return;
|
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);
|
xeKeKfReleaseSpinLock(&lock_ptr->spin_lock, old_irql);
|
||||||
if (!count) {
|
|
||||||
xeKeSetEvent(&lock_ptr->writer_event, 1, 0);
|
xeKeSetEvent(&lock_ptr->writer_event, 1, 0);
|
||||||
}
|
}
|
||||||
}
|
DECLARE_XBOXKRNL_EXPORT1(ExReleaseReadWriteLock, kThreading, kImplemented);
|
||||||
DECLARE_XBOXKRNL_EXPORT2(ExReleaseReadWriteLock, kThreading, kImplemented,
|
|
||||||
kSketchy);
|
|
||||||
|
|
||||||
// NOTE: This function is very commonly inlined, and probably won't be called!
|
// NOTE: This function is very commonly inlined, and probably won't be called!
|
||||||
pointer_result_t InterlockedPushEntrySList(
|
pointer_result_t InterlockedPushEntrySList(
|
||||||
|
|
Loading…
Reference in New Issue