getfem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Getfem-commits] [getfem-commits] branch master updated: Do not expose s


From: Konstantinos Poulios
Subject: [Getfem-commits] [getfem-commits] branch master updated: Do not expose static member variable outside the compilation unit
Date: Thu, 07 Mar 2024 04:16:22 -0500

This is an automated email from the git hooks/post-receive script.

logari81 pushed a commit to branch master
in repository getfem.

The following commit(s) were added to refs/heads/master by this push:
     new 0d311bf4 Do not expose static member variable outside the compilation 
unit
0d311bf4 is described below

commit 0d311bf45bb9bf5b8f430f01c1b6199dc520da48
Author: Konstantinos Poulios <logari81@gmail.com>
AuthorDate: Thu Mar 7 10:16:12 2024 +0100

    Do not expose static member variable outside the compilation unit
---
 src/bgeot_small_vector.cc       | 18 +++++++++++++++++-
 src/getfem/bgeot_small_vector.h | 11 +++++++----
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/bgeot_small_vector.cc b/src/bgeot_small_vector.cc
index e0a582d0..7cb75108 100644
--- a/src/bgeot_small_vector.cc
+++ b/src/bgeot_small_vector.cc
@@ -23,6 +23,22 @@
 namespace bgeot { 
   block_allocator *static_block_allocator::palloc = 0;
 
+  static_block_allocator::static_block_allocator() {
+    if (!palloc) palloc = &dal::singleton<block_allocator, 1000>::instance();
+  }
+  void static_block_allocator::memstats() {
+      if (palloc) palloc->memstats();
+  }
+  block_allocator& static_block_allocator::allocator() const {
+    return *palloc;
+  }
+  bool static_block_allocator::allocator_destroyed() const {
+    return palloc == 0;
+  }
+  void static_block_allocator::destroy() {
+    palloc = 0;
+  }
+
   block_allocator::block_allocator() {
     for (size_type i=0; i < OBJ_SIZE_LIMIT; ++i) 
       first_unfilled[i] = i ? size_type(-1) : 0; 
@@ -32,7 +48,7 @@ namespace bgeot {
   block_allocator::~block_allocator() {
     for (size_type i=0; i < blocks.size(); ++i) 
       if (!blocks[i].empty()) blocks[i].clear();
-    static_block_allocator::palloc = 0;
+    static_block_allocator().destroy();
   }
   block_allocator::node_id 
block_allocator::allocate(block_allocator::size_type n) {
     if (n == 0) return 0;
diff --git a/src/getfem/bgeot_small_vector.h b/src/getfem/bgeot_small_vector.h
index e0aa95ad..95be0a6b 100644
--- a/src/getfem/bgeot_small_vector.h
+++ b/src/getfem/bgeot_small_vector.h
@@ -147,11 +147,16 @@ namespace bgeot {
   };
 
   /* common class for all mini_vec, provides access to the common static 
allocator */
-  struct APIDECL static_block_allocator {
+  class APIDECL static_block_allocator {
     /* must be a pointer ... sgi CC is not able to order correctly the
        destructors of static variables */
     static block_allocator *palloc;
-    static_block_allocator() { if (!palloc) 
palloc=&dal::singleton<block_allocator,1000>::instance(); } //new 
block_allocator(); }
+  public:
+    static_block_allocator();
+    void memstats();
+    block_allocator& allocator() const;
+    bool allocator_destroyed() const;
+    void destroy();
   };
 
 #ifdef GETFEM_HAS_OPENMP
@@ -329,8 +334,6 @@ namespace bgeot {
     const_pointer const_base() const {
       SVEC_ASSERT(id == 0 || refcnt()); return 
static_cast<pointer>(allocator().obj_data(id));
     }
-    block_allocator& allocator() const { return *palloc; }
-    bool allocator_destroyed() const { return palloc == 0; }
     node_id allocate(size_type n) {
       return 
node_id(allocator().allocate(gmm::uint32_type(n*sizeof(value_type)))); 
SVEC_ASSERT(refcnt() == 1);
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]