# # # patch "src/monotone/MonotoneThread.cpp" # from [d1c6c3dddc22a0bf421a81241db596ecd7ab2cde] # to [7a52cb70225dfe2926657f89a35b7402d315016d] # # patch "src/monotone/MonotoneThread.h" # from [0d826631d00d340b7d1b2bc60acc27a78b517827] # to [031a0d05e8b118a3fccc468c8b90b959ed89d0d2] # ============================================================ --- src/monotone/MonotoneThread.cpp d1c6c3dddc22a0bf421a81241db596ecd7ab2cde +++ src/monotone/MonotoneThread.cpp 7a52cb70225dfe2926657f89a35b7402d315016d @@ -137,12 +137,17 @@ int MonotoneThread::enqueueTask(const Mo int MonotoneThread::enqueueTask(const MonotoneTask & task) { QMutexLocker locker(&lock); + if (doAbort) return -1; + commandNumber++; MonotoneTask workItem(task); workItem.setCommandNumber(commandNumber); workItem.setThreadNumber(threadNumber); queue.enqueue(workItem); + + waitForTasks.wakeAll(); + D(QString("thread %1: new task enqueued: %2").arg(threadNumber).arg(QString(task.getEncodedInput()))); return commandNumber; } @@ -176,10 +181,10 @@ void MonotoneThread::run() return; } + D(QString("thread %1: process started").arg(threadNumber)); emit started(threadNumber); QTextStream streamProcess(process); - QByteArray buffer; QByteArray output; @@ -196,7 +201,11 @@ void MonotoneThread::run() return; } - if (queue.size() == 0) continue; + // send the thread to sleep if there are no tasks to process + lock.lock(); + if (queue.size() == 0) + waitForTasks.wait(&lock); + lock.unlock(); if (!processingTask) { @@ -215,7 +224,22 @@ void MonotoneThread::run() return; } - // FIXME: what about stderr output here? + // we currently assume that all stderr output from stdio is evil + QByteArray err = process->readAllStandardError(); + if (err.size() != 0) + { + MonotoneTask task = queue.dequeue(); + task.setOutput(err); + task.setReturnCode(-1); + task.setFinished(); + + processingTask = false; + output.clear(); + + emit taskAborted(task); + continue; + } + buffer.append(process->readAllStandardOutput()); StdioParser parser(buffer); @@ -242,6 +266,9 @@ void MonotoneThread::run() processingTask = false; output.clear(); + D(QString("thread %1: task %2 (%3) finished").arg(threadNumber) + .arg(task.getCommandNumber()).arg(QString(task.getEncodedInput()))); + emit taskFinished(task); } cleanup(process); ============================================================ --- src/monotone/MonotoneThread.h 0d826631d00d340b7d1b2bc60acc27a78b517827 +++ src/monotone/MonotoneThread.h 031a0d05e8b118a3fccc468c8b90b959ed89d0d2 @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "vocab.h" @@ -154,6 +155,7 @@ private: QString workspacePath; QQueue queue; QMutex lock; + QWaitCondition waitForTasks; }; #endif