| 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_CTASKPROCESSORTHREADBASE_H |
| 22 |
#define KONCLUDE_SCHEDULER_CTASKPROCESSORTHREADBASE_H |
| 23 |
|
| 24 |
// Libraries includes |
| 25 |
#include <QTime> |
| 26 |
|
| 27 |
// Namespace includes |
| 28 |
#include "SchedulerSettings.h" |
| 29 |
#include "CTaskEventHandlerBasedProcessor.h" |
| 30 |
#include "CTaskHandleContext.h" |
| 31 |
#include "CTaskHandleMemoryAllocationManager.h" |
| 32 |
#include "CTaskHandleAlgorithm.h" |
| 33 |
#include "CTaskProcessorContextBase.h" |
| 34 |
#include "CTaskStatusPropagator.h" |
| 35 |
#include "CTaskCallbackExecuter.h" |
| 36 |
#include "CTaskProcessingStatistics.h" |
| 37 |
#include "CTaskReserveQueueConsumer.h" |
| 38 |
#include "CTask.h" |
| 39 |
|
| 40 |
// Other includes |
| 41 |
#include "Scheduler/Events/CSendTaskProcessEvent.h" |
| 42 |
#include "Scheduler/Events/CSendTaskCompleteEvent.h" |
| 43 |
#include "Scheduler/Events/CRequestScheduleTaskEvent.h" |
| 44 |
#include "Scheduler/Events/CResponseScheduleTaskEvent.h" |
| 45 |
#include "Scheduler/Events/CTaskAdditionalAllocationEvent.h" |
| 46 |
#include "Scheduler/Events/CUpdateTaskStatusEvent.h" |
| 47 |
|
| 48 |
#include "Concurrent/Events/CHandleEventsEvent.h" |
| 49 |
#include "Concurrent/CQueuedLinkedEventHandler.h" |
| 50 |
|
| 51 |
// Logger includes |
| 52 |
#include "Logger/CLogger.h" |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
namespace Konclude { |
| 57 |
|
| 58 |
using namespace Concurrent; |
| 59 |
using namespace Utilities::Memory; |
| 60 |
|
| 61 |
namespace Scheduler { |
| 62 |
|
| 63 |
using namespace Events; |
| 64 |
|
| 65 |
//#define KONCLUDE_SCHEDULER_DEBUG_TASK_MEMORY_RELEASE |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
/*! |
| 71 |
* |
| 72 |
* \class CTaskProcessorThreadBase |
| 73 |
* \author Andreas Steigmiller |
| 74 |
* \version 0.1 |
| 75 |
* \brief TODO |
| 76 |
* |
| 77 |
*/ |
| 78 |
class CTaskProcessorThreadBase : public CTaskEventHandlerBasedProcessor, public CThread, public CThreadActivator, public CTaskProcessorCommunicator, public CEventProcessor { |
| 79 |
// public methods |
| 80 |
public: |
| 81 |
//! Constructor |
| 82 |
CTaskProcessorThreadBase(CTaskHandleAlgorithm* taskHandleAlgo, const QString &threadStringName = "TaskProcesserThread"); |
| 83 |
|
| 84 |
//! Destructor |
| 85 |
virtual ~CTaskProcessorThreadBase(); |
| 86 |
|
| 87 |
CTaskProcessingStatistics* getTaskProcessingStatistics(); |
| 88 |
|
| 89 |
virtual CThreadActivator* signalizeEvent(); |
| 90 |
virtual CEventHandler* getEventHandler(); |
| 91 |
|
| 92 |
virtual CTaskProcessorThreadBase* startProcessing(); |
| 93 |
virtual CTaskProcessorThreadBase* stopProcessing(); |
| 94 |
|
| 95 |
cint64 getStatisticTaskProcessed(); |
| 96 |
cint64 getStatisticTaskCompleted(); |
| 97 |
cint64 getStatisticEventProcessed(); |
| 98 |
cint64 getStatisticComputionTime(); |
| 99 |
cint64 getStatisticBlockingTime(); |
| 100 |
|
| 101 |
cint64 getTaskProcessingCount(); |
| 102 |
|
| 103 |
virtual bool canDispenseProcessingTasks(); |
| 104 |
virtual bool requiresProcessingTasks(); |
| 105 |
virtual bool requiresSchedulingTasks(); |
| 106 |
virtual cint64 countDispensableProcessingTasks(); |
| 107 |
virtual cint64 countScheduleableProcessingTasks(); |
| 108 |
virtual cint64 getRecievedTasks(); |
| 109 |
|
| 110 |
CTaskProcessorThreadBase* installCallbackExecuter(CTaskCallbackExecuter* callbackExecuter); |
| 111 |
CTaskProcessorThreadBase* installStatusPropagator(CTaskStatusPropagator* statusPropagator); |
| 112 |
|
| 113 |
virtual CTaskHandleAlgorithm* getTaskHandleAlgorithm(); |
| 114 |
|
| 115 |
bool isProcessing(); |
| 116 |
bool isBlocked(); |
| 117 |
|
| 118 |
|
| 119 |
// protected methods |
| 120 |
protected: |
| 121 |
virtual bool processControlEvents(QEvent::Type type, CControlEvent *event); |
| 122 |
|
| 123 |
virtual bool processEvent(CEvent *event, CContext* handlerContext); |
| 124 |
|
| 125 |
virtual bool processingLoop(); |
| 126 |
|
| 127 |
void organizeDispenseTasks(bool forceUpdate); |
| 128 |
|
| 129 |
virtual CTaskProcessorCommunicator* communicateTaskComplete(CTask* task); |
| 130 |
virtual CTaskProcessorCommunicator* communicateTaskError(CTask* task); |
| 131 |
virtual CTaskProcessorCommunicator* communicateTaskCreation(CTask* newTask); |
| 132 |
virtual CTaskProcessorCommunicator* communicateTaskAdditionalAllocation(CTask* task, CMemoryPool* additionalAllocatedMemoryPool); |
| 133 |
virtual CTaskProcessorCommunicator* communicateTaskStatusUpdate(CTask* task); |
| 134 |
virtual CTaskProcessorCommunicator* communicateTaskRelevant(CTask* task); |
| 135 |
|
| 136 |
virtual bool verifyContinueTaskProcessing(CTask* task); |
| 137 |
|
| 138 |
bool processTask(CTask* task); |
| 139 |
bool addProcessingTask(CTask* task); |
| 140 |
bool handleEvents(); |
| 141 |
|
| 142 |
virtual bool processDispenseNotification() = 0; |
| 143 |
virtual bool processRequestProcessTask() = 0; |
| 144 |
virtual bool processCriticalScheduleTask() = 0; |
| 145 |
virtual bool processCompleteTask(CTask* task) = 0; |
| 146 |
virtual bool processAdditionalTaskAllocation(CTask* task, CMemoryPool* memoryPool) = 0; |
| 147 |
virtual bool processResponseScheduleTask(CTask* task, CTaskScheduleItem* taskScheduleItem, bool schedulingTask) = 0; |
| 148 |
virtual bool processUpdateTaskStatus(CTask* task) = 0; |
| 149 |
virtual bool processUpdateTaskStatus(CTask* parentTask, CTask* updateTask) = 0; |
| 150 |
|
| 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 |
CTaskStatusPropagator* mTaskStatusPropagator; |
| 162 |
CTaskCallbackExecuter* mCallbackExecuter; |
| 163 |
CQueuedLinkedEventHandler* mEventHandler; |
| 164 |
|
| 165 |
|
| 166 |
QSemaphore mProcessingWakeUpSemaphore; |
| 167 |
CXLinker<CEventHandler*>* mEventHandlerLinker; |
| 168 |
|
| 169 |
CTaskReserveQueueConsumer* mTaskReserveQueueConsumer; |
| 170 |
|
| 171 |
|
| 172 |
bool mProcessingStopped; |
| 173 |
|
| 174 |
bool mThreadBlocked; |
| 175 |
|
| 176 |
bool mEventSignalized; |
| 177 |
bool mProcessingBlocked; |
| 178 |
cint64 mLastProcessingStartRequestTag; |
| 179 |
cint64 mLastProcessingStartedTag; |
| 180 |
cint64 mTaskProcessingCount; |
| 181 |
cint64 mTaskParentRelevantCount; |
| 182 |
cint64 mTaskSchedulingCount; |
| 183 |
cint64 mTaskReserveQueueCount; |
| 184 |
cint64 mCriticalSchedulingCount; |
| 185 |
cint64 mCriticalSchedulingThresholdCount; |
| 186 |
cint64 mRecievedTasks; |
| 187 |
bool mCriticalSchedulingNotified; |
| 188 |
|
| 189 |
bool mProcessTaskRequesting; |
| 190 |
|
| 191 |
bool mMinimalPriorityTaskInvalidated; |
| 192 |
double mMinTaskPriority; |
| 193 |
CTask* mMinPriorityTask; |
| 194 |
|
| 195 |
bool mConfScheduleTasksDistribution; |
| 196 |
bool mConfProcessingTasksDistribution; |
| 197 |
bool mConfUseReserveTasksQueue; |
| 198 |
|
| 199 |
bool mConfProcessReserveTasks; |
| 200 |
bool mConfProcessSchedulingTasks; |
| 201 |
|
| 202 |
CTaskProcessingStatistics mStats; |
| 203 |
cint64 mStatComputionTime; |
| 204 |
cint64 mStatBlockingTime; |
| 205 |
|
| 206 |
#ifdef KONCLUDE_SCHEDULER_TASK_THREADS_TIME_STATISTICS |
| 207 |
QTime mComputionTimer; |
| 208 |
QTime mBlockingTimer; |
| 209 |
#endif |
| 210 |
|
| 211 |
// for debugging only |
| 212 |
CTask* mLastProcessedTask; |
| 213 |
CTask* mLastDispendedTask; |
| 214 |
CEvent* mLastProcessedEvent; |
| 215 |
|
| 216 |
// private methods |
| 217 |
private: |
| 218 |
|
| 219 |
// private variables |
| 220 |
private: |
| 221 |
|
| 222 |
}; |
| 223 |
|
| 224 |
}; // end namespace Scheduler |
| 225 |
|
| 226 |
}; // end namespace Konclude |
| 227 |
|
| 228 |
#endif // KONCLUDE_SCHEDULER_CTASKPROCESSORTHREADBASE_H |