poco/Foundation/src/Mutex_WIN32.cpp
Roger Meier b0581433a7 LICENSE: add info about SPDX-License-Identifier usage and use it
fix: remove executable flag and change back to 100644 (was 100755)

Signed-off-by: Roger Meier <r.meier@siemens.com>
2014-05-14 08:38:09 +02:00

62 lines
1.1 KiB
C++

//
// Mutex_WIN32.cpp
//
// $Id: //poco/1.4/Foundation/src/Mutex_WIN32.cpp#1 $
//
// Library: Foundation
// Package: Threading
// Module: Mutex
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Mutex_WIN32.h"
#include "Poco/Timestamp.h"
namespace Poco {
MutexImpl::MutexImpl()
{
// the fct has a boolean return value under WInnNt/2000/XP but not on Win98
// the return only checks if the input address of &_cs was valid, so it is safe to omit it
InitializeCriticalSectionAndSpinCount(&_cs, 4000);
}
MutexImpl::~MutexImpl()
{
DeleteCriticalSection(&_cs);
}
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