diff --git a/src/util/mpn.h b/src/util/mpn.h index 621f728e0..d9c71c24b 100644 --- a/src/util/mpn.h +++ b/src/util/mpn.h @@ -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(); diff --git a/src/util/mpz.cpp b/src/util/mpz.cpp index a66add988..4d93ea24d 100644 --- a/src/util/mpz.cpp +++ b/src/util/mpz.cpp @@ -187,15 +187,16 @@ mpz_manager::~mpz_manager() { template mpz_cell * mpz_manager::allocate(unsigned capacity) { SASSERT(capacity >= m_init_cell_capacity); + mpz_cell * cell; #ifdef SINGLE_THREAD - mpz_cell * cell = reinterpret_cast(m_allocator.allocate(cell_size(capacity))); + cell = reinterpret_cast(m_allocator.allocate(cell_size(capacity))); #else -#if SYNC - mpz_cell * cell = reinterpret_cast(m_allocator.allocate(cell_size(capacity))); -#else - mpz_cell * cell = reinterpret_cast(memory::allocate(cell_size(capacity))); - -#endif + if (SYNCH) { + cell = reinterpret_cast(memory::allocate(cell_size(capacity))); + } + else { + cell = reinterpret_cast(m_allocator.allocate(cell_size(capacity))); + } #endif cell->m_capacity = capacity; return cell; @@ -207,11 +208,12 @@ void mpz_manager::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 } } diff --git a/src/util/mpz.h b/src/util/mpz.h index 530bebba7..87a9f0b5b 100644 --- a/src/util/mpz.h +++ b/src/util/mpz.h @@ -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(m_allocator.allocate(sizeof(mpz_t))); + cell = reinterpret_cast(m_allocator.allocate(sizeof(mpz_t))); #else -#if SYNC - mpz_t * cell = reinterpret_cast(m_allocator.allocate(sizeof(mpz_t))); -#else - mpz_t * cell = reinterpret_cast(memory::allocate(sizeof(mpz_t))); -#endif + if (SYNCH) { + cell = reinterpret_cast(memory::allocate(sizeof(mpz_t))); + } + else { + cell = reinterpret_cast(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 } }