Fixes #19. Add destructor to ConditionBank.
authorMatt Weiss <mdw55189@gmail.com>
Mon, 16 Jan 2017 16:26:10 +0000 (10:26 -0600)
committerMatt Weiss <mdw55189@gmail.com>
Mon, 16 Jan 2017 16:26:10 +0000 (10:26 -0600)
Added a destructor to the ConditionBank class to deallocate the m_pair array.
Valgrind was used to test the shutdown of samples/MallocTest was clean.

Additional changes were needed in MallocTest to register with and update QSBR
so the table migration would be cleaned up.

junction/striped/ConditionBank.cpp
junction/striped/ConditionBank.h
samples/MallocTest/MallocTest.cpp

index 30aec8783b258337b89854ffc01cb497dd6b6823..5fda2161113359779eaf6da093f09d7c16a4281c 100644 (file)
@@ -1,6 +1,6 @@
 /*------------------------------------------------------------------------
   Junction: Concurrent data structures in C++
-  Copyright (c) 2016 Jeff Preshing
+  Copyright (c) 2016-2017 Jeff Preshing
 
   Distributed under the Simplified BSD License.
   Original location: https://github.com/preshing/junction
@@ -20,6 +20,13 @@ namespace striped {
 
 ConditionBank DefaultConditionBank;
 
+ConditionBank::~ConditionBank() {
+    m_initSpinLock.lock();
+    ConditionPair* pairs = m_pairs.exchange(nullptr, turf::ConsumeRelease);
+    delete [] pairs;
+    m_initSpinLock.unlock();
+}
+
 ConditionPair* ConditionBank::initialize() {
     m_initSpinLock.lock();
     ConditionPair* pairs = m_pairs.loadNonatomic();
index 25566372fdd172fef9f9bf79bd2ba4ae42013e18..163bc31155a35b58d5ff0f9b3701a7ef8ae4a8c8 100644 (file)
@@ -1,6 +1,6 @@
 /*------------------------------------------------------------------------
   Junction: Concurrent data structures in C++
-  Copyright (c) 2016 Jeff Preshing
+  Copyright (c) 2016-2017 Jeff Preshing
 
   Distributed under the Simplified BSD License.
   Original location: https://github.com/preshing/junction
@@ -36,6 +36,8 @@ private:
     ConditionPair* initialize();
 
 public:
+    ~ConditionBank();
+
     ConditionPair& get(void* ptr) {
         ConditionPair* pairs = m_pairs.load(turf::Consume);
         if (!pairs) {
index c0e18cf71091e50b00b22028ec82f648200285b1..3aba8f0c7058fc3d5074ad68fde17ac584a71fa6 100644 (file)
@@ -1,6 +1,6 @@
 /*------------------------------------------------------------------------
   Junction: Concurrent data structures in C++
-  Copyright (c) 2016 Jeff Preshing
+  Copyright (c) 2016-2017 Jeff Preshing
 
   Distributed under the Simplified BSD License.
   Original location: https://github.com/preshing/junction
@@ -22,6 +22,8 @@ int main() {
     junction::extra::MapAdapter::ThreadContext context(adapter, 0);
     junction::extra::MapAdapter::Map map(65536);
 
+    context.registerThread();
+
     ureg population = 0;
     for (ureg i = 0; i < 100; i++) {
 #if TURF_USE_DLMALLOC && TURF_DLMALLOC_FAST_STATS
@@ -31,5 +33,8 @@ int main() {
             map.assign(population + 1, (void*) ((population << 2) | 3));
     }
 
+    context.update();
+    context.unregisterThread();
+
     return 0;
 }