From 2c14dd6350f9925baaf7681a91e98b4a8a87c28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 9 Jul 2019 00:23:09 +0200 Subject: [PATCH] lifetime of BlockAllocator, and mutex --- libsrc/csg/csgeom.hpp | 2 ++ libsrc/csg/solid.cpp | 3 ++- libsrc/csg/solid.hpp | 6 +++--- libsrc/general/optmem.cpp | 2 +- libsrc/general/optmem.hpp | 1 + 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libsrc/csg/csgeom.hpp b/libsrc/csg/csgeom.hpp index 40d90d51..dc5a4d4f 100644 --- a/libsrc/csg/csgeom.hpp +++ b/libsrc/csg/csgeom.hpp @@ -170,6 +170,8 @@ namespace netgen /// store splinesurfaces, such that added ones do not get deleted before geometry does Array> spline_surfaces; + shared_ptr solid_ball = Solid::ball; + public: CSGeometry (); CSGeometry (const string & afilename); diff --git a/libsrc/csg/solid.cpp b/libsrc/csg/solid.cpp index c61f4e39..d11973ab 100644 --- a/libsrc/csg/solid.cpp +++ b/libsrc/csg/solid.cpp @@ -1842,5 +1842,6 @@ namespace netgen - BlockAllocator Solid :: ball(sizeof (Solid)); + // BlockAllocator Solid :: ball(sizeof (Solid)); + shared_ptr Solid :: ball = make_shared(sizeof (Solid)); } diff --git a/libsrc/csg/solid.hpp b/libsrc/csg/solid.hpp index 33592345..c78e6af8 100644 --- a/libsrc/csg/solid.hpp +++ b/libsrc/csg/solid.hpp @@ -161,15 +161,15 @@ namespace netgen static Solid * CreateSolid (istream & ist, const SymbolTable & solids); - static BlockAllocator ball; + static shared_ptr ball; void * operator new(size_t /* s */) { - return ball.Alloc(); + return ball->Alloc(); } void operator delete (void * p) { - ball.Free (p); + ball->Free (p); } diff --git a/libsrc/general/optmem.cpp b/libsrc/general/optmem.cpp index 73ca693b..40cfb4c5 100644 --- a/libsrc/general/optmem.cpp +++ b/libsrc/general/optmem.cpp @@ -14,7 +14,7 @@ namespace netgen { - static mutex block_allocator_mutex; + // static mutex block_allocator_mutex; BlockAllocator :: BlockAllocator (unsigned asize, unsigned ablocks) : bablocks (0) diff --git a/libsrc/general/optmem.hpp b/libsrc/general/optmem.hpp index 658bf055..0d2b9de7 100644 --- a/libsrc/general/optmem.hpp +++ b/libsrc/general/optmem.hpp @@ -23,6 +23,7 @@ private: void * freelist; /// Array bablocks; + mutex block_allocator_mutex; public: /// BlockAllocator (unsigned asize, unsigned ablocks = 100);