detect no-wait loop in debug build

pull/2/head
weidai 2003-06-10 05:00:45 +00:00
parent be0413d4a6
commit 3fdbab0262
2 changed files with 34 additions and 0 deletions

View File

@ -25,6 +25,7 @@ unsigned int WaitObjectContainer::MaxWaitObjects()
}
WaitObjectContainer::WaitObjectContainer()
: m_sameResultCount(0), m_timer(Timer::MILLISECONDS)
{
Clear();
}
@ -86,6 +87,14 @@ WaitObjectContainer::~WaitObjectContainer()
void WaitObjectContainer::AddHandle(HANDLE handle)
{
#ifndef NDEBUG
if (m_handles.size() == m_lastResult && m_timer.ElapsedTime() > 1000)
{
if (m_sameResultCount > m_timer.ElapsedTime())
try {throw 0;} catch (...) {} // possible no-wait loop, break in debugger
m_timer.StartTimer();
}
#endif
m_handles.push_back(handle);
}
@ -201,7 +210,18 @@ bool WaitObjectContainer::Wait(unsigned long milliseconds)
{
DWORD result = ::WaitForMultipleObjects(m_handles.size(), &m_handles[0], FALSE, milliseconds);
if (result >= WAIT_OBJECT_0 && result < WAIT_OBJECT_0 + m_handles.size())
{
#ifndef NDEBUG
if (result == m_lastResult)
m_sameResultCount++;
else
{
m_lastResult = result;
m_sameResultCount = 0;
}
#endif
return true;
}
else if (result == WAIT_TIMEOUT)
return false;
else

14
wait.h
View File

@ -14,6 +14,10 @@
#include <sys/types.h>
#endif
#ifndef NDEBUG
#include "hrtimer.h"
#endif
NAMESPACE_BEGIN(CryptoPP)
struct WaitingThreadData;
@ -57,6 +61,16 @@ private:
int m_maxFd;
#endif
bool m_noWait;
#ifndef NDEBUG
#ifdef USE_WINDOWS_STYLE_SOCKETS
DWORD m_lastResult;
#else
int m_lastResult;
#endif
unsigned int m_sameResultCount;
Timer m_timer;
#endif
};
NAMESPACE_END