From e223f3a5bcd79f5e72cfc1b6816fcdbe822025eb Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Tue, 6 May 2008 07:44:29 +0200 Subject: [PATCH] More multi-threading fixes, this time for one-file-changes --- hunks/ChangeSet.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/hunks/ChangeSet.cpp b/hunks/ChangeSet.cpp index 2e09cd5..4003d71 100644 --- a/hunks/ChangeSet.cpp +++ b/hunks/ChangeSet.cpp @@ -27,6 +27,7 @@ #include #include #include +#include class HunksFetcher : public QThread { @@ -74,6 +75,7 @@ public: } } } + m_changeSet.lockFile(File()); m_changeSet.allHunksFetched(); // how do we make it be deleted ?... @@ -92,7 +94,7 @@ public: changeSetOnIndex(false), hunksFetcher(0), ref(1), - finishedOneHunk(false) + finishedOneHunk(true) { } @@ -129,7 +131,6 @@ AbstractCommand::ReturnCodes ChangeSet::fillFromDiffFile(QIODevice &file) foreach (File f, readGitDiff(file)) addFile(f); - d->finishedOneHunk = true; if (Logger::verbosity() >= Logger::Debug) { foreach(File f, d->files) { @@ -233,14 +234,17 @@ void ChangeSet::generateHunks() { Q_ASSERT(d->hunksFetcher == 0); d->hunksFetcher = new HunksFetcher(d->files, *this, d->changeSetOnIndex); + d->finishedOneHunk = false; d->hunksFetcher->start(); } void ChangeSet::lockFile(const File &file) { + // qDebug() << "ChangeSet::lockFile"; QMutexLocker ml(&d->fileAccessLock); d->lockedFile = file; - if (d->files.count() == 0 || d->files.at(1) == file) { // as soon as we have done a file, we can start the interaction + if (d->files.count() == 0 || d->files.at(0) != file) { // as soon as we have done a file, we can start the interaction +// qDebug() << " unlock cursorAccessWaiter"; d->cursorAccessLock.lock(); d->finishedOneHunk = true; d->cursorAccessWaiter.wakeAll(); @@ -248,6 +252,7 @@ void ChangeSet::lockFile(const File &file) } d->fileAccessWaiter.wakeAll(); + // qDebug() << "~ChangeSet::lockFile"; } void ChangeSet::removeFile(const File &file) @@ -260,12 +265,13 @@ void ChangeSet::removeFile(const File &file) void ChangeSet::allHunksFetched() { + // qDebug() << "ChangeSet::allHunksFetched"; QMutexLocker ml(&d->fileAccessLock); d->lockedFile = File(); d->fileAccessWaiter.wakeAll(); - d->hunksFetcher->deleteLater(); + d->hunksFetcher->deleteLater(); // TODO delete properly somehow, this will not work since we don't have an eventloop d->hunksFetcher = 0; - // TODO emit something to show to the cursor we have all the changes?? + // qDebug() << "~ChangeSet::allHunksFetched"; } bool ChangeSet::hasAllHunks() const @@ -401,13 +407,17 @@ bool ChangeSet::hasAcceptedChanges() const File ChangeSet::file(int index) const { + // qDebug() << "ChangeSet::file" << index << d->finishedOneHunk; QMutexLocker ml(&d->cursorAccessLock); if (! d->finishedOneHunk) d->cursorAccessWaiter.wait(&d->cursorAccessLock); QMutexLocker ml2(&d->fileAccessLock); while (d->files[index] == d->lockedFile) +// { qDebug() << " waiting for file to be unlocked"; d->fileAccessWaiter.wait(&d->fileAccessLock); +// } + // qDebug() << "ChangeSet::~file"; return d->files[index]; } -- 2.11.4.GIT