[svn] gpgme - r1274 - trunk/gpgme
svn author marcus
cvs at cvs.gnupg.org
Tue Oct 9 23:23:59 CEST 2007
Author: marcus
Date: 2007-10-09 23:23:50 +0200 (Tue, 09 Oct 2007)
New Revision: 1274
Modified:
trunk/gpgme/ChangeLog
trunk/gpgme/kdpipeiodevice.cpp
Log:
2007-10-09 Marcus Brinkmann <marcus at g10code.de>
* kdpipeiodevice.cpp: New version from Frank Osterfeld and Marc
Mutz.
Modified: trunk/gpgme/ChangeLog
===================================================================
--- trunk/gpgme/ChangeLog 2007-10-05 00:20:43 UTC (rev 1273)
+++ trunk/gpgme/ChangeLog 2007-10-09 21:23:50 UTC (rev 1274)
@@ -1,3 +1,8 @@
+2007-10-09 Marcus Brinkmann <marcus at g10code.de>
+
+ * kdpipeiodevice.cpp: New version from Frank Osterfeld and Marc
+ Mutz.
+
2007-10-05 Marcus Brinkmann <marcus at g10code.de>
* kdpipeiodevice.cpp, w32-qt-io.cpp: New versions from Frank
Modified: trunk/gpgme/kdpipeiodevice.cpp
===================================================================
--- trunk/gpgme/kdpipeiodevice.cpp 2007-10-05 00:20:43 UTC (rev 1273)
+++ trunk/gpgme/kdpipeiodevice.cpp 2007-10-09 21:23:50 UTC (rev 1274)
@@ -95,6 +95,7 @@
Qt::HANDLE handle;
public:
QMutex mutex;
+ QWaitCondition waitForCancelCondition;
QWaitCondition bufferNotFullCondition;
QWaitCondition bufferNotEmptyCondition;
QWaitCondition hasStarted;
@@ -126,8 +127,8 @@
error( false ),
eofShortCut( false ),
errorCode( 0 ),
- rptr( 0 ), wptr( 0 ),
- consumerBlocksOnUs( false )
+ consumerBlocksOnUs( false ),
+ rptr( 0 ), wptr( 0 )
{
}
@@ -207,8 +208,6 @@
bool startReaderThread();
bool startWriterThread();
void stopThreads();
- bool triedToStartReader;
- bool triedToStartWriter;
public Q_SLOTS:
void emitReadyRead();
@@ -218,6 +217,8 @@
Qt::HANDLE handle;
Reader * reader;
Writer * writer;
+ bool triedToStartReader;
+ bool triedToStartWriter;
};
KDPipeIODevice::Private::Private( KDPipeIODevice * qq )
@@ -521,9 +522,9 @@
if ( bytesAvailable() > 0 )
maxSize = std::min( maxSize, bytesAvailable() ); // don't block
}
- qDebug( "%p: KDPipeIODevice::readData: try to lock reader (CONSUMER THREAD)" );
+ qDebug( "%p: KDPipeIODevice::readData: try to lock reader (CONSUMER THREAD)", this );
LOCKED( r );
- qDebug( "%p: KDPipeIODevice::readData: locked reader (CONSUMER THREAD)" );
+ qDebug( "%p: KDPipeIODevice::readData: locked reader (CONSUMER THREAD)", this );
r->readyReadSentCondition.wakeAll();
if ( /* maxSize > 0 && */ r->bufferEmpty() && !r->error && !r->eof ) { // ### block on maxSize == 0?
@@ -626,6 +627,7 @@
// tell thread to cancel:
r->cancel = true;
// and wake it, so it can terminate:
+ r->waitForCancelCondition.wakeAll();
r->bufferNotFullCondition.wakeAll();
r->readyReadSentCondition.wakeAll();
}
@@ -653,7 +655,7 @@
qDebug( "KPipeIODevice::close(%p): wait and closing writer %p", this, d->writer );
waitAndDelete( d->writer );
qDebug( "KPipeIODevice::close(%p): wait and closing reader %p", this, d->reader );
- {
+ if ( d->reader ) {
LOCKED( d->reader );
d->reader->readyReadSentCondition.wakeAll();
}
@@ -682,15 +684,20 @@
while ( true ) {
if ( !cancel && ( eof || error ) ) {
+ //notify the client until the buffer is empty and then once
+ //again so he receives eof/error. After that, wait for him
+ //to cancel
+ const bool wasEmpty = bufferEmpty();
qDebug( "%p: Reader::run: received eof(%d) or error(%d), waking everyone", this, eof, error );
notifyReadyRead();
- cancel = true;
+ if ( !cancel && wasEmpty )
+ waitForCancelCondition.wait( &mutex );
} else if ( !cancel && !bufferFull() && !bufferEmpty() ) {
qDebug( "%p: Reader::run: buffer no longer empty, waking everyone", this );
notifyReadyRead();
}
- while ( !error && !cancel && bufferFull() ) {
+ while ( !cancel && !error && bufferFull() ) {
notifyReadyRead();
if ( bufferFull() ) {
qDebug( "%p: Reader::run: buffer is full, going to sleep", this );
@@ -836,8 +843,7 @@
goto leave;
}
#endif
- qDebug( "%p (fd=%d): Writer::run: buffer after WriteFile (numBytes=%lld): %s:", this, fd, numBytesInBuffer,
-buffer );
+ qDebug( "%p (fd=%d): Writer::run: buffer after WriteFile (numBytes=%u): %s:", this, fd, numBytesInBuffer, buffer );
totalWritten += numWritten;
mutex.lock();
} while ( totalWritten < numBytesInBuffer );
More information about the Gnupg-commits
mailing list