2008-01-30 Marcus Brinkmann <marcus@g10code.de>
* kdpipeiodevice.cpp: New version by Frank Osterfeld, fixes race condition.
This commit is contained in:
parent
2b5033018f
commit
2cf46b3ca9
@ -1,3 +1,8 @@
|
|||||||
|
2008-01-30 Marcus Brinkmann <marcus@g10code.de>
|
||||||
|
|
||||||
|
* kdpipeiodevice.cpp: New version by Frank Osterfeld, fixes race
|
||||||
|
condition.
|
||||||
|
|
||||||
2008-01-28 Marcus Brinkmann <marcus@g10code.de>
|
2008-01-28 Marcus Brinkmann <marcus@g10code.de>
|
||||||
|
|
||||||
* engine-gpgsm.c (map_input_enc): Rename to ...
|
* engine-gpgsm.c (map_input_enc): Rename to ...
|
||||||
|
@ -106,6 +106,7 @@ public:
|
|||||||
bool error;
|
bool error;
|
||||||
bool eofShortCut;
|
bool eofShortCut;
|
||||||
int errorCode;
|
int errorCode;
|
||||||
|
bool isReading;
|
||||||
bool consumerBlocksOnUs;
|
bool consumerBlocksOnUs;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -127,6 +128,7 @@ Reader::Reader( int fd_, Qt::HANDLE handle_ )
|
|||||||
error( false ),
|
error( false ),
|
||||||
eofShortCut( false ),
|
eofShortCut( false ),
|
||||||
errorCode( 0 ),
|
errorCode( 0 ),
|
||||||
|
isReading( false ),
|
||||||
consumerBlocksOnUs( false ),
|
consumerBlocksOnUs( false ),
|
||||||
rptr( 0 ), wptr( 0 )
|
rptr( 0 ), wptr( 0 )
|
||||||
{
|
{
|
||||||
@ -321,24 +323,28 @@ bool KDPipeIODevice::Private::startWriterThread()
|
|||||||
|
|
||||||
void KDPipeIODevice::Private::emitReadyRead()
|
void KDPipeIODevice::Private::emitReadyRead()
|
||||||
{
|
{
|
||||||
static int s_counter = 0;
|
|
||||||
const int counter = s_counter++;
|
|
||||||
QPointer<Private> thisPointer( this );
|
QPointer<Private> thisPointer( this );
|
||||||
qDebug( "KDPipeIODevice::Private::emitReadyRead %p, %d", this, counter );
|
qDebug( "KDPipeIODevice::Private::emitReadyRead %p", this );
|
||||||
|
|
||||||
emit q->readyRead();
|
emit q->readyRead();
|
||||||
|
|
||||||
if ( !thisPointer )
|
if ( !thisPointer )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
bool mustNotify = false;
|
||||||
|
|
||||||
if ( reader ) {
|
if ( reader ) {
|
||||||
qDebug( "KDPipeIODevice::Private::emitReadyRead %p, %d: locking reader (CONSUMER THREAD)", this, counter );
|
qDebug( "KDPipeIODevice::Private::emitReadyRead %p: locking reader (CONSUMER THREAD)", this );
|
||||||
synchronized( reader ) {
|
synchronized( reader ) {
|
||||||
qDebug( "KDPipeIODevice::Private::emitReadyRead %p, %d: locked reader (CONSUMER THREAD)", this, counter );
|
qDebug( "KDPipeIODevice::Private::emitReadyRead %p: locked reader (CONSUMER THREAD)", this );
|
||||||
reader->readyReadSentCondition.wakeAll();
|
reader->readyReadSentCondition.wakeAll();
|
||||||
|
mustNotify = !reader->bufferEmpty() && reader->isReading;
|
||||||
|
qDebug( "KDPipeIODevice::emitReadyRead %p: bufferEmpty: %d reader in ReadFile: %d", this, reader->bufferEmpty(), reader->isReading );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug( "KDPipeIODevice::Private::emitReadyRead %p leaving %d", this, counter );
|
if ( mustNotify )
|
||||||
|
QTimer::singleShot( 100, this, SLOT( emitReadyRead() ) );
|
||||||
|
qDebug( "KDPipeIODevice::Private::emitReadyRead %p leaving", this );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -732,10 +738,12 @@ void Reader::run() {
|
|||||||
|
|
||||||
qDebug( "%p: Reader::run: trying to read %d bytes", this, numBytes );
|
qDebug( "%p: Reader::run: trying to read %d bytes", this, numBytes );
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
|
isReading = true;
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
DWORD numRead;
|
DWORD numRead;
|
||||||
const bool ok = ReadFile( handle, buffer + wptr, numBytes, &numRead, 0 );
|
const bool ok = ReadFile( handle, buffer + wptr, numBytes, &numRead, 0 );
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
|
isReading = false;
|
||||||
if ( ok ) {
|
if ( ok ) {
|
||||||
if ( numRead == 0 ) {
|
if ( numRead == 0 ) {
|
||||||
qDebug( "%p: Reader::run: got eof (numRead==0)", this );
|
qDebug( "%p: Reader::run: got eof (numRead==0)", this );
|
||||||
|
Loading…
Reference in New Issue
Block a user