improved performance

This commit is contained in:
Jeff Hill
2000-11-08 03:52:18 +00:00
parent 2ded135da9
commit 4784b73a9f
39 changed files with 2480 additions and 2589 deletions

View File

@@ -17,37 +17,43 @@
#include "iocinf.h"
#include "comBuf_IL.h"
comQueRecv::comQueRecv ()
{
}
comQueRecv::~comQueRecv ()
{
this->clear ();
}
void comQueRecv::clear ()
{
comBuf *pBuf;
this->mutex.lock ();
while ( ( pBuf = this->bufs.get () ) ) {
pBuf->destroy ();
}
this->mutex.unlock ();
}
unsigned comQueRecv::occupiedBytes () const
{
this->mutex.lock ();
unsigned count = this->bufs.count ();
unsigned nBytes;
if ( count >= 2u ) {
nBytes = this->bufs.first ()->occupiedBytes ();
nBytes += this->bufs.last ()->occupiedBytes ();
nBytes += ( count - 2u ) * comBuf::maxBytes ();
if ( count == 0u ) {
nBytes = 0u;
}
else if ( count == 1u ) {
nBytes = this->bufs.first ()->occupiedBytes ();
}
else {
nBytes = 0u;
// this requires the compress operation in
// copyIn ( comBuf & bufIn )
nBytes = this->bufs.first ()->occupiedBytes ();
nBytes += this->bufs.last ()->occupiedBytes ();
nBytes += ( count - 2u ) * comBuf::maxBytes ();
}
this->mutex.unlock ();
return nBytes;
}
@@ -55,11 +61,8 @@ bool comQueRecv::copyOutBytes ( void *pBuf, unsigned nBytes )
{
char *pCharBuf = static_cast < char * > ( pBuf );
this->mutex.lock ();
// dont return partial message
if ( nBytes > this->occupiedBytes () ) {
this->mutex.unlock ();
return false;
}
@@ -74,40 +77,22 @@ bool comQueRecv::copyOutBytes ( void *pBuf, unsigned nBytes )
}
}
this->mutex.unlock ();
return true;
}
unsigned comQueRecv::fillFromWire ()
void comQueRecv::pushLastComBufReceived ( comBuf & bufIn )
{
// this approach requires that only one thread performs fill
// but its advantage is that the lock is not held while filling
comBuf *pComBuf = new comBuf;
if ( ! pComBuf ) {
// no way to be informed when memory is available
threadSleep ( 0.5 );
return 0u;
}
unsigned nNewBytes = pComBuf->fillFromWire ( *this );
this->mutex.lock ();
comBuf *pLastBuf = this->bufs.last ();
if ( pLastBuf ) {
pLastBuf->copyIn ( *pComBuf );
pLastBuf->copyIn ( bufIn );
}
if ( pComBuf->occupiedBytes () ) {
this->bufs.add ( *pComBuf );
if ( bufIn.occupiedBytes () ) {
// move occupied bytes to the start of the buffer
bufIn.compress ();
this->bufs.add ( bufIn );
}
else {
pComBuf->destroy ();
bufIn.destroy ();
}
this->mutex.unlock ();
return nNewBytes;
}