From 2660779a26b8ba285b0ab172c8f48d50dd1da918 Mon Sep 17 00:00:00 2001 From: weidai Date: Tue, 10 Jun 2003 05:00:45 +0000 Subject: detect no-wait loop in debug build git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@79 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- wait.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'wait.cpp') diff --git a/wait.cpp b/wait.cpp index dfcb60c..90231ac 100644 --- a/wait.cpp +++ b/wait.cpp @@ -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 -- cgit v1.2.1