Debian Codegraph @

Source/Scheduler/CSingleThreadTaskProcessorUnit.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
21 #ifndef KONCLUDE_SCHEDULER_CSINGLETHREADTASKPROCESSORUNIT_H
22 #define KONCLUDE_SCHEDULER_CSINGLETHREADTASKPROCESSORUNIT_H
23
24 // Libraries includes
25
26
27 // Namespace includes
28 #include "SchedulerSettings.h"
29 #include "CTaskEventHandlerBasedProcessor.h"
30 #include "CTaskEventHandlerBasedCompletor.h"
31 #include "CTaskEventHandlerBasedScheduler.h"
32 #include "CTaskHandleContext.h"
33 #include "CTaskHandleMemoryAllocationManager.h"
34 #include "CTaskHandleMemoryPoolAllocationManager.h"
35 #include "CTaskHandleLimitedReserveMemoryPoolAllocationManager.h"
36 #include "CTaskHandleAlgorithm.h"
37 #include "CTaskProcessorContextBase.h"
38 #include "CTaskStatusPropagator.h"
39 #include "CTaskCallbackExecuter.h"
40 #include "CTaskProcessingStatistics.h"
41 #include "CTask.h"
42
43 // Other includes
44 #include "Utilities/Memory/CNewAllocationMemoryPoolProvider.h"
45 #include "Utilities/Memory/CConsiderateMemoryPoolProvider.h"
46
47 #include "Scheduler/Events/CSendTaskProcessEvent.h"
48 #include "Scheduler/Events/CSendTaskCompleteEvent.h"
49 #include "Scheduler/Events/CSendTaskScheduleEvent.h"
50 #include "Scheduler/Events/CRequestScheduleTaskEvent.h"
51 #include "Scheduler/Events/CResponseScheduleTaskEvent.h"
52 #include "Scheduler/Events/CTaskAdditionalAllocationEvent.h"
53 #include "Scheduler/Events/CRequestProcessTaskEvent.h"
54
55 #include "Concurrent/Events/CHandleEventsEvent.h"
56 #include "Concurrent/CQueuedLinkedEventHandler.h"
57
58 // Logger includes
59 #include "Logger/CLogger.h"
60
61
62
63 namespace Konclude {
64
65 using namespace Concurrent;
66 using namespace Utilities::Memory;
67
68 namespace Scheduler {
69
70 using namespace Events;
71
72
73 /*!
74 *
75 * \class CSingleThreadTaskProcessorUnit
76 * \author Andreas Steigmiller
77 * \version 0.1
78 * \brief TODO
79 *
80 */
81 class CSingleThreadTaskProcessorUnit : virtual public CTaskEventHandlerBasedProcessor, virtual public CTaskEventHandlerBasedCompletor, virtual public CTaskEventHandlerBasedScheduler, public CThread, public CThreadActivator, public CTaskProcessorCommunicator, public CEventProcessor {
82 // public methods
83 public:
84 //! Constructor
85 CSingleThreadTaskProcessorUnit(CTaskHandleAlgorithm* taskHandleAlgo, CConsiderateMemoryPoolProvider* memoryPoolProvider = nullptr);
86
87 //! Destructor
88 virtual ~CSingleThreadTaskProcessorUnit();
89
90 virtual CTaskEventHandlerBasedProcessor* installScheduler(CTaskEventHandlerBasedScheduler* scheduler);
91 virtual CTaskSchedulerCommunicator* createSchedulerProcessorCommunication(CTaskEventHandlerBasedProcessor* taskProcessor);
92 virtual CTaskReserveQueueConsumer* createTaskReserveQueueConsumer(CTaskEventHandlerBasedProcessor* taskProcessor);
93
94 virtual CThreadActivator* signalizeEvent();
95 virtual CEventHandler* getEventHandler();
96
97 virtual CSingleThreadTaskProcessorUnit* startProcessing();
98 virtual CSingleThreadTaskProcessorUnit* stopProcessing();
99
100 virtual bool processEvent(CEvent *event, CContext* handlerContext);
101
102 CTaskProcessingStatistics* getTaskProcessingStatistics();
103 cint64 getStatisticComputionTime();
104 cint64 getStatisticBlockingTime();
105
106 cint64 getTaskProcessingCount();
107 virtual cint64 getRecievedTasks();
108
109 virtual bool canDispenseProcessingTasks();
110 virtual bool requiresProcessingTasks();
111 virtual bool requiresSchedulingTasks();
112 virtual cint64 countDispensableProcessingTasks();
113 virtual bool requiresTaskDispenseNotification(cint64 &updateDispenseNotificationTag);
114 virtual cint64 countScheduleableProcessingTasks();
115
116 CSingleThreadTaskProcessorUnit* installCallbackExecuter(CTaskCallbackExecuter* callbackExecuter);
117 CSingleThreadTaskProcessorUnit* installStatusPropagator(CTaskStatusPropagator* statusPropagator);
118
119 virtual CTaskHandleAlgorithm* getTaskHandleAlgorithm();
120
121
122 // protected methods
123 protected:
124 virtual bool processControlEvents(QEvent::Type type, CControlEvent *event);
125
126 bool addProcessingTask(CTask* task);
127
128
129 virtual bool processingLoop();
130
131 virtual CTaskProcessorCommunicator* communicateTaskComplete(CTask* task);
132 virtual CTaskProcessorCommunicator* communicateTaskError(CTask* task);
133 virtual CTaskProcessorCommunicator* communicateTaskCreation(CTask* newTask);
134 virtual CTaskProcessorCommunicator* communicateTaskAdditionalAllocation(CTask* task, CMemoryPool* additionalAllocatedMemoryPool);
135 virtual CTaskProcessorCommunicator* communicateTaskStatusUpdate(CTask* task);
136 virtual CTaskProcessorCommunicator* communicateTaskRelevant(CTask* task);
137
138 virtual bool verifyContinueTaskProcessing(CTask* task);
139
140
141 virtual cint64 completeTask(CTask* task);
142 virtual bool updateTaskStatus(CTask* task);
143 virtual bool updateTaskStatusDown(CTask* task, cint64 depth);
144 virtual bool processTask(CTask* task);
145
146 virtual bool handleEvents();
147
148 cint64 countProcessingTasksMemoryPools();
149 cint64 countProcessedOpenTasksMemoryPools();
150 cint64 closeOpenTasksMemoryPools();
151
152
153 // protected variables
154 protected:
155 CTask* mTaskSchedulingQueue;
156 CTask* mTaskProcessingQueue;
157 CTask* mTaskCompletionQueue;
158 CTaskProcessorContext *mTaskProcessorContext;
159 CTaskHandleMemoryAllocationManager *mMemoryAllocator;
160 CTaskHandleAlgorithm* mTaskHandleAlgo;
161 CQueuedLinkedEventHandler* mEventHandler;
162 CTaskStatusPropagator* mTaskStatusPropagator;
163 CTaskCallbackExecuter* mCallbackExecuter;
164 CConsiderateMemoryPoolProvider* mMemoryPoolProvider;
165
166
167 QSemaphore mProcessingWakeUpSemaphore;
168 CXLinker<CEventHandler*>* mEventHandlerLinker;
169
170 bool mProcessingStopped;
171
172 bool mThreadBlocked;
173
174
175 bool mEventSignalized;
176 bool mProcessingBlocked;
177 cint64 mLastProcessingStartRequestTag;
178 cint64 mLastProcessingStartedTag;
179 cint64 mTaskProcessingCount;
180 cint64 mTaskSchedulingCount;
181
182 CTaskProcessingStatistics mStats;
183 cint64 mStatComputionTime;
184 cint64 mStatBlockingTime;
185 cint64 mStatRecievedScheduleTasks;
186 cint64 mStatRemovedTasks;
187
188 #ifdef KONCLUDE_SCHEDULER_TASK_THREADS_TIME_STATISTICS
189 QTime mComputionTimer;
190 QTime mBlockingTimer;
191 #endif
192
193
194 CTask* mDebugLastCompletedTask;
195 CTask* mDebugLastProcessedTask;
196
197 // private methods
198 private:
199
200 // private variables
201 private:
202
203 };
204
205 }; // end namespace Scheduler
206
207 }; // end namespace Konclude
208
209 #endif // KONCLUDE_SCHEDULER_CSINGLETHREADTASKPROCESSORUNIT_H