mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: minor code cleanup for codeStream/codedFixedValueFvPatchScalarField
This commit is contained in:
@ -98,21 +98,20 @@ bool Foam::functionEntries::codeStream::execute
|
||||
// see if library is loaded
|
||||
void* lib = dlLibraryTable::findLibrary(libPath);
|
||||
|
||||
bool reuseLib = false;
|
||||
|
||||
// nothing loaded
|
||||
// avoid compilation if possible by loading an existing library
|
||||
if (!lib && dlLibraryTable::open(libPath, false))
|
||||
{
|
||||
lib = dlLibraryTable::findLibrary(libPath);
|
||||
reuseLib = true;
|
||||
}
|
||||
|
||||
|
||||
// create library if required
|
||||
if (!lib)
|
||||
{
|
||||
if (Pstream::master())
|
||||
bool create = Pstream::master();
|
||||
|
||||
if (create)
|
||||
{
|
||||
if (!dynCode.upToDate(context))
|
||||
{
|
||||
@ -137,7 +136,7 @@ bool Foam::functionEntries::codeStream::execute
|
||||
"functionEntries::codeStream::execute(..)",
|
||||
parentDict
|
||||
) << "Failed writing files for" << nl
|
||||
<< dynCode.libPath() << nl
|
||||
<< dynCode.libRelPath() << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
@ -148,14 +147,13 @@ bool Foam::functionEntries::codeStream::execute
|
||||
(
|
||||
"functionEntries::codeStream::execute(..)",
|
||||
parentDict
|
||||
) << "Failed wmake " << libPath
|
||||
) << "Failed wmake " << dynCode.libRelPath() << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
// all processes must wait for compile
|
||||
bool waiting = true;
|
||||
reduce(waiting, orOp<bool>());
|
||||
// all processes must wait for compile to finish
|
||||
reduce(create, orOp<bool>());
|
||||
|
||||
if (!dlLibraryTable::open(libPath, false))
|
||||
{
|
||||
@ -163,21 +161,17 @@ bool Foam::functionEntries::codeStream::execute
|
||||
(
|
||||
"functionEntries::codeStream::execute(..)",
|
||||
parentDict
|
||||
) << "Failed loading library " << libPath
|
||||
) << "Failed loading library " << libPath << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
lib = dlLibraryTable::findLibrary(libPath);
|
||||
}
|
||||
else if (reuseLib)
|
||||
{
|
||||
Info<< "Reusing library in " << libPath << endl;
|
||||
}
|
||||
|
||||
|
||||
// Find the function handle in the library
|
||||
void (*function)(Ostream&, const dictionary&);
|
||||
function = reinterpret_cast<void(*)(Ostream&, const dictionary&)>
|
||||
streamingFunctionType function =
|
||||
reinterpret_cast<streamingFunctionType>
|
||||
(
|
||||
dlSym(lib, dynCode.codeName())
|
||||
);
|
||||
|
||||
@ -109,6 +109,11 @@ class codeStream
|
||||
:
|
||||
public functionEntry
|
||||
{
|
||||
|
||||
//- Interpreter function type
|
||||
typedef void (*streamingFunctionType)(Ostream&, const dictionary&);
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
|
||||
@ -47,32 +47,6 @@ const Foam::word Foam::codedFixedValueFvPatchScalarField::codeTemplateH
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
|
||||
Foam::string Foam::codedFixedValueFvPatchScalarField::libraryGlobalName
|
||||
(
|
||||
const fileName& libPath
|
||||
)
|
||||
{
|
||||
// global function name (SHA1-encoded)
|
||||
// that can be used for version control and/or explicit loading/unloading
|
||||
string globalFuncName = libPath.name();
|
||||
|
||||
// remove ".so" extension
|
||||
string::size_type dot = globalFuncName.find('.');
|
||||
if (dot != string::npos)
|
||||
{
|
||||
globalFuncName.resize(dot);
|
||||
}
|
||||
|
||||
// remove leading 'lib' from name
|
||||
globalFuncName.erase(0, 3);
|
||||
|
||||
return globalFuncName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void* Foam::codedFixedValueFvPatchScalarField::loadLibrary
|
||||
(
|
||||
const fileName& libPath,
|
||||
@ -82,20 +56,17 @@ void* Foam::codedFixedValueFvPatchScalarField::loadLibrary
|
||||
{
|
||||
void* lib = 0;
|
||||
|
||||
// global function name (SHA1-encoded)
|
||||
// that can be used for version control and/or explicit loading/unloading
|
||||
|
||||
// avoid compilation by loading an existing library
|
||||
if (dlLibraryTable::open(libPath, false))
|
||||
if (!libPath.empty() && dlLibraryTable::open(libPath, false))
|
||||
{
|
||||
lib = dlLibraryTable::findLibrary(libPath);
|
||||
|
||||
// verify the loaded version and unload if needed
|
||||
if (lib)
|
||||
{
|
||||
// provision for manual execution of code after loading
|
||||
if (dlSymFound(lib, globalFuncName))
|
||||
{
|
||||
// Find the function handle in the library
|
||||
loaderFunctionType function =
|
||||
reinterpret_cast<loaderFunctionType>
|
||||
(
|
||||
@ -104,8 +75,7 @@ void* Foam::codedFixedValueFvPatchScalarField::loadLibrary
|
||||
|
||||
if (function)
|
||||
{
|
||||
// force load
|
||||
(*function)(true);
|
||||
(*function)(true); // force load
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -152,7 +122,12 @@ void Foam::codedFixedValueFvPatchScalarField::unloadLibrary
|
||||
const dictionary& contextDict
|
||||
)
|
||||
{
|
||||
void* lib = dlLibraryTable::findLibrary(libPath);
|
||||
void* lib = 0;
|
||||
|
||||
if (!libPath.empty())
|
||||
{
|
||||
lib = dlLibraryTable::findLibrary(libPath);
|
||||
}
|
||||
|
||||
if (!lib)
|
||||
{
|
||||
@ -162,7 +137,6 @@ void Foam::codedFixedValueFvPatchScalarField::unloadLibrary
|
||||
// provision for manual execution of code before unloading
|
||||
if (dlSymFound(lib, globalFuncName))
|
||||
{
|
||||
// Find the function handle in the library
|
||||
loaderFunctionType function =
|
||||
reinterpret_cast<loaderFunctionType>
|
||||
(
|
||||
@ -171,8 +145,7 @@ void Foam::codedFixedValueFvPatchScalarField::unloadLibrary
|
||||
|
||||
if (function)
|
||||
{
|
||||
// force unload
|
||||
(*function)(false);
|
||||
(*function)(false); // force unload
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -181,8 +154,7 @@ void Foam::codedFixedValueFvPatchScalarField::unloadLibrary
|
||||
"codedFixedValueFvPatchScalarField::unloadLibrary()",
|
||||
contextDict
|
||||
) << "Failed looking up symbol " << globalFuncName << nl
|
||||
<< "from " << libPath
|
||||
<< exit(FatalIOError);
|
||||
<< "from " << libPath << exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,9 +204,13 @@ void Foam::codedFixedValueFvPatchScalarField::createLibrary
|
||||
dynamicCode& dynCode,
|
||||
const dynamicCodeContext& context
|
||||
) const
|
||||
{
|
||||
bool create = Pstream::master();
|
||||
|
||||
if (create)
|
||||
{
|
||||
// Write files for new library
|
||||
if (Pstream::master() && !dynCode.upToDate(context))
|
||||
if (!dynCode.upToDate(context))
|
||||
{
|
||||
// filter with this context
|
||||
dynCode.reset(context);
|
||||
@ -266,13 +242,28 @@ void Foam::codedFixedValueFvPatchScalarField::createLibrary
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
|
||||
"codedFixedValueFvPatchScalarField::createLibrary(..)",
|
||||
context.dict()
|
||||
) << "Failed writing files for" << nl
|
||||
<< dynCode.libPath() << nl
|
||||
<< dynCode.libRelPath() << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
if (!dynCode.wmakeLibso())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::createLibrary(..)",
|
||||
context.dict()
|
||||
) << "Failed wmake " << dynCode.libRelPath() << nl
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// all processes must wait for compile to finish
|
||||
reduce(create, orOp<bool>());
|
||||
}
|
||||
|
||||
|
||||
@ -294,7 +285,6 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() const
|
||||
|
||||
dynamicCodeContext context(codeDict);
|
||||
|
||||
|
||||
// codeName: redirectType + _<sha1>
|
||||
// codeDir : redirectType
|
||||
dynamicCode dynCode
|
||||
@ -305,77 +295,33 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() const
|
||||
const fileName libPath = dynCode.libPath();
|
||||
|
||||
|
||||
// see if library is loaded
|
||||
void* lib = dlLibraryTable::findLibrary(libPath);
|
||||
|
||||
// library not loaded, and also need to unload old version
|
||||
if (!lib && !oldLibPath_.empty())
|
||||
{
|
||||
// unload code
|
||||
// Remove instantiation of fvPatchField provided by library
|
||||
redirectPatchFieldPtr_.clear();
|
||||
|
||||
unloadLibrary
|
||||
(
|
||||
oldLibPath_,
|
||||
libraryGlobalName(oldLibPath_),
|
||||
context.dict()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// retain for future reference
|
||||
oldLibPath_ = libPath;
|
||||
|
||||
bool waiting = false;
|
||||
|
||||
if (lib)
|
||||
// the correct library was already loaded => we are done
|
||||
if (dlLibraryTable::findLibrary(libPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove instantiation of fvPatchField provided by library
|
||||
// remove instantiation of fvPatchField provided by library
|
||||
redirectPatchFieldPtr_.clear();
|
||||
|
||||
// avoid compilation by loading an existing library
|
||||
lib = loadLibrary
|
||||
// may need to unload old library
|
||||
unloadLibrary
|
||||
(
|
||||
libPath,
|
||||
dynCode.codeName(),
|
||||
oldLibPath_,
|
||||
dynamicCode::libraryBaseName(oldLibPath_),
|
||||
context.dict()
|
||||
);
|
||||
|
||||
|
||||
// really do need to create library
|
||||
if (!lib)
|
||||
{
|
||||
if (Pstream::master())
|
||||
// try loading an existing library (avoid compilation when possible)
|
||||
if (!loadLibrary(libPath, dynCode.codeName(), context.dict()))
|
||||
{
|
||||
createLibrary(dynCode, context);
|
||||
|
||||
if (!dynCode.wmakeLibso())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::updateLibrary()",
|
||||
context.dict()
|
||||
) << "Failed wmake " << libPath
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
loadLibrary(libPath, dynCode.codeName(), context.dict());
|
||||
}
|
||||
|
||||
// all processes must wait for compile
|
||||
waiting = true;
|
||||
reduce(waiting, orOp<bool>());
|
||||
|
||||
// load newly compiled libray
|
||||
lib = loadLibrary
|
||||
(
|
||||
libPath,
|
||||
dynCode.codeName(),
|
||||
context.dict()
|
||||
);
|
||||
}
|
||||
// retain for future reference
|
||||
oldLibPath_ = libPath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -114,13 +114,11 @@ class codedFixedValueFvPatchScalarField
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
// Generic library management pieces
|
||||
const IOdictionary& dict() const;
|
||||
|
||||
//- Global loader/unloader function type
|
||||
typedef void (*loaderFunctionType)(bool);
|
||||
|
||||
static string libraryGlobalName(const fileName& libPath);
|
||||
|
||||
static void* loadLibrary
|
||||
(
|
||||
const fileName& libPath,
|
||||
@ -136,13 +134,12 @@ class codedFixedValueFvPatchScalarField
|
||||
);
|
||||
|
||||
|
||||
const IOdictionary& dict() const;
|
||||
|
||||
void createLibrary(dynamicCode&, const dynamicCodeContext&) const;
|
||||
|
||||
//- Update library as required
|
||||
void updateLibrary() const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Static data members
|
||||
|
||||
Reference in New Issue
Block a user