- Timestamp:
- Oct 4, 2009, 1:23:44 AM (16 years ago)
- Location:
- trunk/src/corelib/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/corelib/io/qprocess_os2.cpp
r197 r198 126 126 static void removeProcess(USHORT procKey); 127 127 128 static QMutex *mutex() { return &mtx; }129 130 128 private: 131 129 … … 162 160 163 161 static QProcessManager *instance; 164 static QMutex m tx;162 static QMutex mx; 165 163 }; 166 164 167 165 // static 168 166 QProcessManager *QProcessManager::instance = 0; 169 QMutex QProcessManager::m tx;167 QMutex QProcessManager::mx; 170 168 171 169 // static … … 202 200 void QProcessManager::addRef() 203 201 { 204 QMutexLocker locker( mutex());202 QMutexLocker locker(); 205 203 206 204 if (instance == 0) { … … 214 212 void QProcessManager::release() 215 213 { 216 QMutexLocker locker( mutex());214 QMutexLocker locker(); 217 215 218 216 Q_ASSERT(instance); … … 245 243 #endif 246 244 247 QMutexLocker locker( mutex());245 QMutexLocker locker(); 248 246 Q_ASSERT(instance); 249 247 … … 301 299 void QProcessManager::removeProcess(USHORT procKey) 302 300 { 303 QMutexLocker locker( mutex());301 QMutexLocker locker(); 304 302 Q_ASSERT(instance); 305 303 … … 392 390 // and all complex work is done here asynchronously. 393 391 394 QMutexLocker locker( mutex());392 QMutexLocker locker(); 395 393 APIRET arc; 396 394 … … 480 478 // data to read, or if it fails to write to a (closed) pipe 481 479 } else { 482 d->pipeData[type].bytes = pipeStates[i].usAvail; 480 // update the counter 481 if (d->pipeData[type].newBytes.fetchAndStoreRelaxed(pipeStates[i].usAvail) != 0) { 482 // the object didn't process the previous notification yet; 483 // there is no point to send a new one 484 continue; 485 } 483 486 } 484 485 if (d->pipeData[type].isNew) {486 // the object didn't process the previous notification yet;487 // there is no point to send a new one488 continue;489 }490 491 d->pipeData[type].isNew = true;492 487 493 488 // signal the process object … … 532 527 waitSem = NULLHANDLE; 533 528 534 // Note: after calling QProcessManager::addProcess(), pipeData member must 535 // only be accessed from under QProcessManager::mutex()! 536 memset(pipeData, sizeof(pipeData), 0); 529 pipeData[InPipe].bytesLeft = 0; 530 pipeData[OutPipe].bytesLeft = 0; 531 pipeData[ErrPipe].bytesLeft = 0; 532 537 533 procKey = QProcessManager::InvalidProcKey; 538 534 … … 992 988 qint64 QProcessPrivate::bytesAvailableFromStdout() const 993 989 { 994 qint64 available = 0;995 { 996 QMutexLocker lock(QProcessManager::mutex());997 available = pipeData[OutPipe].bytes;998 // accept new messages from QProcessManager999 const_cast<QProcessPrivate*>(this)->pipeData[OutPipe].isNew = false; 1000 } 1001 #if defined (QPROCESS_DEBUG) 1002 qDebug("QProcessPrivate::bytesAvailableFromStdout() == %lld", available);1003 #endif 1004 return available;990 ; 991 992 993 ; 994 995 996 #if defined (QPROCESS_DEBUG) 997 qDebug("QProcessPrivate::bytesAvailableFromStdout() == %lld", 998 ); 999 #endif 1000 return ; 1005 1001 } 1006 1002 1007 1003 qint64 QProcessPrivate::bytesAvailableFromStderr() const 1008 1004 { 1009 qint64 available = 0;1010 { 1011 QMutexLocker lock(QProcessManager::mutex());1012 available = pipeData[ErrPipe].bytes;1013 // accept new messages from QProcessManager1014 const_cast<QProcessPrivate*>(this)->pipeData[ErrPipe].isNew = false; 1015 } 1016 #if defined (QPROCESS_DEBUG) 1017 qDebug("QProcessPrivate::bytesAvailableFromStderr() == %lld", available);1018 #endif 1019 return available;1005 ; 1006 1007 1008 ; 1009 1010 1011 #if defined (QPROCESS_DEBUG) 1012 qDebug("QProcessPrivate::bytesAvailableFromStderr() == %lld", 1013 ); 1014 #endif 1015 return ; 1020 1016 } 1021 1017 … … 1025 1021 APIRET arc = DosRead(stdoutChannel.pipe.server, data, maxlen, &actual); 1026 1022 1027 // decrement the counter to make sure bytesAvailableFromStdout() will return 1028 // a correct number before QProcessManager::run() updates it 1029 QMutexLocker lock(QProcessManager::mutex()); 1030 if (actual <= (ULONG) pipeData[OutPipe].bytes) 1031 pipeData[OutPipe].bytes -= (USHORT) actual; 1032 else 1033 pipeData[OutPipe].bytes = 0; 1034 1035 qint64 bytesRead = arc == NO_ERROR ? (qint64)actual : -1; 1023 qint64 bytesRead = -1; 1024 if (arc == NO_ERROR) { 1025 bytesRead = (qint64)actual; 1026 // update our counter 1027 Q_ASSERT(pipeData[OutPipe].bytesLeft >= bytesRead); 1028 pipeData[OutPipe].bytesLeft -= bytesRead; 1029 } 1036 1030 1037 1031 #if defined QPROCESS_DEBUG … … 1047 1041 APIRET arc = DosRead(stderrChannel.pipe.server, data, maxlen, &actual); 1048 1042 1049 // decrement the counter to make sure bytesAvailableFromStderr() will return 1050 // a correct number before QProcessManager::run() updates it 1051 QMutexLocker lock(QProcessManager::mutex()); 1052 if (actual <= (ULONG) pipeData[ErrPipe].bytes) 1053 pipeData[ErrPipe].bytes -= (USHORT) actual; 1054 else 1055 pipeData[ErrPipe].bytes = 0; 1056 1057 qint64 bytesRead = arc == NO_ERROR ? (qint64)actual : -1; 1043 qint64 bytesRead = -1; 1044 if (arc == NO_ERROR) { 1045 bytesRead = (qint64)actual; 1046 // update our counter 1047 Q_ASSERT(pipeData[ErrPipe].bytesLeft >= bytesRead); 1048 pipeData[ErrPipe].bytesLeft -= bytesRead; 1049 } 1058 1050 1059 1051 #if defined QPROCESS_DEBUG … … 1071 1063 qint64 written = arc == NO_ERROR ? (qint64)actual : -1; 1072 1064 1073 // accept new messages from QProcessManager 1074 QMutexLocker lock(QProcessManager::mutex()); 1075 const_cast<QProcessPrivate*>(this)->pipeData[InPipe].isNew = false; 1065 QProcessPrivate* that = const_cast<QProcessPrivate*>(this); 1066 1067 // reset the counter so that QProcessManager will inform us again if 1068 // more space is available (note that we don't care about the actual number) 1069 that->pipeData[InPipe].newBytes.fetchAndStoreRelaxed(0); 1076 1070 1077 1071 #if defined QPROCESS_DEBUG … … 1174 1168 failed = true; 1175 1169 } else { 1176 QMutexLocker lock(QProcessManager::mutex());1177 1178 1170 bool readyReadEmitted = false; 1179 if (pipeData[OutPipe]. bytes) {1171 if (pipeData[OutPipe].) { 1180 1172 bool canRead = _q_canReadStandardOutput(); 1181 1173 if (processChannel == QProcess::StandardOutput && canRead) 1182 1174 readyReadEmitted = true; 1183 1175 } 1184 if (pipeData[ErrPipe]. bytes) {1176 if (pipeData[ErrPipe].) { 1185 1177 bool canRead = _q_canReadStandardError(); 1186 1178 if (processChannel == QProcess::StandardError && canRead) … … 1192 1184 } 1193 1185 1194 if (pipeData[InPipe]. bytes)1186 if (pipeData[InPipe].) 1195 1187 _q_canWrite(); 1196 1188 … … 1242 1234 failed = true; 1243 1235 } else { 1244 QMutexLocker lock(QProcessManager::mutex()); 1245 1246 if (pipeData[InPipe].bytes) { 1236 if (pipeData[InPipe].newBytes.fetchAndAddRelaxed(0)) { 1247 1237 waitMode.fetchAndStoreRelaxed(Async); 1248 1238 return _q_canWrite(); 1249 1239 } 1250 1240 1251 if (pipeData[OutPipe]. bytes)1241 if (pipeData[OutPipe].) 1252 1242 _q_canReadStandardOutput(); 1253 1243 1254 if (pipeData[ErrPipe]. bytes)1244 if (pipeData[ErrPipe].) 1255 1245 _q_canReadStandardError(); 1256 1246 … … 1303 1293 failed = true; 1304 1294 } else { 1305 QMutexLocker lock(QProcessManager::mutex()); 1306 1307 if (pipeData[InPipe].bytes) 1295 if (pipeData[InPipe].newBytes.fetchAndAddRelaxed(0)) 1308 1296 _q_canWrite(); 1309 1297 1310 if (pipeData[OutPipe]. bytes)1298 if (pipeData[OutPipe].) 1311 1299 _q_canReadStandardOutput(); 1312 1300 1313 if (pipeData[ErrPipe]. bytes)1301 if (pipeData[ErrPipe].) 1314 1302 _q_canReadStandardError(); 1315 1303 … … 1350 1338 qDosNI(arc = DosWaitEventSem(waitSem, (ULONG)msecs)); 1351 1339 if (arc == NO_ERROR) { 1352 QMutexLocker lock(QProcessManager::mutex()); 1353 ret = pipeData[InPipe].bytes; 1340 ret = pipeData[InPipe].newBytes.fetchAndAddRelaxed(0); 1354 1341 } 1355 1342 } -
trunk/src/corelib/io/qprocess_p.h
r197 r198 236 236 HEV waitSem; 237 237 struct PipeData { 238 qint64 bytes;239 bool isNew;238 ytes; 239 ; 240 240 }; 241 241 PipeData pipeData[3]; // size must match PipeType!
Note:
See TracChangeset
for help on using the changeset viewer.