diff --git a/Utils.h b/Utils.h index 080a6f8e..a94513a5 100644 --- a/Utils.h +++ b/Utils.h @@ -14,6 +14,7 @@ #include #include #include +#include #include using std::map; @@ -109,53 +110,17 @@ public: } //! timeout in milliseconds - bool TryExLock(const CString& sLockFile, unsigned long long iTimeout = 0, bool bRw = false) { + bool TryExLock(const CString& sLockFile, bool bRw = false) { Open(sLockFile, bRw); - return TryExLock(iTimeout); + return TryExLock(); } - bool TryExLock(unsigned long long iTimeout = 0) { - if (iTimeout == 0) { - return Lock(LOCK_EX|LOCK_NB); - } - - unsigned long long iNow = CUtils::GetMillTime(); - - while(true) { - if (Lock(LOCK_EX|LOCK_NB)) { - return true; - } - - if ((CUtils::GetMillTime() - iNow) > iTimeout) { - break; - } - - usleep(100); - } - - return(false); + bool TryExLock() { + return Lock(LOCK_EX|LOCK_NB); } - bool TryShLock(unsigned long long iTimeout = 0) { - if (iTimeout == 0) { - return(Lock(LOCK_SH|LOCK_NB)); - } - - unsigned long long iNow = CUtils::GetMillTime(); - - while(true) { - if (Lock(LOCK_SH|LOCK_NB)) { - return true; - } - - if ((CUtils::GetMillTime() - iNow) > iTimeout) { - break; - } - - usleep(100); - } - - return false; + bool TryShLock() { + return(Lock(LOCK_SH|LOCK_NB)); } bool LockEx() { return Lock(LOCK_EX); } diff --git a/znc.cpp b/znc.cpp index 8f338984..eb327584 100644 --- a/znc.cpp +++ b/znc.cpp @@ -186,7 +186,7 @@ bool CZNC::WriteISpoof(CUser* pUser) { if (!m_sISpoofFile.empty()) { m_pISpoofLockFile = new CLockFile; - if(!m_pISpoofLockFile->TryExLock(m_sISpoofFile, 50, true)) { + if(!m_pISpoofLockFile->TryExLock(m_sISpoofFile, true)) { delete m_pISpoofLockFile; m_pISpoofLockFile = NULL; return false; @@ -457,7 +457,7 @@ bool CZNC::WriteNewConfig(const CString& sConfig) { vector vsLines; if (CFile::Exists(sConfigFile)) { - if (!m_LockFile.TryExLock(sConfigFile, 50)) { + if (!m_LockFile.TryExLock(sConfigFile)) { CUtils::PrintError("ZNC is currently running on this config."); return false; } @@ -760,7 +760,7 @@ bool CZNC::ParseConfig(const CString& sConfig) { return false; } - if (!m_LockFile.TryExLock(m_sConfigFile, 50)) { + if (!m_LockFile.TryExLock(m_sConfigFile)) { CUtils::PrintStatus(false, "ZNC is already running on this config."); return false; }