lifetime of BlockAllocator, and mutex

This commit is contained in:
Joachim Schöberl 2019-07-09 00:23:09 +02:00
parent 933c93da3a
commit 2c14dd6350
5 changed files with 9 additions and 5 deletions

View File

@ -170,6 +170,8 @@ namespace netgen
/// store splinesurfaces, such that added ones do not get deleted before geometry does /// store splinesurfaces, such that added ones do not get deleted before geometry does
Array<shared_ptr<SplineSurface>> spline_surfaces; Array<shared_ptr<SplineSurface>> spline_surfaces;
shared_ptr<BlockAllocator> solid_ball = Solid::ball;
public: public:
CSGeometry (); CSGeometry ();
CSGeometry (const string & afilename); CSGeometry (const string & afilename);

View File

@ -1842,5 +1842,6 @@ namespace netgen
BlockAllocator Solid :: ball(sizeof (Solid)); // BlockAllocator Solid :: ball(sizeof (Solid));
shared_ptr<BlockAllocator> Solid :: ball = make_shared<BlockAllocator>(sizeof (Solid));
} }

View File

@ -161,15 +161,15 @@ namespace netgen
static Solid * CreateSolid (istream & ist, const SymbolTable<Solid*> & solids); static Solid * CreateSolid (istream & ist, const SymbolTable<Solid*> & solids);
static BlockAllocator ball; static shared_ptr<BlockAllocator> ball;
void * operator new(size_t /* s */) void * operator new(size_t /* s */)
{ {
return ball.Alloc(); return ball->Alloc();
} }
void operator delete (void * p) void operator delete (void * p)
{ {
ball.Free (p); ball->Free (p);
} }

View File

@ -14,7 +14,7 @@
namespace netgen namespace netgen
{ {
static mutex block_allocator_mutex; // static mutex block_allocator_mutex;
BlockAllocator :: BlockAllocator (unsigned asize, unsigned ablocks) BlockAllocator :: BlockAllocator (unsigned asize, unsigned ablocks)
: bablocks (0) : bablocks (0)

View File

@ -23,6 +23,7 @@ private:
void * freelist; void * freelist;
/// ///
Array<char*> bablocks; Array<char*> bablocks;
mutex block_allocator_mutex;
public: public:
/// ///
BlockAllocator (unsigned asize, unsigned ablocks = 100); BlockAllocator (unsigned asize, unsigned ablocks = 100);