diff --git a/src/OSspecific/MSwindows/fileMonitor/fileMonitor.C b/src/OSspecific/MSwindows/fileMonitor/fileMonitor.C index 425a0c333d006645d06d87c4fbf2de751ea3d76a..b40c49c48467d8fc78ab1cb3c0430a6e366887e8 100644 --- a/src/OSspecific/MSwindows/fileMonitor/fileMonitor.C +++ b/src/OSspecific/MSwindows/fileMonitor/fileMonitor.C @@ -450,14 +450,16 @@ Foam::fileMonitor::~fileMonitor() // regIOobject) Foam::label Foam::fileMonitor::addWatch(const fileName& fName) { - label watchFd; + if (debug) + { + Pout<< "fileMonitor : adding watch on file " << fName << endl; + } - label sz = freeWatchFds_.size(); + label watchFd; - if (sz) + if (freeWatchFds_.size()) { - watchFd = freeWatchFds_[sz-1]; - freeWatchFds_.setSize(sz-1); + watchFd = freeWatchFds_.remove(); } else { @@ -495,7 +497,10 @@ bool Foam::fileMonitor::removeWatch(const label watchFd) << watchFile_[watchFd] << endl; } - freeWatchFds_.append(watchFd); + if (!freeWatchFds_.found(watchFd)) + { + freeWatchFds_.append(watchFd); + } return watcher_->removeWatch(watchFd); } diff --git a/src/OSspecific/POSIX/fileMonitor/fileMonitor.C b/src/OSspecific/POSIX/fileMonitor/fileMonitor.C index f8f9a46af72a1650ae827c5d8ffac8bd9789aeb0..80b5b4044dec779712231a77c2c0ce4ea8f52442 100644 --- a/src/OSspecific/POSIX/fileMonitor/fileMonitor.C +++ b/src/OSspecific/POSIX/fileMonitor/fileMonitor.C @@ -446,14 +446,16 @@ Foam::fileMonitor::~fileMonitor() // regIOobject) Foam::label Foam::fileMonitor::addWatch(const fileName& fName) { - label watchFd; + if (debug) + { + Pout<< "fileMonitor : adding watch on file " << fName << endl; + } - label sz = freeWatchFds_.size(); + label watchFd; - if (sz) + if (freeWatchFds_.size()) { - watchFd = freeWatchFds_[sz-1]; - freeWatchFds_.setSize(sz-1); + watchFd = freeWatchFds_.remove(); } else { @@ -491,7 +493,10 @@ bool Foam::fileMonitor::removeWatch(const label watchFd) << watchFile_[watchFd] << endl; } - freeWatchFds_.append(watchFd); + if (!freeWatchFds_.found(watchFd)) + { + freeWatchFds_.append(watchFd); + } return watcher_->removeWatch(watchFd); }