Merge topic 'file-LOCK-timeout-type'
97841dad file: Use 'long' to represent the parsed LOCK TIMEOUT value
This commit is contained in:
commit
47c41d902c
@ -3521,7 +3521,7 @@ bool cmFileCommand::HandleLockCommand(
|
|||||||
};
|
};
|
||||||
Guard guard = GUARD_PROCESS;
|
Guard guard = GUARD_PROCESS;
|
||||||
std::string resultVariable;
|
std::string resultVariable;
|
||||||
unsigned timeout = static_cast<unsigned>(-1);
|
unsigned long timeout = static_cast<unsigned long>(-1);
|
||||||
|
|
||||||
// Parse arguments
|
// Parse arguments
|
||||||
if(args.size() < 2)
|
if(args.size() < 2)
|
||||||
@ -3597,15 +3597,16 @@ bool cmFileCommand::HandleLockCommand(
|
|||||||
"expected timeout value after TIMEOUT");
|
"expected timeout value after TIMEOUT");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int scanned;
|
long scanned;
|
||||||
if(!cmSystemTools::StringToInt(args[i].c_str(), &scanned) || scanned < 0)
|
if(!cmSystemTools::StringToLong(args[i].c_str(), &scanned)
|
||||||
|
|| scanned < 0)
|
||||||
{
|
{
|
||||||
cmOStringStream e;
|
cmOStringStream e;
|
||||||
e << "TIMEOUT value \"" << args[i] << "\" is not an unsigned integer.";
|
e << "TIMEOUT value \"" << args[i] << "\" is not an unsigned integer.";
|
||||||
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
timeout = static_cast<unsigned>(scanned);
|
timeout = static_cast<unsigned long>(scanned);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ cmFileLock::~cmFileLock()
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmFileLockResult cmFileLock::Lock(
|
cmFileLockResult cmFileLock::Lock(
|
||||||
const std::string& filename, unsigned timeout)
|
const std::string& filename, unsigned long timeout)
|
||||||
{
|
{
|
||||||
if (filename.empty())
|
if (filename.empty())
|
||||||
{
|
{
|
||||||
@ -48,7 +48,7 @@ cmFileLockResult cmFileLock::Lock(
|
|||||||
cmFileLockResult result = this->OpenFile();
|
cmFileLockResult result = this->OpenFile();
|
||||||
if (result.IsOk())
|
if (result.IsOk())
|
||||||
{
|
{
|
||||||
if (timeout == static_cast<unsigned>(-1))
|
if (timeout == static_cast<unsigned long>(-1))
|
||||||
{
|
{
|
||||||
result = this->LockWithoutTimeout();
|
result = this->LockWithoutTimeout();
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class cmFileLock
|
|||||||
* @brief Lock the file.
|
* @brief Lock the file.
|
||||||
* @param timeoutSec Lock timeout. If -1 try until success or fatal error.
|
* @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.
|
* @brief Unlock the file.
|
||||||
@ -57,7 +57,7 @@ class cmFileLock
|
|||||||
|
|
||||||
cmFileLockResult OpenFile();
|
cmFileLockResult OpenFile();
|
||||||
cmFileLockResult LockWithoutTimeout();
|
cmFileLockResult LockWithoutTimeout();
|
||||||
cmFileLockResult LockWithTimeout(unsigned timeoutSec);
|
cmFileLockResult LockWithTimeout(unsigned long timeoutSec);
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
typedef HANDLE FileId;
|
typedef HANDLE FileId;
|
||||||
|
@ -60,7 +60,7 @@ void cmFileLockPool::PopFileScope()
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmFileLockResult cmFileLockPool::LockFunctionScope(
|
cmFileLockResult cmFileLockPool::LockFunctionScope(
|
||||||
const std::string& filename, unsigned timeoutSec)
|
const std::string& filename, unsigned long timeoutSec)
|
||||||
{
|
{
|
||||||
if (this->IsAlreadyLocked(filename))
|
if (this->IsAlreadyLocked(filename))
|
||||||
{
|
{
|
||||||
@ -74,7 +74,7 @@ cmFileLockResult cmFileLockPool::LockFunctionScope(
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmFileLockResult cmFileLockPool::LockFileScope(
|
cmFileLockResult cmFileLockPool::LockFileScope(
|
||||||
const std::string& filename, unsigned timeoutSec)
|
const std::string& filename, unsigned long timeoutSec)
|
||||||
{
|
{
|
||||||
if (this->IsAlreadyLocked(filename))
|
if (this->IsAlreadyLocked(filename))
|
||||||
{
|
{
|
||||||
@ -85,7 +85,7 @@ cmFileLockResult cmFileLockPool::LockFileScope(
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmFileLockResult cmFileLockPool::LockProcessScope(
|
cmFileLockResult cmFileLockPool::LockProcessScope(
|
||||||
const std::string& filename, unsigned timeoutSec)
|
const std::string& filename, unsigned long timeoutSec)
|
||||||
{
|
{
|
||||||
if (this->IsAlreadyLocked(filename))
|
if (this->IsAlreadyLocked(filename))
|
||||||
{
|
{
|
||||||
@ -155,7 +155,7 @@ cmFileLockPool::ScopePool::~ScopePool()
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmFileLockResult cmFileLockPool::ScopePool::Lock(
|
cmFileLockResult cmFileLockPool::ScopePool::Lock(
|
||||||
const std::string& filename, unsigned timeoutSec)
|
const std::string& filename, unsigned long timeoutSec)
|
||||||
{
|
{
|
||||||
cmFileLock *lock = new cmFileLock();
|
cmFileLock *lock = new cmFileLock();
|
||||||
const cmFileLockResult result = lock->Lock(filename, timeoutSec);
|
const cmFileLockResult result = lock->Lock(filename, timeoutSec);
|
||||||
|
@ -45,13 +45,13 @@ class cmFileLockPool
|
|||||||
* @param timeoutSec Lock timeout. If -1 try until success or fatal error.
|
* @param timeoutSec Lock timeout. If -1 try until success or fatal error.
|
||||||
*/
|
*/
|
||||||
cmFileLockResult LockFunctionScope(
|
cmFileLockResult LockFunctionScope(
|
||||||
const std::string& filename, unsigned timeoutSec
|
const std::string& filename, unsigned long timeoutSec
|
||||||
);
|
);
|
||||||
cmFileLockResult LockFileScope(
|
cmFileLockResult LockFileScope(
|
||||||
const std::string& filename, unsigned timeoutSec
|
const std::string& filename, unsigned long timeoutSec
|
||||||
);
|
);
|
||||||
cmFileLockResult LockProcessScope(
|
cmFileLockResult LockProcessScope(
|
||||||
const std::string& filename, unsigned timeoutSec
|
const std::string& filename, unsigned long timeoutSec
|
||||||
);
|
);
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
@ -72,7 +72,9 @@ class cmFileLockPool
|
|||||||
ScopePool();
|
ScopePool();
|
||||||
~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);
|
cmFileLockResult Release(const std::string& filename);
|
||||||
bool IsAlreadyLocked(const std::string& filename) const;
|
bool IsAlreadyLocked(const std::string& filename) const;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ cmFileLockResult cmFileLock::LockWithoutTimeout()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmFileLockResult cmFileLock::LockWithTimeout(unsigned seconds)
|
cmFileLockResult cmFileLock::LockWithTimeout(unsigned long seconds)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -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;
|
const DWORD flags = LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY;
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -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;
|
char *endp;
|
||||||
*value = static_cast<int>(strtol(str, &endp, 10));
|
*value = strtol(str, &endp, 10);
|
||||||
return (*endp == '\0') && (endp != str);
|
return (*endp == '\0') && (endp != str) && (errno == 0);
|
||||||
}
|
}
|
||||||
|
@ -458,8 +458,8 @@ public:
|
|||||||
static std::vector<std::string> tokenize(const std::string& str,
|
static std::vector<std::string> tokenize(const std::string& str,
|
||||||
const std::string& sep);
|
const std::string& sep);
|
||||||
|
|
||||||
/** Convert string to int. Expected that the whole string is an integer */
|
/** Convert string to long. Expected that the whole string is an integer */
|
||||||
static bool StringToInt(const char* str, int* value);
|
static bool StringToLong(const char* str, long* value);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
struct WindowsFileRetry
|
struct WindowsFileRetry
|
||||||
|
Loading…
x
Reference in New Issue
Block a user