mirror of
https://github.com/Z3Prover/z3
synced 2025-04-12 04:03:39 +00:00
restore most global muxes as heap-allocated to avoid crashes with hard-kills like ctrl-c
This commit is contained in:
parent
d17248821a
commit
c21f0c2f00
|
@ -21,7 +21,7 @@ Notes:
|
||||||
#include "util/trace.h"
|
#include "util/trace.h"
|
||||||
#include "util/mutex.h"
|
#include "util/mutex.h"
|
||||||
|
|
||||||
static mutex gparams_mux;
|
static DECLARE_MUTEX(gparams_mux);
|
||||||
|
|
||||||
extern void gparams_register_modules();
|
extern void gparams_register_modules();
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
lock_guard lock(gparams_mux);
|
lock_guard lock(*gparams_mux);
|
||||||
m_params.reset();
|
m_params.reset();
|
||||||
for (auto & kv : m_module_params) {
|
for (auto & kv : m_module_params) {
|
||||||
dealloc(kv.m_value);
|
dealloc(kv.m_value);
|
||||||
|
@ -329,7 +329,7 @@ public:
|
||||||
bool error = false;
|
bool error = false;
|
||||||
std::string error_msg;
|
std::string error_msg;
|
||||||
{
|
{
|
||||||
lock_guard lock(gparams_mux);
|
lock_guard lock(*gparams_mux);
|
||||||
try {
|
try {
|
||||||
symbol m, p;
|
symbol m, p;
|
||||||
normalize(name, m, p);
|
normalize(name, m, p);
|
||||||
|
@ -381,7 +381,7 @@ public:
|
||||||
bool error = false;
|
bool error = false;
|
||||||
std::string error_msg;
|
std::string error_msg;
|
||||||
{
|
{
|
||||||
lock_guard lock(gparams_mux);
|
lock_guard lock(*gparams_mux);
|
||||||
try {
|
try {
|
||||||
symbol m, p;
|
symbol m, p;
|
||||||
normalize(name, m, p);
|
normalize(name, m, p);
|
||||||
|
@ -428,7 +428,7 @@ public:
|
||||||
params_ref result;
|
params_ref result;
|
||||||
params_ref * ps = nullptr;
|
params_ref * ps = nullptr;
|
||||||
{
|
{
|
||||||
lock_guard lock(gparams_mux);
|
lock_guard lock(*gparams_mux);
|
||||||
if (m_module_params.find(module_name, ps)) {
|
if (m_module_params.find(module_name, ps)) {
|
||||||
result.copy(*ps);
|
result.copy(*ps);
|
||||||
}
|
}
|
||||||
|
@ -447,30 +447,28 @@ public:
|
||||||
// -----------------------------------------------
|
// -----------------------------------------------
|
||||||
|
|
||||||
void display(std::ostream & out, unsigned indent, bool smt2_style, bool include_descr) {
|
void display(std::ostream & out, unsigned indent, bool smt2_style, bool include_descr) {
|
||||||
{
|
lock_guard lock(*gparams_mux);
|
||||||
lock_guard lock(gparams_mux);
|
out << "Global parameters\n";
|
||||||
out << "Global parameters\n";
|
get_param_descrs().display(out, indent + 4, smt2_style, include_descr);
|
||||||
get_param_descrs().display(out, indent + 4, smt2_style, include_descr);
|
out << "\n";
|
||||||
|
if (!smt2_style) {
|
||||||
|
out << "To set a module parameter, use <module-name>.<parameter-name>=value\n";
|
||||||
|
out << "Example: pp.decimal=true\n";
|
||||||
out << "\n";
|
out << "\n";
|
||||||
if (!smt2_style) {
|
}
|
||||||
out << "To set a module parameter, use <module-name>.<parameter-name>=value\n";
|
for (auto & kv : get_module_param_descrs()) {
|
||||||
out << "Example: pp.decimal=true\n";
|
out << "[module] " << kv.m_key;
|
||||||
out << "\n";
|
char const * descr = nullptr;
|
||||||
}
|
if (get_module_descrs().find(kv.m_key, descr)) {
|
||||||
for (auto & kv : get_module_param_descrs()) {
|
out << ", description: " << descr;
|
||||||
out << "[module] " << kv.m_key;
|
|
||||||
char const * descr = nullptr;
|
|
||||||
if (get_module_descrs().find(kv.m_key, descr)) {
|
|
||||||
out << ", description: " << descr;
|
|
||||||
}
|
|
||||||
out << "\n";
|
|
||||||
kv.m_value->display(out, indent + 4, smt2_style, include_descr);
|
|
||||||
}
|
}
|
||||||
|
out << "\n";
|
||||||
|
kv.m_value->display(out, indent + 4, smt2_style, include_descr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_modules(std::ostream & out) {
|
void display_modules(std::ostream & out) {
|
||||||
lock_guard lock(gparams_mux);
|
lock_guard lock(*gparams_mux);
|
||||||
for (auto & kv : get_module_param_descrs()) {
|
for (auto & kv : get_module_param_descrs()) {
|
||||||
out << "[module] " << kv.m_key;
|
out << "[module] " << kv.m_key;
|
||||||
char const * descr = nullptr;
|
char const * descr = nullptr;
|
||||||
|
@ -484,7 +482,7 @@ public:
|
||||||
void display_module(std::ostream & out, symbol const & module_name) {
|
void display_module(std::ostream & out, symbol const & module_name) {
|
||||||
bool error = false;
|
bool error = false;
|
||||||
std::string error_msg;
|
std::string error_msg;
|
||||||
lock_guard lock(gparams_mux);
|
lock_guard lock(*gparams_mux);
|
||||||
try {
|
try {
|
||||||
param_descrs * d = nullptr;
|
param_descrs * d = nullptr;
|
||||||
if (!get_module_param_descrs().find(module_name, d)) {
|
if (!get_module_param_descrs().find(module_name, d)) {
|
||||||
|
@ -513,7 +511,7 @@ public:
|
||||||
bool error = false;
|
bool error = false;
|
||||||
std::string error_msg;
|
std::string error_msg;
|
||||||
{
|
{
|
||||||
lock_guard lock(gparams_mux);
|
lock_guard lock(*gparams_mux);
|
||||||
try {
|
try {
|
||||||
symbol m, p;
|
symbol m, p;
|
||||||
normalize(name, m, p);
|
normalize(name, m, p);
|
||||||
|
@ -636,10 +634,8 @@ void gparams::init() {
|
||||||
|
|
||||||
void gparams::finalize() {
|
void gparams::finalize() {
|
||||||
TRACE("gparams", tout << "gparams::finalize()\n";);
|
TRACE("gparams", tout << "gparams::finalize()\n";);
|
||||||
if (g_imp != nullptr) {
|
dealloc(g_imp);
|
||||||
dealloc(g_imp);
|
delete gparams_mux;
|
||||||
g_imp = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,7 @@ out_of_memory_error::out_of_memory_error():z3_error(ERR_MEMOUT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef SINGLE_THREAD
|
static DECLARE_MUTEX(g_memory_mux);
|
||||||
static mutex *g_memory_mux = new mutex;
|
|
||||||
#else
|
|
||||||
static mutex *g_memory_mux = nullptr;
|
|
||||||
#endif
|
|
||||||
static atomic<bool> g_memory_out_of_memory(false);
|
static atomic<bool> g_memory_out_of_memory(false);
|
||||||
static bool g_memory_initialized = false;
|
static bool g_memory_initialized = false;
|
||||||
static long long g_memory_alloc_size = 0;
|
static long long g_memory_alloc_size = 0;
|
||||||
|
@ -138,9 +134,7 @@ void memory::finalize() {
|
||||||
if (g_memory_initialized) {
|
if (g_memory_initialized) {
|
||||||
g_finalizing = true;
|
g_finalizing = true;
|
||||||
mem_finalize();
|
mem_finalize();
|
||||||
#ifndef SINGLE_THREAD
|
|
||||||
delete g_memory_mux;
|
delete g_memory_mux;
|
||||||
#endif
|
|
||||||
g_memory_initialized = false;
|
g_memory_initialized = false;
|
||||||
g_finalizing = false;
|
g_finalizing = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ struct lock_guard {
|
||||||
lock_guard(mutex &) {}
|
lock_guard(mutex &) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define DECLARE_MUTEX(name) mutex *name = nullptr
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -32,4 +34,6 @@ struct lock_guard {
|
||||||
template<typename T> using atomic = std::atomic<T>;
|
template<typename T> using atomic = std::atomic<T>;
|
||||||
typedef std::mutex mutex;
|
typedef std::mutex mutex;
|
||||||
typedef std::lock_guard<std::mutex> lock_guard;
|
typedef std::lock_guard<std::mutex> lock_guard;
|
||||||
|
|
||||||
|
#define DECLARE_MUTEX(name) mutex *name = new mutex
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -110,7 +110,7 @@ prime_iterator::prime_iterator(prime_generator * g):m_idx(0) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static mutex g_prime_iterator;
|
static DECLARE_MUTEX(g_prime_iterator);
|
||||||
|
|
||||||
uint64_t prime_iterator::next() {
|
uint64_t prime_iterator::next() {
|
||||||
unsigned idx = m_idx;
|
unsigned idx = m_idx;
|
||||||
|
@ -120,7 +120,7 @@ uint64_t prime_iterator::next() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
uint64_t r;
|
uint64_t r;
|
||||||
lock_guard lock(g_prime_iterator);
|
lock_guard lock(*g_prime_iterator);
|
||||||
{
|
{
|
||||||
r = (*m_generator)(idx);
|
r = (*m_generator)(idx);
|
||||||
}
|
}
|
||||||
|
@ -134,4 +134,5 @@ void prime_iterator::initialize() {
|
||||||
|
|
||||||
void prime_iterator::finalize() {
|
void prime_iterator::finalize() {
|
||||||
g_prime_generator.finalize();
|
g_prime_generator.finalize();
|
||||||
|
delete g_prime_iterator;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,11 +40,11 @@ static void mk_power_up_to(vector<rational> & pws, unsigned n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static mutex g_powers_of_two;
|
static DECLARE_MUTEX(g_powers_of_two);
|
||||||
|
|
||||||
rational rational::power_of_two(unsigned k) {
|
rational rational::power_of_two(unsigned k) {
|
||||||
rational result;
|
rational result;
|
||||||
lock_guard lock(g_powers_of_two);
|
lock_guard lock(*g_powers_of_two);
|
||||||
{
|
{
|
||||||
if (k >= m_powers_of_two.size())
|
if (k >= m_powers_of_two.size())
|
||||||
mk_power_up_to(m_powers_of_two, k+1);
|
mk_power_up_to(m_powers_of_two, k+1);
|
||||||
|
@ -81,5 +81,6 @@ void rational::finalize() {
|
||||||
m_minus_one.~rational();
|
m_minus_one.~rational();
|
||||||
dealloc(g_mpq_manager);
|
dealloc(g_mpq_manager);
|
||||||
g_mpq_manager = nullptr;
|
g_mpq_manager = nullptr;
|
||||||
|
delete g_powers_of_two;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,11 @@ Revision History:
|
||||||
#include "util/mutex.h"
|
#include "util/mutex.h"
|
||||||
|
|
||||||
|
|
||||||
static mutex g_rlimit_mux;
|
static DECLARE_MUTEX(g_rlimit_mux);
|
||||||
|
|
||||||
|
void finalize_rlimit() {
|
||||||
|
delete g_rlimit_mux;
|
||||||
|
}
|
||||||
|
|
||||||
reslimit::reslimit():
|
reslimit::reslimit():
|
||||||
m_cancel(0),
|
m_cancel(0),
|
||||||
|
@ -73,32 +77,32 @@ char const* reslimit::get_cancel_msg() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void reslimit::push_child(reslimit* r) {
|
void reslimit::push_child(reslimit* r) {
|
||||||
lock_guard lock(g_rlimit_mux);
|
lock_guard lock(*g_rlimit_mux);
|
||||||
m_children.push_back(r);
|
m_children.push_back(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reslimit::pop_child() {
|
void reslimit::pop_child() {
|
||||||
lock_guard lock(g_rlimit_mux);
|
lock_guard lock(*g_rlimit_mux);
|
||||||
m_children.pop_back();
|
m_children.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reslimit::cancel() {
|
void reslimit::cancel() {
|
||||||
lock_guard lock(g_rlimit_mux);
|
lock_guard lock(*g_rlimit_mux);
|
||||||
set_cancel(m_cancel+1);
|
set_cancel(m_cancel+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reslimit::reset_cancel() {
|
void reslimit::reset_cancel() {
|
||||||
lock_guard lock(g_rlimit_mux);
|
lock_guard lock(*g_rlimit_mux);
|
||||||
set_cancel(0);
|
set_cancel(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reslimit::inc_cancel() {
|
void reslimit::inc_cancel() {
|
||||||
lock_guard lock(g_rlimit_mux);
|
lock_guard lock(*g_rlimit_mux);
|
||||||
set_cancel(m_cancel+1);
|
set_cancel(m_cancel+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reslimit::dec_cancel() {
|
void reslimit::dec_cancel() {
|
||||||
lock_guard lock(g_rlimit_mux);
|
lock_guard lock(*g_rlimit_mux);
|
||||||
if (m_cancel > 0) {
|
if (m_cancel > 0) {
|
||||||
set_cancel(m_cancel-1);
|
set_cancel(m_cancel-1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,11 @@ Revision History:
|
||||||
|
|
||||||
#include "util/vector.h"
|
#include "util/vector.h"
|
||||||
|
|
||||||
|
void finalize_rlimit();
|
||||||
|
/*
|
||||||
|
ADD_FINALIZER('finalize_rlimit();')
|
||||||
|
*/
|
||||||
|
|
||||||
class reslimit {
|
class reslimit {
|
||||||
volatile unsigned m_cancel;
|
volatile unsigned m_cancel;
|
||||||
bool m_suspend;
|
bool m_suspend;
|
||||||
|
|
|
@ -23,7 +23,7 @@ Revision History:
|
||||||
#include "util/string_buffer.h"
|
#include "util/string_buffer.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
static mutex g_symbol_lock;
|
static DECLARE_MUTEX(g_symbol_lock);
|
||||||
|
|
||||||
symbol symbol::m_dummy(TAG(void*, nullptr, 2));
|
symbol symbol::m_dummy(TAG(void*, nullptr, 2));
|
||||||
const symbol symbol::null;
|
const symbol symbol::null;
|
||||||
|
@ -38,7 +38,7 @@ public:
|
||||||
|
|
||||||
char const * get_str(char const * d) {
|
char const * get_str(char const * d) {
|
||||||
const char * result;
|
const char * result;
|
||||||
lock_guard lock(g_symbol_lock);
|
lock_guard lock(*g_symbol_lock);
|
||||||
str_hashtable::entry * e;
|
str_hashtable::entry * e;
|
||||||
if (m_table.insert_if_not_there_core(d, e)) {
|
if (m_table.insert_if_not_there_core(d, e)) {
|
||||||
// new entry
|
// new entry
|
||||||
|
@ -69,6 +69,7 @@ void initialize_symbols() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void finalize_symbols() {
|
void finalize_symbols() {
|
||||||
|
delete g_symbol_lock;
|
||||||
dealloc(g_symbol_table);
|
dealloc(g_symbol_table);
|
||||||
g_symbol_table = nullptr;
|
g_symbol_table = nullptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue