1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #ifndef PENDINGTHREADSMAINTAINER_H
21 #define PENDINGTHREADSMAINTAINER_H
23 #include <libdolphin_export.h>
30 * If the creator of a thread gets deleted, although the thread is still
31 * working, usually QThread::wait() is invoked. The drawback of this
32 * approach is that the user interface gets blocked for an undefined amount
33 * of time. If the thread does not contain references to the creator, the
34 * deleting can be forwarded to the PendingThreadsMaintainer. In the following
35 * example it is assumed, that m_thread will be 0, if it has been deleted by the
36 * creator after receiving the signal QThread::finished():
39 * ThreadCreator::~ThreadCreator()
42 * PendingThreadsMaintainer::instance().append(m_thread);
48 * The thread will get automatically deleted after it (or has already) been finished.
50 * Implementation note: Connecting to the signal QThread::finished() is
51 * not sufficient, as it is possible that the thread has already emitted
52 * the signal, but the signal has not been received yet by the thread creator.
53 * Because of this a polling is done each 5 seconds to check, whether the
54 * thread has been finished.
56 class LIBDOLPHINPRIVATE_EXPORT PendingThreadsMaintainer
: public QObject
61 static PendingThreadsMaintainer
& instance();
62 virtual ~PendingThreadsMaintainer();
65 * Appends the thread \p thread to the maintainer. The thread
66 * will be deleted by the maintainer after it has been finished.
68 void append(QThread
* thread
);
71 PendingThreadsMaintainer();
77 QList
<QThread
*> m_threads
;
80 friend class PendingThreadsMaintainerSingleton
;