diff --git a/etc/controlDict b/etc/controlDict index 1bacba34532ba0caa53dd0d158f28fcea0258ad6..d928d90a74883b707853279d1284911d2fc366b8 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -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; diff --git a/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C index 54b3feca21b10ddee05fe480b6e454afe4c3008a..9a5ad023d9f9d72bdb658b769944a0f7c641018f 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C +++ b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C @@ -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; diff --git a/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.H b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.H index a89df8f90854e65b8c53437bbaf9d561ce8e44fe..8fa2f99a0247285d33a9fe37c39cec233415ec70 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.H +++ b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.H @@ -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);