3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-10 19:27:06 +00:00

fixup use of SYNC/SYNCH for mpz

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-02-01 11:18:36 -08:00
parent 7df8d17639
commit abbee32ddc
3 changed files with 28 additions and 31 deletions

View file

@ -27,14 +27,6 @@ Revision History:
typedef unsigned int mpn_digit;
class mpn_manager {
#ifndef SINGLE_THREAD
std::recursive_mutex m_lock;
#define MPN_BEGIN_CRITICAL() m_lock.lock()
#define MPN_END_CRITICAL() m_lock.unlock()
#else
#define MPN_BEGIN_CRITICAL() {}
#define MPN_END_CRITICAL() {}
#endif
public:
mpn_manager();

View file

@ -187,15 +187,16 @@ mpz_manager<SYNCH>::~mpz_manager() {
template<bool SYNCH>
mpz_cell * mpz_manager<SYNCH>::allocate(unsigned capacity) {
SASSERT(capacity >= m_init_cell_capacity);
mpz_cell * cell;
#ifdef SINGLE_THREAD
mpz_cell * cell = reinterpret_cast<mpz_cell*>(m_allocator.allocate(cell_size(capacity)));
cell = reinterpret_cast<mpz_cell*>(m_allocator.allocate(cell_size(capacity)));
#else
#if SYNC
mpz_cell * cell = reinterpret_cast<mpz_cell*>(m_allocator.allocate(cell_size(capacity)));
#else
mpz_cell * cell = reinterpret_cast<mpz_cell*>(memory::allocate(cell_size(capacity)));
#endif
if (SYNCH) {
cell = reinterpret_cast<mpz_cell*>(memory::allocate(cell_size(capacity)));
}
else {
cell = reinterpret_cast<mpz_cell*>(m_allocator.allocate(cell_size(capacity)));
}
#endif
cell->m_capacity = capacity;
return cell;
@ -207,11 +208,12 @@ void mpz_manager<SYNCH>::deallocate(bool is_heap, mpz_cell * ptr) {
#ifdef SINGLE_THREAD
m_allocator.deallocate(cell_size(ptr->m_capacity), ptr);
#else
#if SYNC
m_allocator.deallocate(cell_size(ptr->m_capacity), ptr);
#else
memory::deallocate(ptr);
#endif
if (SYNCH) {
memory::deallocate(ptr);
}
else {
m_allocator.deallocate(cell_size(ptr->m_capacity), ptr);
}
#endif
}
}

View file

@ -196,14 +196,16 @@ class mpz_manager {
mutable mpz_t m_int64_min;
mpz_t * allocate() {
mpz_t * cell;
#ifdef SINGLE_THREAD
mpz_t * cell = reinterpret_cast<mpz_t*>(m_allocator.allocate(sizeof(mpz_t)));
cell = reinterpret_cast<mpz_t*>(m_allocator.allocate(sizeof(mpz_t)));
#else
#if SYNC
mpz_t * cell = reinterpret_cast<mpz_t*>(m_allocator.allocate(sizeof(mpz_t)));
#else
mpz_t * cell = reinterpret_cast<mpz_t*>(memory::allocate(sizeof(mpz_t)));
#endif
if (SYNCH) {
cell = reinterpret_cast<mpz_t*>(memory::allocate(sizeof(mpz_t)));
}
else {
cell = reinterpret_cast<mpz_t*>(m_allocator.allocate(sizeof(mpz_t)));
}
#endif
mpz_init(*cell);
return cell;
@ -215,11 +217,12 @@ class mpz_manager {
#ifdef SINGLE_THREAD
m_allocator.deallocate(sizeof(mpz_t), ptr);
#else
#if SYNC
memory::deallocate(ptr);
#else
m_allocator.deallocate(sizeof(mpz_t), ptr);
#endif
if (SYNCH) {
memory::deallocate(ptr);
}
else {
m_allocator.deallocate(sizeof(mpz_t), ptr);
}
#endif
}
}