3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +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:
Nikolaj Bjorner 2015-09-28 13:37:59 -07:00
parent ad16cc0ce2
commit 9b3e242990
26 changed files with 165 additions and 14 deletions

55
src/util/rlimit.cpp Normal file
View 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();
}

47
src/util/rlimit.h Normal file
View file

@ -0,0 +1,47 @@
/*++
Copyright (c) 2015 Microsoft Corporation
Module Name:
rlimit.h
Abstract:
Resource limit container.
Author:
Nikolaj Bjorner (nbjorner) 2015-09-28
Revision History:
--*/
#ifndef RLIMIT_H_
#define RLIMIT_H_
#include "vector.h"
class reslimit {
unsigned m_count;
unsigned m_limit;
unsigned_vector m_limits;
public:
reslimit();
bool inc();
bool inc(unsigned offset);
void push(unsigned delta_limit);
void pop();
unsigned count() const;
};
class scoped_rlimit {
reslimit& m_limit;
public:
scoped_rlimit(reslimit& r, unsigned l): m_limit(r) {
r.push(l);
}
~scoped_rlimit() { m_limit.pop(); }
};
#endif

View file

@ -236,3 +236,7 @@ void get_memory_statistics(statistics& st) {
st.update("memory", static_cast<double>(mem)/100.0);
st.update("num allocs", static_cast<double>(memory::get_allocation_count()));
}
void get_rlimit_statistics(reslimit& l, statistics& st) {
st.update("rlimit-count", l.count());
}

View file

@ -21,6 +21,7 @@ Notes:
#include<iostream>
#include"vector.h"
#include"rlimit.h"
class statistics {
typedef std::pair<char const *, unsigned> key_val_pair;
@ -43,5 +44,6 @@ public:
};
void get_memory_statistics(statistics& st);
void get_rlimit_statistics(reslimit& l, statistics& st);
#endif