| 111 | |
| 112 | |
| 113 | void Foam::codedBase::unloadLibrary |
| 114 | ( |
| 115 | const fileName& libPath, |
| 116 | const string& globalFuncName, |
| 117 | const dictionary& contextDict |
| 118 | ) const |
| 119 | { |
| 120 | void* lib = 0; |
| 121 | |
| 122 | if (libPath.empty()) |
| 123 | { |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | lib = libs().findLibrary(libPath); |
| 128 | |
| 129 | if (!lib) |
| 130 | { |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | // provision for manual execution of code before unloading |
| 135 | if (dlSymFound(lib, globalFuncName)) |
| 136 | { |
| 137 | loaderFunctionType function = |
| 138 | reinterpret_cast<loaderFunctionType> |
| 139 | ( |
| 140 | dlSym(lib, globalFuncName) |
| 141 | ); |
| 142 | |
| 143 | if (function) |
| 144 | { |
| 145 | (*function)(false); // force unload |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | FatalIOErrorInFunction |
| 150 | ( |
| 151 | contextDict |
| 152 | ) << "Failed looking up symbol " << globalFuncName << nl |
| 153 | << "from " << libPath << exit(FatalIOError); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | if (!libs().close(libPath, false)) |
| 158 | { |
| 159 | FatalIOErrorInFunction |
| 160 | ( |
| 161 | contextDict |
| 162 | ) << "Failed unloading library " << libPath |
| 163 | << exit(FatalIOError); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | |
| 168 | // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // |
no test coverage detected