]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/versioncontrol/pendingthreadsmaintainer.h
Coding style update for pointer comparison
[dolphin.git] / src / views / versioncontrol / pendingthreadsmaintainer.h
1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #ifndef PENDINGTHREADSMAINTAINER_H
21 #define PENDINGTHREADSMAINTAINER_H
22
23 #include <libdolphin_export.h>
24
25 #include <QObject>
26
27 class QTimer;
28
29 /**
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():
37 *
38 * \code
39 * ThreadCreator::~ThreadCreator()
40 * {
41 * if (m_thread) {
42 * PendingThreadsMaintainer::instance().append(m_thread);
43 * m_thread = 0;
44 * }
45 * }
46 * \endcode
47 *
48 * The thread will get automatically deleted after it (or has already) been finished.
49 *
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.
55 */
56 class LIBDOLPHINPRIVATE_EXPORT PendingThreadsMaintainer : public QObject
57 {
58 Q_OBJECT
59
60 public:
61 static PendingThreadsMaintainer& instance();
62 virtual ~PendingThreadsMaintainer();
63
64 /**
65 * Appends the thread \p thread to the maintainer. The thread
66 * will be deleted by the maintainer after it has been finished.
67 */
68 void append(QThread* thread);
69
70 protected:
71 PendingThreadsMaintainer();
72
73 private slots:
74 void cleanup();
75
76 private:
77 QList<QThread*> m_threads;
78 QTimer* m_timer;
79
80 friend class PendingThreadsMaintainerSingleton;
81 };
82
83 #endif