|
From: CVS C. to T. <the...@li...> - 2011-11-12 15:31:24
|
Revision: 670
http://themis.svn.sourceforge.net/themis/?rev=670&view=rev
Author: mark_hellegers
Date: 2011-11-12 15:31:17 +0000 (Sat, 12 Nov 2011)
Log Message:
-----------
Another attempt to reduce the cpu usage that is caused by busy looping.
Modified Paths:
--------------
trunk/themis/framework/tcpmanager.cpp
Modified: trunk/themis/framework/tcpmanager.cpp
===================================================================
--- trunk/themis/framework/tcpmanager.cpp 2011-11-09 23:43:31 UTC (rev 669)
+++ trunk/themis/framework/tcpmanager.cpp 2011-11-12 15:31:17 UTC (rev 670)
@@ -125,6 +125,7 @@
int32 connect_count = 0;
int32 current_time;
// int32 last_used;
+ bool actionTaken = false; // When no action has been taken in a run of the while loop, snooze to prevent a busy loop.
int32 time_out=DEFAULT_TIMEOUT;
@@ -148,18 +149,24 @@
if (!connection->already_connected)
connection->ConnectionEstablished();
connection->NotifyConnect();
+ actionTaken = true;
} else {
if (connection->IsDataWaiting()) {
connection->RetrieveData();
- if (connection->owner!=NULL) {
+ if (connection->owner!=NULL && connection->DataSize() > 0) {
connection->owner->DataIsWaiting(connection);
+ actionTaken = true;
}
+ else if ((connection->LastUsed()!=0) && ((current_time-connection->LastUsed())>=time_out)) {
+ connection->TimeOut();
+ Disconnect(connection);
+ actionTaken = true;
+ }
}
else if ((connection->LastUsed()!=0) && ((current_time-connection->LastUsed())>=time_out)) {
- // if (connection->owner!=NULL)
- // connection->owner->DestroyingConnectionObject(connection);
connection->TimeOut();
Disconnect(connection);
+ actionTaken = true;
}
}
} else {
@@ -168,25 +175,25 @@
int32 lastused=connection->LastUsed();
connection->RetrieveData();
connection->lastusedtime=lastused;
+ actionTaken = true;
}
else if ((connection->LastUsed()!=0) && ((current_time-connection->LastUsed())>=time_out)) {
- // if (connection->owner!=NULL)
- // connection->owner->DestroyingConnectionObject(connection);
connection->TimeOut();
Disconnect(connection);
+ actionTaken = true;
}
}
} else {
if (!connection->NotifiedDisconnect()) {
connection->NotifyDisconnect();
// Disconnect(connection);
+ actionTaken = true;
}
else {
if ((connection->LastUsed()!=0) && ((current_time-connection->LastUsed())>=time_out)) {
- // if (connection->owner!=NULL)
- // connection->owner->DestroyingConnectionObject(connection);
connection->TimeOut();
Disconnect(connection);
+ actionTaken = true;
}
}
}
@@ -200,11 +207,12 @@
connect_count = 0;
}
- if (connect_count == 0) {
- // No connections, so take it easy before we check again for connections.
+ if (!actionTaken) {
+ // Nothing done, so take it easy before we check again for connections.
// Otherwise we create a busy loop.
snooze(25000);
}
+ actionTaken = false;
// release_sem(process_sem_2);
// }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|