mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-30 05:29:41 +01:00
synced with main repository
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Mutex_WIN32.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/Mutex_WIN32.cpp#13 $
|
||||
// $Id: //poco/svn/Foundation/src/Mutex_WIN32.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
|
||||
#include "Poco/Mutex_WIN32.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -54,4 +55,27 @@ MutexImpl::~MutexImpl()
|
||||
}
|
||||
|
||||
|
||||
bool MutexImpl::tryLockImpl(long milliseconds)
|
||||
{
|
||||
const int sleepMillis = 5;
|
||||
Timestamp now;
|
||||
Timestamp::TimeDiff diff(Timestamp::TimeDiff(milliseconds)*1000);
|
||||
do
|
||||
{
|
||||
try
|
||||
{
|
||||
if (TryEnterCriticalSection(&_cs) == TRUE)
|
||||
return true;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
throw SystemException("cannot lock mutex");
|
||||
}
|
||||
Sleep(sleepMillis);
|
||||
}
|
||||
while (!now.isElapsed(diff));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
Reference in New Issue
Block a user