summaryrefslogtreecommitdiff
path: root/wait.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-06-19 17:09:07 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-06-19 17:09:07 +0000
commitab1ed4b45d7c6ea11785065027986d389e5b673a (patch)
tree7e300cb2827b1bf3cc05695e5e89b5ef58b1be93 /wait.cpp
parentb0034a8989f961db2fcfb7673e487031e3115cb5 (diff)
downloadcryptopp-ab1ed4b45d7c6ea11785065027986d389e5b673a.tar.gz
sync with private branch
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@81 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'wait.cpp')
-rw-r--r--wait.cpp52
1 files changed, 47 insertions, 5 deletions
diff --git a/wait.cpp b/wait.cpp
index e4da612..b468bc7 100644
--- a/wait.cpp
+++ b/wait.cpp
@@ -13,6 +13,12 @@
#include <unistd.h>
#endif
+#define TRACE_WAIT 0
+
+#if TRACE_WAIT
+#include "hrtimer.h"
+#endif
+
NAMESPACE_BEGIN(CryptoPP)
unsigned int WaitObjectContainer::MaxWaitObjects()
@@ -25,9 +31,8 @@ unsigned int WaitObjectContainer::MaxWaitObjects()
}
WaitObjectContainer::WaitObjectContainer()
-#ifndef NDEBUG
- : m_sameResultCount(0)
- , m_timer(Timer::MILLISECONDS)
+#if CRYPTOPP_DETECT_NO_WAIT
+ : m_sameResultCount(0), m_timer(Timer::MILLISECONDS)
#endif
{
Clear();
@@ -45,6 +50,19 @@ void WaitObjectContainer::Clear()
m_noWait = false;
}
+void WaitObjectContainer::SetNoWait()
+{
+#if CRYPTOPP_DETECT_NO_WAIT
+ if (-1 == 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_noWait = true;
+}
+
#ifdef USE_WINDOWS_STYLE_SOCKETS
struct WaitingThreadData
@@ -90,7 +108,7 @@ WaitObjectContainer::~WaitObjectContainer()
void WaitObjectContainer::AddHandle(HANDLE handle)
{
-#ifndef NDEBUG
+#if CRYPTOPP_DETECT_NO_WAIT
if (m_handles.size() == m_lastResult && m_timer.ElapsedTime() > 1000)
{
if (m_sameResultCount > m_timer.ElapsedTime())
@@ -165,7 +183,18 @@ void WaitObjectContainer::CreateThreads(unsigned int count)
bool WaitObjectContainer::Wait(unsigned long milliseconds)
{
if (m_noWait || m_handles.empty())
+ {
+#if CRYPTOPP_DETECT_NO_WAIT
+ if (-1 == m_lastResult)
+ m_sameResultCount++;
+ else
+ {
+ m_lastResult = -1;
+ m_sameResultCount = 0;
+ }
+#endif
return true;
+ }
if (m_handles.size() > MAXIMUM_WAIT_OBJECTS)
{
@@ -211,10 +240,23 @@ bool WaitObjectContainer::Wait(unsigned long milliseconds)
}
else
{
+#if TRACE_WAIT
+ static Timer t(Timer::MICROSECONDS);
+ static unsigned long lastTime = 0;
+ unsigned long timeBeforeWait = t.ElapsedTime();
+#endif
DWORD result = ::WaitForMultipleObjects(m_handles.size(), &m_handles[0], FALSE, milliseconds);
+#if TRACE_WAIT
+ if (milliseconds > 0)
+ {
+ unsigned long timeAfterWait = t.ElapsedTime();
+ OutputDebugString(("Handles " + IntToString(m_handles.size()) + ", Woke up by " + IntToString(result-WAIT_OBJECT_0) + ", Busied for " + IntToString(timeBeforeWait-lastTime) + " us, Waited for " + IntToString(timeAfterWait-timeBeforeWait) + " us, max " + IntToString(milliseconds) + "ms\n").c_str());
+ lastTime = timeAfterWait;
+ }
+#endif
if (result >= WAIT_OBJECT_0 && result < WAIT_OBJECT_0 + m_handles.size())
{
-#ifndef NDEBUG
+#if CRYPTOPP_DETECT_NO_WAIT
if (result == m_lastResult)
m_sameResultCount++;
else