Skip to content
Snippets Groups Projects
Commit 2811c054 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: lazier handling of dynamic libraries

- previously always called dlclose on opened libraries when destroying
  the dlLibraryTable. However, by force closing the libraries the
  situation can arise that the library is missing its own code that it
  needs on unload (#1524). This is also sometimes evident when closing
  VTK libraries for runTimePostProcessing (#354, #1585).

- The new default is to not forcibly dlclose any libraries, unless
  the dlcloseOnTerminate OptimisationSwitch specifies otherwise.

  - The dlLibraryTable::close() method can be used to explicitly close
    all libraries and clear the list.

  - The dlLibraryTable::clear() method now only clears the entries,
    without a dlclose.
parent dc037285
Branches
Tags
No related merge requests found
...@@ -140,6 +140,11 @@ OptimisationSwitches ...@@ -140,6 +140,11 @@ OptimisationSwitches
// Force dumping (at next timestep) upon signal (-1 to disable) and exit // Force dumping (at next timestep) upon signal (-1 to disable) and exit
stopAtWriteNowSignal -1; stopAtWriteNowSignal -1;
//- Use dlclose() when clearing the dlLibraryTable.
// This is presumably cleaner, but can also remove functions
// that are still needed (eg, to terminate the library itself)
dlcloseOnTerminate 0;
//- Choose STL ASCII parser: 0=Flex, 1=Ragel, 2=Manual //- Choose STL ASCII parser: 0=Flex, 1=Ragel, 2=Manual
fileFormats::stl 0; fileFormats::stl 0;
......
...@@ -46,6 +46,12 @@ namespace Foam ...@@ -46,6 +46,12 @@ namespace Foam
defineTypeNameAndDebug(dlLibraryTable, 0); defineTypeNameAndDebug(dlLibraryTable, 0);
} }
int Foam::dlLibraryTable::dlcloseOnTerminate
(
Foam::debug::optimisationSwitch("dlcloseOnTerminate", 0)
);
std::unique_ptr<Foam::dlLibraryTable> Foam::dlLibraryTable::global_(nullptr); std::unique_ptr<Foam::dlLibraryTable> Foam::dlLibraryTable::global_(nullptr);
...@@ -238,7 +244,10 @@ Foam::dlLibraryTable::dlLibraryTable ...@@ -238,7 +244,10 @@ Foam::dlLibraryTable::dlLibraryTable
Foam::dlLibraryTable::~dlLibraryTable() Foam::dlLibraryTable::~dlLibraryTable()
{ {
clear(); if (dlLibraryTable::dlcloseOnTerminate)
{
close();
}
} }
...@@ -274,6 +283,13 @@ Foam::label Foam::dlLibraryTable::size() const ...@@ -274,6 +283,13 @@ Foam::label Foam::dlLibraryTable::size() const
} }
void Foam::dlLibraryTable::clear()
{
libPtrs_.clear();
libNames_.clear();
}
Foam::List<Foam::fileName> Foam::dlLibraryTable::loaded() const Foam::List<Foam::fileName> Foam::dlLibraryTable::loaded() const
{ {
List<fileName> list(libNames_.size()); List<fileName> list(libNames_.size());
...@@ -298,7 +314,7 @@ Foam::List<Foam::fileName> Foam::dlLibraryTable::loaded() const ...@@ -298,7 +314,7 @@ Foam::List<Foam::fileName> Foam::dlLibraryTable::loaded() const
} }
void Foam::dlLibraryTable::clear(bool verbose) void Foam::dlLibraryTable::close(bool verbose)
{ {
label nLoaded = 0; label nLoaded = 0;
......
...@@ -99,6 +99,14 @@ class dlLibraryTable ...@@ -99,6 +99,14 @@ class dlLibraryTable
public: public:
// Static Data Members
//- Use dlclose() when clearing the dlLibraryTable.
// This is presumably \em cleaner, but can also remove functions
// that are still needed (eg, to terminate the library itself)
static int dlcloseOnTerminate;
// Public Data Types // Public Data Types
//- Global loader/unloader function type (C-linkage) //- Global loader/unloader function type (C-linkage)
...@@ -229,8 +237,8 @@ public: ...@@ -229,8 +237,8 @@ public:
return libPtrs_; return libPtrs_;
} }
//- Clearing closes all libraries loaded by the table. //- Clears the table, without attempting to close the libraries
void clear(bool verbose = true); void clear();
//- Add to the list of names, but do not yet open. //- Add to the list of names, but do not yet open.
// Ignores duplicate names. // Ignores duplicate names.
...@@ -261,6 +269,10 @@ public: ...@@ -261,6 +269,10 @@ public:
bool verbose = true bool verbose = true
); );
//- Close all libraries loaded by the table and remove the closed
//- functions from the table.
void close(bool verbose = true);
//- Close the named library, optionally warn if problems occur //- Close the named library, optionally warn if problems occur
// Using an empty name is a no-op and always returns false. // Using an empty name is a no-op and always returns false.
bool close(const fileName& libName, bool verbose = true); bool close(const fileName& libName, bool verbose = true);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment