mirror of
https://github.com/Z3Prover/z3
synced 2025-08-26 13:06:05 +00:00
mux
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
2788f72bbb
commit
9262908ebb
30 changed files with 191 additions and 341 deletions
|
@ -7,10 +7,10 @@ Copyright (c) 2015 Microsoft Corporation
|
|||
#include<iostream>
|
||||
#include<stdlib.h>
|
||||
#include<climits>
|
||||
#include<mutex>
|
||||
#include "util/trace.h"
|
||||
#include "util/memory_manager.h"
|
||||
#include "util/error_codes.h"
|
||||
#include "util/z3_omp.h"
|
||||
#include "util/debug.h"
|
||||
// The following two function are automatically generated by the mk_make.py script.
|
||||
// The script collects ADD_INITIALIZER and ADD_FINALIZER commands in the .h files.
|
||||
|
@ -35,6 +35,7 @@ out_of_memory_error::out_of_memory_error():z3_error(ERR_MEMOUT) {
|
|||
}
|
||||
|
||||
|
||||
static std::mutex g_memory_mux;
|
||||
static volatile bool g_memory_out_of_memory = false;
|
||||
static bool g_memory_initialized = false;
|
||||
static long long g_memory_alloc_size = 0;
|
||||
|
@ -54,8 +55,8 @@ void memory::exit_when_out_of_memory(bool flag, char const * msg) {
|
|||
}
|
||||
|
||||
static void throw_out_of_memory() {
|
||||
#pragma omp critical (z3_memory_manager)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_memory_mux);
|
||||
g_memory_out_of_memory = true;
|
||||
}
|
||||
|
||||
|
@ -90,8 +91,8 @@ mem_usage_report g_info;
|
|||
|
||||
void memory::initialize(size_t max_size) {
|
||||
bool initialize = false;
|
||||
#pragma omp critical (z3_memory_manager)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_memory_mux);
|
||||
// only update the maximum size if max_size != UINT_MAX
|
||||
if (max_size != UINT_MAX)
|
||||
g_memory_max_size = max_size;
|
||||
|
@ -116,8 +117,8 @@ void memory::initialize(size_t max_size) {
|
|||
|
||||
bool memory::is_out_of_memory() {
|
||||
bool r = false;
|
||||
#pragma omp critical (z3_memory_manager)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_memory_mux);
|
||||
r = g_memory_out_of_memory;
|
||||
}
|
||||
return r;
|
||||
|
@ -131,12 +132,8 @@ void memory::set_high_watermark(size_t watermark) {
|
|||
bool memory::above_high_watermark() {
|
||||
if (g_memory_watermark == 0)
|
||||
return false;
|
||||
bool r;
|
||||
#pragma omp critical (z3_memory_manager)
|
||||
{
|
||||
r = g_memory_watermark < g_memory_alloc_size;
|
||||
}
|
||||
return r;
|
||||
std::lock_guard<std::mutex> lock(g_memory_mux);
|
||||
return g_memory_watermark < g_memory_alloc_size;
|
||||
}
|
||||
|
||||
// The following methods are only safe to invoke at
|
||||
|
@ -163,8 +160,8 @@ void memory::finalize() {
|
|||
|
||||
unsigned long long memory::get_allocation_size() {
|
||||
long long r;
|
||||
#pragma omp critical (z3_memory_manager)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_memory_mux);
|
||||
r = g_memory_alloc_size;
|
||||
}
|
||||
if (r < 0)
|
||||
|
@ -174,8 +171,8 @@ unsigned long long memory::get_allocation_size() {
|
|||
|
||||
unsigned long long memory::get_max_used_memory() {
|
||||
unsigned long long r;
|
||||
#pragma omp critical (z3_memory_manager)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_memory_mux);
|
||||
r = g_memory_max_used_size;
|
||||
}
|
||||
return r;
|
||||
|
@ -258,8 +255,8 @@ static void synchronize_counters(bool allocating) {
|
|||
|
||||
bool out_of_mem = false;
|
||||
bool counts_exceeded = false;
|
||||
#pragma omp critical (z3_memory_manager)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_memory_mux);
|
||||
g_memory_alloc_size += g_memory_thread_alloc_size;
|
||||
g_memory_alloc_count += g_memory_thread_alloc_count;
|
||||
if (g_memory_alloc_size > g_memory_max_used_size)
|
||||
|
@ -339,8 +336,8 @@ void memory::deallocate(void * p) {
|
|||
size_t * sz_p = reinterpret_cast<size_t*>(p) - 1;
|
||||
size_t sz = *sz_p;
|
||||
void * real_p = reinterpret_cast<void*>(sz_p);
|
||||
#pragma omp critical (z3_memory_manager)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_memory_mux);
|
||||
g_memory_alloc_size -= sz;
|
||||
}
|
||||
free(real_p);
|
||||
|
@ -349,8 +346,8 @@ void memory::deallocate(void * p) {
|
|||
void * memory::allocate(size_t s) {
|
||||
s = s + sizeof(size_t); // we allocate an extra field!
|
||||
bool out_of_mem = false, counts_exceeded = false;
|
||||
#pragma omp critical (z3_memory_manager)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_memory_mux);
|
||||
g_memory_alloc_size += s;
|
||||
g_memory_alloc_count += 1;
|
||||
if (g_memory_alloc_size > g_memory_max_used_size)
|
||||
|
@ -379,8 +376,8 @@ void* memory::reallocate(void *p, size_t s) {
|
|||
void * real_p = reinterpret_cast<void*>(sz_p);
|
||||
s = s + sizeof(size_t); // we allocate an extra field!
|
||||
bool out_of_mem = false, counts_exceeded = false;
|
||||
#pragma omp critical (z3_memory_manager)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_memory_mux);
|
||||
g_memory_alloc_size += s - sz;
|
||||
g_memory_alloc_count += 1;
|
||||
if (g_memory_alloc_size > g_memory_max_used_size)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue