Use scoped_lock, etc
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user