BUG: fileMonitor: do not allow used watch also in free watches.

See #1328.
This commit is contained in:
mattijs
2019-06-12 12:27:28 +01:00
committed by Andrew Heather
parent fc58d517f0
commit 3ef37ce188
2 changed files with 22 additions and 12 deletions

View File

@ -450,14 +450,16 @@ Foam::fileMonitor::~fileMonitor()
// regIOobject) // regIOobject)
Foam::label Foam::fileMonitor::addWatch(const fileName& fName) Foam::label Foam::fileMonitor::addWatch(const fileName& fName)
{ {
if (debug)
{
Pout<< "fileMonitor : adding watch on file " << fName << endl;
}
label watchFd; label watchFd;
label sz = freeWatchFds_.size(); if (freeWatchFds_.size())
if (sz)
{ {
watchFd = freeWatchFds_[sz-1]; watchFd = freeWatchFds_.remove();
freeWatchFds_.setSize(sz-1);
} }
else else
{ {
@ -495,7 +497,10 @@ bool Foam::fileMonitor::removeWatch(const label watchFd)
<< watchFile_[watchFd] << endl; << watchFile_[watchFd] << endl;
} }
if (!freeWatchFds_.found(watchFd))
{
freeWatchFds_.append(watchFd); freeWatchFds_.append(watchFd);
}
return watcher_->removeWatch(watchFd); return watcher_->removeWatch(watchFd);
} }

View File

@ -446,14 +446,16 @@ Foam::fileMonitor::~fileMonitor()
// regIOobject) // regIOobject)
Foam::label Foam::fileMonitor::addWatch(const fileName& fName) Foam::label Foam::fileMonitor::addWatch(const fileName& fName)
{ {
if (debug)
{
Pout<< "fileMonitor : adding watch on file " << fName << endl;
}
label watchFd; label watchFd;
label sz = freeWatchFds_.size(); if (freeWatchFds_.size())
if (sz)
{ {
watchFd = freeWatchFds_[sz-1]; watchFd = freeWatchFds_.remove();
freeWatchFds_.setSize(sz-1);
} }
else else
{ {
@ -491,7 +493,10 @@ bool Foam::fileMonitor::removeWatch(const label watchFd)
<< watchFile_[watchFd] << endl; << watchFile_[watchFd] << endl;
} }
if (!freeWatchFds_.found(watchFd))
{
freeWatchFds_.append(watchFd); freeWatchFds_.append(watchFd);
}
return watcher_->removeWatch(watchFd); return watcher_->removeWatch(watchFd);
} }