make Memory pool thread safe

This commit is contained in:
Andreas Fabri 2016-12-02 12:42:49 +01:00 committed by Laurent Rineau
parent 1b2fcdb82a
commit 8972c92a14
2 changed files with 6 additions and 8 deletions

View File

@ -128,7 +128,7 @@ CGAL_GLOBAL_STATE_VAR(extLong, defInputDigits, CORE_posInfty)
/** This value cannot be CORE_INFTY
See also defBigFloatOutputDigits.
(it really should be an int, as in std::cout.setprecision(int)). */
CGAL_GLOBAL_STATE_VAR(CGAL::cpp11::atomic<long>, defOutputDigits, get_static_defBigFloatOutputDigits())
CGAL_GLOBAL_STATE_VAR(CGAL::cpp11::atomic<long>, defOutputDigits, 10) // == get_static_defBigFloatOutputDigits()
/// default input precision in digits for converting a string to a BigFloat
/** This value cannot be CORE_INFTY. */

View File

@ -37,6 +37,7 @@
#include <new> // for placement new
#include <cassert>
#include <CGAL/assertions.h>
#include <CGAL/tss.h>
#include <vector>
namespace CORE {
@ -50,6 +51,7 @@ private:
Thunk* next;
};
typedef MemoryPool<T,nObjects> Self;
public:
MemoryPool() : head( 0 ) {}
@ -78,7 +80,8 @@ public:
void free(void* p);
// Access the corresponding static global allocator.
static MemoryPool<T>& global_allocator() {
static MemoryPool<T,nObjects>& global_allocator() {
CGAL_STATIC_THREAD_LOCAL_VARIABLE_0(Self, memPool);
return memPool;
}
@ -86,14 +89,9 @@ private:
Thunk* head; // next available block in the pool
std::vector<void*> blocks;
private:
// Static global allocator.
static MemoryPool<T, nObjects> memPool;
};
template <class T, int nObjects >
MemoryPool<T, nObjects> MemoryPool<T, nObjects>::memPool;
template< class T, int nObjects >
void* MemoryPool< T, nObjects >::allocate(std::size_t) {
if ( head == 0 ) { // if no more memory in the pool