Use scoped_lock, etc

This commit is contained in:
TuxSH
2018-11-05 14:12:38 +01:00
committed by Michael Scire
parent 698fa9fcb0
commit cd1f74154d
7 changed files with 21 additions and 21 deletions

View File

@@ -8,27 +8,27 @@ KResourceLimit KResourceLimit::defaultInstance{};
size_t KResourceLimit::GetCurrentValue(KResourceLimit::Category category) const
{
// Caller should check category
std::lock_guard guard{condvar.mutex()};
std::scoped_lock guard{condvar.mutex()};
return currentValues[(uint)category];
}
size_t KResourceLimit::GetLimitValue(KResourceLimit::Category category) const
{
// Caller should check category
std::lock_guard guard{condvar.mutex()};
std::scoped_lock guard{condvar.mutex()};
return limitValues[(uint)category];
}
size_t KResourceLimit::GetRemainingValue(KResourceLimit::Category category) const
{
// Caller should check category
std::lock_guard guard{condvar.mutex()};
std::scoped_lock guard{condvar.mutex()};
return limitValues[(uint)category] - currentValues[(uint)category];
}
bool KResourceLimit::SetLimitValue(KResourceLimit::Category category, size_t value)
{
std::lock_guard guard{condvar.mutex()};
std::scoped_lock guard{condvar.mutex()};
if ((long)value < 0 || currentValues[(uint)category] > value) {
return false;
} else {
@@ -40,7 +40,7 @@ bool KResourceLimit::SetLimitValue(KResourceLimit::Category category, size_t val
void KResourceLimit::Release(KResourceLimit::Category category, size_t count, size_t realCount)
{
// Caller should ensure parameters are correct
std::lock_guard guard{condvar.mutex()};
std::scoped_lock guard{condvar.mutex()};
currentValues[(uint)category] -= count;
realValues[(uint)category] -= realCount;
condvar.notify_all();
@@ -48,7 +48,7 @@ void KResourceLimit::Release(KResourceLimit::Category category, size_t count, si
bool KResourceLimit::ReserveDetail(KResourceLimit::Category category, size_t count, const KSystemClock::time_point &timeoutTime)
{
std::lock_guard guard{condvar.mutex()};
std::scoped_lock guard{condvar.mutex()};
if ((long)count <= 0 || realValues[(uint)category] >= limitValues[(uint)category]) {
return false;
}