From 884e95cc985ccf3a7d9de9ebe0d9b1bbd2d9e706 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Wed, 24 Mar 2010 22:21:09 +0000 Subject: Version control: Move the maintainance of pending threads into a custom class. Also the UpdateItemStatesThread differs now between protecting the globally shared plugin and the locally shared data. svn path=/trunk/KDE/kdebase/apps/; revision=1107125 --- src/versioncontrol/pendingthreadsmaintainer.cpp | 77 +++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/versioncontrol/pendingthreadsmaintainer.cpp (limited to 'src/versioncontrol/pendingthreadsmaintainer.cpp') diff --git a/src/versioncontrol/pendingthreadsmaintainer.cpp b/src/versioncontrol/pendingthreadsmaintainer.cpp new file mode 100644 index 000000000..f61c79975 --- /dev/null +++ b/src/versioncontrol/pendingthreadsmaintainer.cpp @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright (C) 2010 by Peter Penz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "pendingthreadsmaintainer.h" + +#include +#include +#include + +struct PendingThreadsMaintainerSingleton +{ + PendingThreadsMaintainer instance; +}; +K_GLOBAL_STATIC(PendingThreadsMaintainerSingleton, s_pendingThreadsMaintainer) + + +PendingThreadsMaintainer& PendingThreadsMaintainer::instance() +{ + return s_pendingThreadsMaintainer->instance; +} + +PendingThreadsMaintainer::~PendingThreadsMaintainer() +{ +} + +void PendingThreadsMaintainer::append(QThread* thread) +{ + Q_ASSERT(thread != 0); + m_threads.append(thread); + m_timer->start(); +} + +PendingThreadsMaintainer::PendingThreadsMaintainer() : + QObject(), + m_threads(), + m_timer(0) +{ + m_timer = new QTimer(this); + m_timer->setSingleShot(true); + m_timer->setInterval(5000); // 5 seconds + connect(m_timer, SIGNAL(timeout()), this, SLOT(cleanup())); +} + +void PendingThreadsMaintainer::cleanup() +{ + QList::iterator it = m_threads.begin(); + while (it != m_threads.end()) { + if ((*it)->isFinished()) { + (*it)->deleteLater(); + it = m_threads.erase(it); + } else { + ++it; + } + } + + if (!m_threads.isEmpty()) { + m_timer->start(); + } +} + +#include "pendingthreadsmaintainer.moc" -- cgit v1.3