# # # patch "src/monotone/MonotoneThread.cpp" # from [dce2c0128306f3c8316e73bdee982dd121571760] # to [aa371bf1e9c55b57371417d36127fb1723526c7b] # # patch "src/monotone/MonotoneThread.h" # from [38117b009f3e7a519cce82f7e725ecf3b19d8ce4] # to [137aa57d261f140e9e824d758fe89a24ad1c88d0] # ============================================================ --- src/monotone/MonotoneThread.cpp dce2c0128306f3c8316e73bdee982dd121571760 +++ src/monotone/MonotoneThread.cpp aa371bf1e9c55b57371417d36127fb1723526c7b @@ -34,6 +34,8 @@ MonotoneTask::MonotoneTask(const Monoton { returnCode = other.returnCode; commandNumber = other.commandNumber; + threadNumber = other.threadNumber; + finished = other.finished; arguments = other.arguments; options = other.options; output = other.output; @@ -64,6 +66,7 @@ void MonotoneTask::init(const ByteArrayL arguments = args; options = opts; returnCode = -1; + finished = false; static bool initialized = false; if (!initialized) @@ -123,8 +126,10 @@ const int MonotoneThread::StdioBufferSiz const int MonotoneThread::StdioBufferSize = 50 * 1024 * 1024; -MonotoneThread::MonotoneThread(const QString & m, const QString & d, const QString & w) - : QThread(), doAbort(false), commandNumber(0), mtnBinary(m), databasePath(d), workspacePath(w) +MonotoneThread::MonotoneThread( + int thread, const QString & m, const QString & d, const QString & w +) : QThread(), doAbort(false), commandNumber(0), threadNumber(thread), + mtnBinary(m), databasePath(d), workspacePath(w) {} MonotoneThread::~MonotoneThread() {} @@ -136,6 +141,7 @@ int MonotoneThread::enqueueTask(const Mo commandNumber++; MonotoneTask workItem(task); workItem.setCommandNumber(commandNumber); + workItem.setThreadNumber(threadNumber); queue.enqueue(workItem); return commandNumber; } @@ -163,13 +169,15 @@ void MonotoneThread::run() if (!process->waitForStarted()) { - emit aborted(process->error(), + emit aborted(threadNumber, process->error(), QString::fromUtf8(process->readAllStandardError()) ); cleanup(process); return; } + emit started(threadNumber); + QTextStream streamProcess(process); QByteArray buffer; @@ -181,7 +189,7 @@ void MonotoneThread::run() { if (process->state() != QProcess::Running) { - emit aborted(process->error(), + emit aborted(threadNumber, process->error(), QString::fromUtf8(process->readAllStandardError()) ); cleanup(process); @@ -200,7 +208,7 @@ void MonotoneThread::run() if (!process->waitForReadyRead(-1)) { - emit aborted(process->error(), + emit aborted(threadNumber, process->error(), QString::fromUtf8(process->readAllStandardError()) ); cleanup(process); @@ -230,6 +238,7 @@ void MonotoneThread::run() MonotoneTask task = queue.dequeue(); task.setOutput(output); task.setReturnCode(returnCode); + task.setFinished(); processingTask = false; output.clear(); @@ -281,8 +290,10 @@ MonotoneThread * MonotoneThreadManager:: { if (!threadMap.contains(database)) { - // TODO: connect to taskAborted here - MonotoneThread * thread = new MonotoneThread(mtnPath, database, workspace); + // TODO: connect to started(int) and aborted(int, ...) here + // and wait for started() + MonotoneThread * thread = + new MonotoneThread(threadNumber++, mtnPath, database, workspace); threadMap.insert(database, thread); } @@ -291,7 +302,7 @@ MonotoneThread * MonotoneThreadManager:: MonotoneThread * thread = threadMap.value(database); if (!thread->isRunning()) { - // TODO: disconnect from taskAborted here + // TODO: disconnect from started(int) and aborted(int, ...) here delete thread; threadMap.remove(database); // up to the next round @@ -383,13 +394,8 @@ QString MonotoneThreadManager::getDataba return databaseFilePath; } -void MonotoneThreadManager::aborted(QProcess::ProcessError error, const QString & message) +void MonotoneThreadManager::aborted(int threadNumber, QProcess::ProcessError error, const QString & message) { // FIXME: many-to-one resolution } -void MonotoneThreadManager::taskAborted(const MonotoneTask & task) -{ - // FIXME: many-to-one resolution -} - ============================================================ --- src/monotone/MonotoneThread.h 38117b009f3e7a519cce82f7e725ecf3b19d8ce4 +++ src/monotone/MonotoneThread.h 137aa57d261f140e9e824d758fe89a24ad1c88d0 @@ -40,8 +40,10 @@ public: MonotoneTask(const ByteArrayList &, const ByteArrayList &); void setCommandNumber(int num) { commandNumber = num; } + void setThreadNumber(int num) { threadNumber = num; } void setOutput(const QByteArray & out) { output = out; } void setReturnCode(int code) { returnCode = code; } + void setFinished() { finished = true; } QByteArray getEncodedInput() const; ByteArrayList getArguments() const { return arguments; } @@ -50,6 +52,8 @@ public: QString getOutputUtf8() const { return QString::fromUtf8(output); } int getReturnCode() const { return returnCode; } int getCommandNumber() const { return commandNumber; } + int getThreadNumber() const { return threadNumber; } + bool isFinished() const { return finished; } private: void init(const ByteArrayList &, const ByteArrayList &); @@ -57,6 +61,8 @@ private: int returnCode; int commandNumber; + int threadNumber; + bool finished; ByteArrayList arguments; ByteArrayList options; @@ -68,11 +74,12 @@ public: Q_OBJECT public: - MonotoneThread(const QString &, const QString &, const QString & workspace = QString()); + MonotoneThread(int, const QString &, const QString &, const QString & workspace = QString()); ~MonotoneThread(); - QString getDatabaseFilePath() const { return databasePath; } - QString getWorkspacePath() const { return workspacePath; } - int getQueueCount() const { return queue.size(); } + inline QString getDatabaseFilePath() const { return databasePath; } + inline QString getWorkspacePath() const { return workspacePath; } + inline int getQueueCount() const { return queue.size(); } + inline int getThreadNumber() const { return threadNumber; } protected: void run(); @@ -84,7 +91,8 @@ signals: signals: void taskFinished(const MonotoneTask &); void taskAborted(const MonotoneTask &); - void aborted(QProcess::ProcessError, const QString &); + void started(int); + void aborted(int, QProcess::ProcessError, const QString &); private: void cleanup(QProcess *); @@ -93,6 +101,7 @@ private: bool doAbort; int commandNumber; + int threadNumber; QString mtnBinary; QString databasePath; QString workspacePath; @@ -105,7 +114,7 @@ public: Q_OBJECT public: - MonotoneThreadManager(const QString & p) : mtnPath(p) {}; + MonotoneThreadManager(const QString & p) : mtnPath(p), threadNumber(0) {}; ~MonotoneThreadManager() {}; inline void setMtnBinaryPath(const QString & path) { mtnPath = path; } @@ -116,12 +125,12 @@ private: QMap threadMap; QMap workspaceMap; QString mtnPath; + int threadNumber; QString getDatabaseFilePath(const QString &); QString normalizeWorkspacePath(const QString &); private slots: - void aborted(QProcess::ProcessError, const QString &); - void taskAborted(const MonotoneTask &); + void aborted(int, QProcess::ProcessError, const QString &); }; #endif