Skip to content
Snippets Groups Projects
Commit cd06ce09 authored by David C. Lonie's avatar David C. Lonie
Browse files

Add Schwartz counters for consistent static destruction.

Static builds of paraview were not freeing
vtkObjectFactory::RegisteredFactories or vtkOutputWindow::Instance. See:

https://open.cdash.org/viewTest.php?onlyfailed&buildid=4572721

This fixes the issue to ensure that they are always freed at process exit.
parent 874a7d8b
No related branches found
No related tags found
No related merge requests found
......@@ -27,21 +27,20 @@
vtkObjectFactoryCollection* vtkObjectFactory::RegisteredFactories = 0;
static unsigned int vtkObjectFactoryRegistryCleanupCounter = 0;
vtkObjectFactoryRegistryCleanup::vtkObjectFactoryRegistryCleanup()
{
++vtkObjectFactoryRegistryCleanupCounter;
}
class vtkCleanUpObjectFactory
vtkObjectFactoryRegistryCleanup::~vtkObjectFactoryRegistryCleanup()
{
public:
inline void Use()
{
}
~vtkCleanUpObjectFactory()
if (--vtkObjectFactoryRegistryCleanupCounter == 0)
{
vtkObjectFactory::UnRegisterAllFactories();
vtkObjectFactory::UnRegisterAllFactories();
}
};
static vtkCleanUpObjectFactory vtkCleanUpObjectFactoryGlobal;
}
// Create an instance of a named vtk object using the loaded
// factories
......@@ -88,7 +87,6 @@ void vtkObjectFactory::ConstructInstance(const char *vtkclassname)
// A one time initialization method.
void vtkObjectFactory::Init()
{
vtkCleanUpObjectFactoryGlobal.Use();
// Don't do anything if we are already initialized
if(vtkObjectFactory::RegisteredFactories)
{
......@@ -737,4 +735,3 @@ void vtkObjectFactory::CreateAllInstance(const char* vtkclassname,
}
}
}
......@@ -38,6 +38,7 @@
#ifndef vtkObjectFactory_h
#define vtkObjectFactory_h
#include "vtkDebugLeaksManager.h" // Must be included before singletons
#include "vtkCommonCoreModule.h" // For export macro
#include "vtkObject.h"
......@@ -286,6 +287,20 @@ private:
void operator=(const vtkObjectFactory&) VTK_DELETE_FUNCTION;
};
// Implementation detail for Schwartz counter idiom.
class VTKCOMMONCORE_EXPORT vtkObjectFactoryRegistryCleanup
{
public:
vtkObjectFactoryRegistryCleanup();
~vtkObjectFactoryRegistryCleanup();
private:
vtkObjectFactoryRegistryCleanup(const vtkObjectFactoryRegistryCleanup& other) VTK_DELETE_FUNCTION;
vtkObjectFactoryRegistryCleanup& operator=(const vtkObjectFactoryRegistryCleanup& rhs) VTK_DELETE_FUNCTION;
};
static vtkObjectFactoryRegistryCleanup vtkObjectFactoryRegistryCleanupInstance;
// Macro to create an object creation function.
// The name of the function will by vtkObjectFactoryCreateclassname
// where classname is the name of the class being created
......
......@@ -22,13 +22,10 @@
#endif
#include "vtkCommand.h"
#include "vtkObjectFactory.h"
#include "vtkDebugLeaks.h"
//----------------------------------------------------------------------------
vtkOutputWindow* vtkOutputWindow::Instance = 0;
vtkOutputWindowCleanup vtkOutputWindow::Cleanup;
static unsigned int vtkOutputWindowCleanupCounter = 0;
void vtkOutputWindowDisplayText(const char* message)
{
......@@ -57,12 +54,16 @@ void vtkOutputWindowDisplayDebugText(const char* message)
vtkOutputWindowCleanup::vtkOutputWindowCleanup()
{
++vtkOutputWindowCleanupCounter;
}
vtkOutputWindowCleanup::~vtkOutputWindowCleanup()
{
// Destroy any remaining output window.
vtkOutputWindow::SetInstance(0);
if (--vtkOutputWindowCleanupCounter == 0)
{
// Destroy any remaining output window.
vtkOutputWindow::SetInstance(0);
}
}
vtkOutputWindow::vtkOutputWindow()
......
......@@ -25,6 +25,7 @@
#ifndef vtkOutputWindow_h
#define vtkOutputWindow_h
#include "vtkDebugLeaksManager.h" // Must be included before singletons
#include "vtkCommonCoreModule.h" // For export macro
#include "vtkObject.h"
......@@ -89,11 +90,6 @@ public:
vtkSetMacro(PromptUser, int);
//@}
// use this as a way of memory management when the
// program exits the SmartPointer will be deleted which
// will delete the Instance singleton
static vtkOutputWindowCleanup Cleanup;
protected:
vtkOutputWindow();
~vtkOutputWindow() VTK_OVERRIDE;
......@@ -105,4 +101,8 @@ private:
void operator=(const vtkOutputWindow&) VTK_DELETE_FUNCTION;
};
// Uses schwartz counter idiom for singleton management
static vtkOutputWindowCleanup vtkOutputWindowCleanupInstance;
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment