Merge topic 'file-LOCK-timeout-type'

97841dad file: Use 'long' to represent the parsed LOCK TIMEOUT value
This commit is contained in:
Brad King 2014-12-08 09:07:14 -05:00 committed by CMake Topic Stage
commit 47c41d902c
9 changed files with 27 additions and 23 deletions

View File

@ -3521,7 +3521,7 @@ bool cmFileCommand::HandleLockCommand(
};
Guard guard = GUARD_PROCESS;
std::string resultVariable;
unsigned timeout = static_cast<unsigned>(-1);
unsigned long timeout = static_cast<unsigned long>(-1);
// Parse arguments
if(args.size() < 2)
@ -3597,15 +3597,16 @@ bool cmFileCommand::HandleLockCommand(
"expected timeout value after TIMEOUT");
return false;
}
int scanned;
if(!cmSystemTools::StringToInt(args[i].c_str(), &scanned) || scanned < 0)
long scanned;
if(!cmSystemTools::StringToLong(args[i].c_str(), &scanned)
|| scanned < 0)
{
cmOStringStream e;
e << "TIMEOUT value \"" << args[i] << "\" is not an unsigned integer.";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return false;
}
timeout = static_cast<unsigned>(scanned);
timeout = static_cast<unsigned long>(scanned);
}
else
{

View File

@ -28,7 +28,7 @@ cmFileLock::~cmFileLock()
}
cmFileLockResult cmFileLock::Lock(
const std::string& filename, unsigned timeout)
const std::string& filename, unsigned long timeout)
{
if (filename.empty())
{
@ -48,7 +48,7 @@ cmFileLockResult cmFileLock::Lock(
cmFileLockResult result = this->OpenFile();
if (result.IsOk())
{
if (timeout == static_cast<unsigned>(-1))
if (timeout == static_cast<unsigned long>(-1))
{
result = this->LockWithoutTimeout();
}

View File

@ -37,7 +37,7 @@ class cmFileLock
* @brief Lock the file.
* @param timeoutSec Lock timeout. If -1 try until success or fatal error.
*/
cmFileLockResult Lock(const std::string& filename, unsigned timeoutSec);
cmFileLockResult Lock(const std::string& filename, unsigned long timeoutSec);
/**
* @brief Unlock the file.
@ -57,7 +57,7 @@ class cmFileLock
cmFileLockResult OpenFile();
cmFileLockResult LockWithoutTimeout();
cmFileLockResult LockWithTimeout(unsigned timeoutSec);
cmFileLockResult LockWithTimeout(unsigned long timeoutSec);
#if defined(_WIN32)
typedef HANDLE FileId;

View File

@ -60,7 +60,7 @@ void cmFileLockPool::PopFileScope()
}
cmFileLockResult cmFileLockPool::LockFunctionScope(
const std::string& filename, unsigned timeoutSec)
const std::string& filename, unsigned long timeoutSec)
{
if (this->IsAlreadyLocked(filename))
{
@ -74,7 +74,7 @@ cmFileLockResult cmFileLockPool::LockFunctionScope(
}
cmFileLockResult cmFileLockPool::LockFileScope(
const std::string& filename, unsigned timeoutSec)
const std::string& filename, unsigned long timeoutSec)
{
if (this->IsAlreadyLocked(filename))
{
@ -85,7 +85,7 @@ cmFileLockResult cmFileLockPool::LockFileScope(
}
cmFileLockResult cmFileLockPool::LockProcessScope(
const std::string& filename, unsigned timeoutSec)
const std::string& filename, unsigned long timeoutSec)
{
if (this->IsAlreadyLocked(filename))
{
@ -155,7 +155,7 @@ cmFileLockPool::ScopePool::~ScopePool()
}
cmFileLockResult cmFileLockPool::ScopePool::Lock(
const std::string& filename, unsigned timeoutSec)
const std::string& filename, unsigned long timeoutSec)
{
cmFileLock *lock = new cmFileLock();
const cmFileLockResult result = lock->Lock(filename, timeoutSec);

View File

@ -45,13 +45,13 @@ class cmFileLockPool
* @param timeoutSec Lock timeout. If -1 try until success or fatal error.
*/
cmFileLockResult LockFunctionScope(
const std::string& filename, unsigned timeoutSec
const std::string& filename, unsigned long timeoutSec
);
cmFileLockResult LockFileScope(
const std::string& filename, unsigned timeoutSec
const std::string& filename, unsigned long timeoutSec
);
cmFileLockResult LockProcessScope(
const std::string& filename, unsigned timeoutSec
const std::string& filename, unsigned long timeoutSec
);
//@}
@ -72,7 +72,9 @@ class cmFileLockPool
ScopePool();
~ScopePool();
cmFileLockResult Lock(const std::string& filename, unsigned timeoutSec);
cmFileLockResult Lock(
const std::string& filename, unsigned long timeoutSec
);
cmFileLockResult Release(const std::string& filename);
bool IsAlreadyLocked(const std::string& filename) const;

View File

@ -66,7 +66,7 @@ cmFileLockResult cmFileLock::LockWithoutTimeout()
}
}
cmFileLockResult cmFileLock::LockWithTimeout(unsigned seconds)
cmFileLockResult cmFileLock::LockWithTimeout(unsigned long seconds)
{
while (true)
{

View File

@ -86,7 +86,7 @@ cmFileLockResult cmFileLock::LockWithoutTimeout()
}
}
cmFileLockResult cmFileLock::LockWithTimeout(unsigned seconds)
cmFileLockResult cmFileLock::LockWithTimeout(unsigned long seconds)
{
const DWORD flags = LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY;
while (true)

View File

@ -2925,9 +2925,10 @@ std::vector<std::string> cmSystemTools::tokenize(const std::string& str,
}
//----------------------------------------------------------------------------
bool cmSystemTools::StringToInt(const char* str, int* value)
bool cmSystemTools::StringToLong(const char* str, long* value)
{
errno = 0;
char *endp;
*value = static_cast<int>(strtol(str, &endp, 10));
return (*endp == '\0') && (endp != str);
*value = strtol(str, &endp, 10);
return (*endp == '\0') && (endp != str) && (errno == 0);
}

View File

@ -458,8 +458,8 @@ public:
static std::vector<std::string> tokenize(const std::string& str,
const std::string& sep);
/** Convert string to int. Expected that the whole string is an integer */
static bool StringToInt(const char* str, int* value);
/** Convert string to long. Expected that the whole string is an integer */
static bool StringToLong(const char* str, long* value);
#ifdef _WIN32
struct WindowsFileRetry