mirror of
https://github.com/Z3Prover/z3
synced 2025-05-12 02:04:43 +00:00
adding rlimit resource limit facility to provide platform and architecture independent method for canceling activities
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
ad16cc0ce2
commit
9b3e242990
26 changed files with 165 additions and 14 deletions
55
src/util/rlimit.cpp
Normal file
55
src/util/rlimit.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*++
|
||||
Copyright (c) 2015 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
rlimit.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Resource limit container.
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2015-09-28
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#include "rlimit.h"
|
||||
|
||||
reslimit::reslimit():
|
||||
m_count(0),
|
||||
m_limit(UINT_MAX) {
|
||||
}
|
||||
|
||||
unsigned reslimit::count() const {
|
||||
return m_count;
|
||||
}
|
||||
|
||||
bool reslimit::inc() {
|
||||
++m_count;
|
||||
return m_count <= m_limit;
|
||||
}
|
||||
|
||||
bool reslimit::inc(unsigned offset) {
|
||||
m_count += offset;
|
||||
return m_count <= m_limit;
|
||||
}
|
||||
|
||||
void reslimit::push(unsigned delta_limit) {
|
||||
unsigned new_limit = UINT_MAX;
|
||||
if (delta_limit > 0 && delta_limit + m_count > m_count) {
|
||||
new_limit = delta_limit + m_count;
|
||||
}
|
||||
m_limits.push_back(m_limit);
|
||||
m_limit = std::min(new_limit, m_limit);
|
||||
}
|
||||
|
||||
void reslimit::pop() {
|
||||
if (m_count > m_limit) {
|
||||
m_count = m_limit;
|
||||
}
|
||||
m_limit = m_limits.back();
|
||||
m_limits.pop_back();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue