Fixed buffer CPU usage

This commit is contained in:
ThatGuy 2013-07-29 14:15:51 +02:00
parent 2cc27efcae
commit 3dcdb0ccd7
2 changed files with 11 additions and 12 deletions

View file

@ -214,26 +214,22 @@ namespace Buffer {
if (thisStream->getIPInput().connected()){ if (thisStream->getIPInput().connected()){
if (!connected){ if (!connected){
connected = true; connected = true;
thisStream->getIPInput().setBlocking(false); thisStream->getIPInput().setBlocking(true);
} }
if (thisStream->getIPInput().spool()){ if (thisStream->getIPInput().spool()){
while (true){
thisStream->getWriteLock(); thisStream->getWriteLock();
if (thisStream->getStream()->parsePacket(thisStream->getIPInput().Received())){ bool newPackets = false;
while (thisStream->getStream()->parsePacket(thisStream->getIPInput().Received())){
if (thisStream->getStream()->metadata.isMember("reset")){ if (thisStream->getStream()->metadata.isMember("reset")){
thisStream->disconnectUsers(); thisStream->disconnectUsers();
thisStream->getStream()->metadata.removeMember("reset"); thisStream->getStream()->metadata.removeMember("reset");
thisStream->getStream()->metadata.netPrepare(); thisStream->getStream()->metadata.netPrepare();
} }
thisStream->dropWriteLock(true); newPackets = true;
}else{
thisStream->dropWriteLock(false);
//Util::sleep(10); //10ms wait
break;
} }
} thisStream->dropWriteLock(newPackets);
//}else{
//Util::sleep(500); //500ms wait
} }
}else{ }else{
if (connected){ if (connected){

View file

@ -179,6 +179,9 @@ namespace Buffer {
///\brief Drops a previously obtained write lock. ///\brief Drops a previously obtained write lock.
///\param newPacketsAvailable Whether new packets are available to update the index. ///\param newPacketsAvailable Whether new packets are available to update the index.
void Stream::dropWriteLock(bool newPacketsAvailable){ void Stream::dropWriteLock(bool newPacketsAvailable){
if (newPacketsAvailable){
Strm->metadata.netPrepare();
}
rw_mutex.lock(); rw_mutex.lock();
writers--; writers--;
rw_mutex.unlock(); rw_mutex.unlock();