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
......@@ -140,6 +140,11 @@ OptimisationSwitches
// Force dumping (at next timestep) upon signal (-1 to disable) and exit
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
fileFormats::stl 0;
......
......@@ -46,6 +46,12 @@ namespace Foam
defineTypeNameAndDebug(dlLibraryTable, 0);
}
int Foam::dlLibraryTable::dlcloseOnTerminate
(
Foam::debug::optimisationSwitch("dlcloseOnTerminate", 0)
);
std::unique_ptr<Foam::dlLibraryTable> Foam::dlLibraryTable::global_(nullptr);
......@@ -238,7 +244,10 @@ Foam::dlLibraryTable::dlLibraryTable
Foam::dlLibraryTable::~dlLibraryTable()
{
clear();
if (dlLibraryTable::dlcloseOnTerminate)
{
close();
}
}
......@@ -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
{
List<fileName> list(libNames_.size());
......@@ -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;
......
......@@ -99,6 +99,14 @@ class dlLibraryTable
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
//- Global loader/unloader function type (C-linkage)
......@@ -229,8 +237,8 @@ public:
return libPtrs_;
}
//- Clearing closes all libraries loaded by the table.
void clear(bool verbose = true);
//- Clears the table, without attempting to close the libraries
void clear();
//- Add to the list of names, but do not yet open.
// Ignores duplicate names.
......@@ -261,6 +269,10 @@ public:
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
// Using an empty name is a no-op and always returns false.
bool close(const fileName& libName, bool verbose = true);
......
Markdown is supported
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