Debian Codegraph @

Source/Concurrent/CWatchDogThread.h

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20 #ifndef KONCLUDE_CONCURRENT_CWATCHDOGTHREAD_H
21 #define KONCLUDE_CONCURRENT_CWATCHDOGTHREAD_H
22
23
24 #include <QSemaphore>
25 #include <QReadWriteLock>
26 #include <QHash>
27 #include <QDateTime>
28 #include <QLinkedList>
29
30 #include "CThread.h"
31 #include "CIntervalThread.h"
32 #include "CWatchDogThreadData.h"
33 #include "CWatchDog.h"
34 #include "ConcurrentSettings.h"
35
36
37 #include "Events/CCustomEvent.h"
38 #include "Events/CControlEvent.h"
39
40
41
42 namespace Konclude {
43
44 namespace Concurrent {
45
46 using namespace Events;
47
48
49 /*!
50 * \class CWatchDogThread
51 * \author Andreas Steigmiller
52 * \version 0.1
53 * \brief
54 */
55 class CWatchDogThread : public CIntervalThread, public CWatchDog {
56
57 // public methods
58 public:
59 //! Constructor
60 CWatchDogThread();
61
62 //! Destructor
63 virtual ~CWatchDogThread();
64
65
66 static CWatchDogThread *getInstance();
67
68 bool registerThread(CThread *thread);
69 void feedbackThread(CThread *thread, qint64 updateNumber);
70 void checkoutThread(CThread *thread);
71 void crashedThread(CThread *thread);
72
73 QLinkedList<CWatchDogThreadData> getActiveThreadList();
74
75
76 // protected methods
77 protected:
78
79 virtual void threadStarted();
80
81 virtual bool processCustomsEvents(QEvent::Type type, CCustomEvent *event);
82
83 virtual bool processTimer(qint64 timerID);
84
85 // private methods
86 private:
87
88 void sendRequestFeedbackEvent(CThread *thread, qint64 uNr);
89 void updateThreadData(CThread *thread, CWatchDogThreadData *threadData);
90
91
92 // private variables
93 private:
94 static const qint64 REQUESTFEEDBACKTIMERID = 1;
95 static const qint64 UPDATETHREADINFOTIMERID = 2;
96
97 static CWatchDogThread *watchDogInstance;
98 static QSemaphore *syncSemaphore;
99
100 QReadWriteLock regSync;
101 QHash<qint64,CWatchDogThreadData *> threadWatch;
102
103 qint64 currentUpdateNumber;
104
105 };
106
107 }; // end namespace Concurrent
108
109 }; // end namespace Konclude
110
111 #endif // KONCLUDE_CONCURRENT_CWATCHDOGTHREAD_H