Commit 7e0f1e2a authored by mattijs's avatar mattijs
Browse files

ENH: allocate fileMonitor only if wanted

parent 0ad7b2cd
......@@ -159,15 +159,21 @@ namespace Foam
{
if (inotifyFd_ < 0)
{
WarningIn("fileMonitorWatcher(const label)")
<< "Failed allocating an inotify descriptor : "
<< string(strerror(errno)) << endl
<< " Please increase the number of allowable "
<< "inotify instances" << endl
<< " (/proc/sys/fs/inotify/max_user_instances on Linux)"
<< endl
<< " Continuing without additional file monitoring."
<< endl;
static bool hasWarned = false;
if (!hasWarned)
{
hasWarned = true;
WarningIn("fileMonitorWatcher(const label)")
<< "Failed allocating an inotify descriptor : "
<< string(strerror(errno)) << endl
<< " Please increase the number of allowable "
<< "inotify instances" << endl
<< " (/proc/sys/fs/inotify/max_user_instances"
<< " on Linux)" << endl
<< " or switch off runTimeModifiable." << endl
<< " Continuing without additional file monitoring."
<< endl;
}
}
}
......
......@@ -250,6 +250,7 @@ Foam::Time::Time
// Time objects not registered so do like objectRegistry::checkIn ourselves.
if (runTimeModifiable_)
{
monitorPtr_.reset(new fileMonitor());
controlDict_.watchIndex() = addWatch(controlDict_.filePath());
}
}
......@@ -312,6 +313,8 @@ Foam::Time::Time
// Time objects not registered so do like objectRegistry::checkIn ourselves.
if (runTimeModifiable_)
{
monitorPtr_.reset(new fileMonitor());
// File might not exist yet.
fileName f(controlDict_.filePath());
if (f != fileName::null)
......@@ -392,18 +395,18 @@ Foam::Time::~Time()
Foam::label Foam::Time::addWatch(const fileName& fName) const
{
return monitor_.addWatch(fName);
return monitorPtr_().addWatch(fName);
}
bool Foam::Time::removeWatch(const label watchIndex) const
{
return monitor_.removeWatch(watchIndex);
return monitorPtr_().removeWatch(watchIndex);
}
const Foam::fileName& Foam::Time::getFile(const label watchIndex) const
{
return monitor_.getFile(watchIndex);
return monitorPtr_().getFile(watchIndex);
}
......@@ -412,13 +415,13 @@ Foam::fileMonitor::fileState Foam::Time::getState
const label watchFd
) const
{
return monitor_.getState(watchFd);
return monitorPtr_().getState(watchFd);
}
void Foam::Time::setUnmodified(const label watchFd) const
{
monitor_.setUnmodified(watchFd);
monitorPtr_().setUnmodified(watchFd);
}
......
......@@ -73,7 +73,7 @@ class Time
// Private data
//- file-change monitor for all registered files
mutable fileMonitor monitor_;
mutable autoPtr<fileMonitor> monitorPtr_;
//- The controlDict
IOdictionary controlDict_;
......
......@@ -211,10 +211,7 @@ void Foam::Time::readModifiedObjects()
// valid filePath).
// Note: requires same ordering in objectRegistries on different
// processors!
monitor_.updateStates(Pstream::parRun());
//Pout<< "Time : runTimeModifiable_ and watchIndex:"
// << controlDict_.watchIndex() << endl;
monitorPtr_().updateStates(Pstream::parRun());
// Time handling is special since controlDict_ is the one dictionary
// that is not registered to any database.
......
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