bool DirectoryMonitor::Server::addDirectory(const string& aPath) throw(MonitorException) { { RLock l(cs); if (monitors.find(aPath) != monitors.end()) return false; } init(); Monitor* mon = new Monitor(aPath, this, 0, 32 * 1024, true); try { mon->openDirectory(m_hIOCP); { WLock l(cs); mon->beginRead(); monitors.emplace(aPath, mon); failedDirectories.erase(aPath); } } catch (MonitorException& e) { mon->stopMonitoring(); delete mon; { WLock l(cs); failedDirectories.insert(aPath); } throw e; } return true; }