| 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 |
#include "CTaskProcessorSchedulerThread.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Scheduler { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
CTaskProcessorSchedulerThread::CTaskProcessorSchedulerThread(CTaskHandleAlgorithm* taskHandleAlgo, CTaskEventHandlerBasedDistributionCompletor* distributorCompletor, CConsiderateMemoryPoolProvider* memoryPoolProvider) : CTaskProcessorThreadBase(taskHandleAlgo,"TaskProcesserSchedulerThread") { |
| 31 |
mDistributorCompletorCommunicator = new CTaskDistributionCompletorCommunicator(distributorCompletor,this); |
| 32 |
mMemoryPoolReleaser = new CEventDistributionMemoryPoolReleaser(mDistributorCompletorCommunicator); |
| 33 |
mMemoryPoolProvider = memoryPoolProvider; |
| 34 |
if (!mMemoryPoolProvider) { |
| 35 |
//mMemoryPoolProvider = distributorCompletor->createDistributionMemoryPoolProvider(mMemoryPoolReleaser); |
| 36 |
mMemoryPoolProvider = new CNewAllocationMemoryPoolProvider(); |
| 37 |
} |
| 38 |
mMemoryAllocator = new CTaskHandleLimitedReserveMemoryPoolAllocationManager(mMemoryPoolProvider,80000,30); |
| 39 |
mTaskProcessorContext = new CTaskProcessorContextBase(this,mMemoryAllocator); |
| 40 |
|
| 41 |
|
| 42 |
mFreeSchedulerItemLinker = nullptr; |
| 43 |
mWaitingSchedulerItemLinker = nullptr; |
| 44 |
mSchedulerCommunicatorLinker = nullptr; |
| 45 |
|
| 46 |
mRequestingTaskCount = 0; |
| 47 |
mDeliveringWaitingCount = 0; |
| 48 |
mRequiresTaskDispenseNotification = false; |
| 49 |
mSchedulerDispenseNotificationTag = 0; |
| 50 |
mDispenseNotificationTag = 0; |
| 51 |
mProcessorWithCriticalScheduleTask = false; |
| 52 |
|
| 53 |
mSchedulerCommunicator = nullptr; |
| 54 |
mLastScheduledTask = nullptr; |
| 55 |
|
| 56 |
mTaskReserveQueue = new CTaskReserveArrayQueue(10000); |
| 57 |
mTaskReserveQueueController = nullptr; |
| 58 |
//mTaskReserveQueue = new CTaskReserveMultiArrayQueue(10000); |
| 59 |
//mTaskReserveQueueController = new CTaskReserveMultiArrayQueueAdderController(mTaskReserveQueue); |
| 60 |
} |
| 61 |
|
| 62 |
CTaskProcessorSchedulerThread::~CTaskProcessorSchedulerThread() { |
| 63 |
} |
| 64 |
|
| 65 |
bool CTaskProcessorSchedulerThread::requiresSchedulingTasks() { |
| 66 |
return false; |
| 67 |
} |
| 68 |
|
| 69 |
CTaskReserveQueue* CTaskProcessorSchedulerThread::getTaskReserveQueue() { |
| 70 |
return mTaskReserveQueue; |
| 71 |
} |
| 72 |
|
| 73 |
CTaskReserveQueueAdder* CTaskProcessorSchedulerThread::createTaskReserveQueueAdder() { |
| 74 |
if (mTaskReserveQueueController) { |
| 75 |
return mTaskReserveQueueController->createTaskReserveQueueAdder(); |
| 76 |
} else { |
| 77 |
return nullptr; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
bool CTaskProcessorSchedulerThread::requiresTaskDispenseNotification(cint64 &updateDispenseNotificationTag) { |
| 82 |
bool requiresNotification = updateDispenseNotificationTag != mSchedulerDispenseNotificationTag; |
| 83 |
updateDispenseNotificationTag = mSchedulerDispenseNotificationTag; |
| 84 |
return requiresNotification; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
CTaskSchedulerCommunicator* CTaskProcessorSchedulerThread::createSchedulerProcessorCommunication(CTaskEventHandlerBasedProcessor* taskProcessor) { |
| 89 |
CConcreteTaskSchedulerCommunicator* taskSchedulerCommunicator = new CConcreteTaskSchedulerCommunicator(this,taskProcessor); |
| 90 |
mCreateCommunicatorSyncMutex.lock(); |
| 91 |
mSchedulerCommunicatorLinker = new CXLinker<CConcreteTaskSchedulerCommunicator*>(taskSchedulerCommunicator,mSchedulerCommunicatorLinker); |
| 92 |
mCreateCommunicatorSyncMutex.unlock(); |
| 93 |
return taskSchedulerCommunicator; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
CTaskReserveQueueConsumer* CTaskProcessorSchedulerThread::createTaskReserveQueueConsumer(CTaskEventHandlerBasedProcessor* taskProcessor) { |
| 98 |
CTaskReserveQueueConsumer* consumer = nullptr; |
| 99 |
if (mConfUseReserveTasksQueue && mTaskReserveQueue) { |
| 100 |
consumer = mTaskReserveQueue->createTaskReserveQueueConsumer(); |
| 101 |
} |
| 102 |
return consumer; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
CTaskEventHandlerBasedProcessor* CTaskProcessorSchedulerThread::installScheduler(CTaskEventHandlerBasedScheduler* scheduler) { |
| 107 |
mTaskReserveQueueConsumer = scheduler->createTaskReserveQueueConsumer(this); |
| 108 |
CTaskSchedulerCommunicator* schedulerCommunicator = scheduler->createSchedulerProcessorCommunication(this); |
| 109 |
installSchedulerCommunicator(schedulerCommunicator); |
| 110 |
return this; |
| 111 |
} |
| 112 |
|
| 113 |
CTaskProcessorSchedulerThread* CTaskProcessorSchedulerThread::installSchedulerCommunicator(CTaskSchedulerCommunicator* schedulerCommunicator) { |
| 114 |
mSchedulerCommunicator = schedulerCommunicator; |
| 115 |
processSchedulerRequestProcessTask(mSchedulerCommunicator); |
| 116 |
return this; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
bool CTaskProcessorSchedulerThread::processEvent(CEvent *event, CContext* handlerContext) { |
| 122 |
mLastProcessedEvent = event; |
| 123 |
cint64 eventID = event->getEventTypeID(); |
| 124 |
if (eventID == CSendTaskScheduleEvent::EVENTTYPEID) { |
| 125 |
CTask* taskIt = ((CSendTaskScheduleEvent*)event)->getTask(); |
| 126 |
while (taskIt) { |
| 127 |
CTask* task = taskIt; |
| 128 |
taskIt = taskIt->getNext(); |
| 129 |
task->clearNext(); |
| 130 |
processSchedulerScheduleTask(task,true); |
| 131 |
} |
| 132 |
mMemoryAllocator->releaseMemoryPoolContainer(event); |
| 133 |
return true; |
| 134 |
} else if (eventID == CRequestProcessTaskEvent::EVENTTYPEID) { |
| 135 |
CRequestProcessTaskEvent* reqEvent = (CRequestProcessTaskEvent*)event; |
| 136 |
processSchedulerRequestProcessTask(reqEvent->getCommunicator()); |
| 137 |
mMemoryAllocator->releaseMemoryPoolContainer(event); |
| 138 |
return true; |
| 139 |
} else if (eventID == CTaskDispenseNotificationEvent::EVENTTYPEID) { |
| 140 |
CTaskDispenseNotificationEvent* disNotEvent = (CTaskDispenseNotificationEvent*)event; |
| 141 |
processSchedulerDispenseNotification(disNotEvent->getCommunicator()); |
| 142 |
mMemoryAllocator->releaseMemoryPoolContainer(event); |
| 143 |
return true; |
| 144 |
} else if (eventID == CCriticalScheduleTaskEvent::EVENTTYPEID) { |
| 145 |
CCriticalScheduleTaskEvent* criticalScheduleTasksEvent = (CCriticalScheduleTaskEvent*)event; |
| 146 |
processSchedulingScheduleTasks(); |
| 147 |
mMemoryAllocator->releaseMemoryPoolContainer(event); |
| 148 |
return true; |
| 149 |
} else if (eventID == CResponseScheduleTaskEvent::EVENTTYPEID) { |
| 150 |
CResponseScheduleTaskEvent* resEvent = (CResponseScheduleTaskEvent*)event; |
| 151 |
processSchedulerResponseScheduleTask(resEvent->getTask(),resEvent->getCommunicator(),resEvent->getTaskScheduleItem(),resEvent->isSchedulingTask()); |
| 152 |
mMemoryAllocator->releaseMemoryPoolContainer(event); |
| 153 |
return true; |
| 154 |
} else if (CTaskProcessorThreadBase::processEvent(event,handlerContext)) { |
| 155 |
return true; |
| 156 |
} else { |
| 157 |
// not supported |
| 158 |
} |
| 159 |
return false; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
bool CTaskProcessorSchedulerThread::processUpdateTaskStatus(CTask* updateTask) { |
| 164 |
CTask* parentTask = updateTask->getParentTask(); |
| 165 |
if (!parentTask || parentTask->hasNoTaskOwnerAndNoParentTask() || parentTask->hasTaskOwner(this)) { |
| 166 |
// update status local |
| 167 |
bool downProp = false; |
| 168 |
bool upProp = false; |
| 169 |
if (mTaskStatusPropagator && mTaskStatusPropagator->updateTaskStatus(updateTask,downProp,upProp)) { |
| 170 |
if (downProp) { |
| 171 |
// update task status local |
| 172 |
CXNegLinker<CTask*>* refTaskIt = updateTask->getReferencedTaskLinker(); |
| 173 |
while (refTaskIt) { |
| 174 |
if (refTaskIt->isNegated()) { |
| 175 |
// task still exists, update task status |
| 176 |
// TODO: check better not recursive? |
| 177 |
CTask* refTask = refTaskIt->getData(); |
| 178 |
processUpdateTaskStatus(refTask); |
| 179 |
} |
| 180 |
refTaskIt = refTaskIt->getNext(); |
| 181 |
} |
| 182 |
} |
| 183 |
if (upProp && parentTask) { |
| 184 |
processUpdateTaskStatus(parentTask); |
| 185 |
} |
| 186 |
} |
| 187 |
} else { |
| 188 |
mDistributorCompletorCommunicator->communicateAlignedUpdateTaskStatus(updateTask,mMemoryAllocator); |
| 189 |
} |
| 190 |
return true; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
bool CTaskProcessorSchedulerThread::processUpdateTaskStatus(CTask* parentTask, CTask* updateTask) { |
| 195 |
if (parentTask->hasNoTaskOwnerAndNoParentTask() || parentTask->hasTaskOwner(this)) { |
| 196 |
// local task status update |
| 197 |
// check whether task is completed |
| 198 |
bool taskCompleted = false; |
| 199 |
CXNegLinker<CTask*>* refTaskLinkerIt = parentTask->getReferencedTaskLinker(); |
| 200 |
while (refTaskLinkerIt) { |
| 201 |
CTask* refTask = refTaskLinkerIt->getData(); |
| 202 |
if (refTask == updateTask) { |
| 203 |
if (!refTaskLinkerIt->isNegated()) { |
| 204 |
taskCompleted = true; |
| 205 |
} |
| 206 |
break; |
| 207 |
} |
| 208 |
refTaskLinkerIt = refTaskLinkerIt->getNext(); |
| 209 |
} |
| 210 |
if (!taskCompleted) { |
| 211 |
processUpdateTaskStatus(updateTask); |
| 212 |
} |
| 213 |
|
| 214 |
mDistributorCompletorCommunicator->communicateTaskStatusUpdated(parentTask,updateTask,true,mMemoryAllocator); |
| 215 |
} else { |
| 216 |
// delegate task update to processor unit |
| 217 |
CTaskOwner* taskOwner = parentTask->getTaskOwner(); |
| 218 |
bool scheduled = false; |
| 219 |
CXLinker<CConcreteTaskSchedulerCommunicator*>* commLinkIt = mSchedulerCommunicatorLinker; |
| 220 |
while (commLinkIt) { |
| 221 |
CConcreteTaskSchedulerCommunicator* communicator = commLinkIt->getData(); |
| 222 |
if (communicator->hasTaskOwner(taskOwner)) { |
| 223 |
communicator->communicateUpdateTaskStatus(parentTask,updateTask,mMemoryAllocator); |
| 224 |
scheduled = true; |
| 225 |
break; |
| 226 |
} |
| 227 |
commLinkIt = commLinkIt->getNext(); |
| 228 |
} |
| 229 |
if (!scheduled) { |
| 230 |
mDistributorCompletorCommunicator->communicateTaskStatusUpdated(parentTask,updateTask,false,mMemoryAllocator); |
| 231 |
} |
| 232 |
} |
| 233 |
return true; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
bool CTaskProcessorSchedulerThread::processSchedulerRequestProcessTask(CTaskSchedulerCommunicator* communicator) { |
| 238 |
if (!mFreeSchedulerItemLinker) { |
| 239 |
mFreeSchedulerItemLinker = new CConcreteTaskScheduleItem(); |
| 240 |
} |
| 241 |
CConcreteTaskScheduleItem* tmpTaskScheduleItem = mFreeSchedulerItemLinker; |
| 242 |
mFreeSchedulerItemLinker = mFreeSchedulerItemLinker->getNext(); |
| 243 |
|
| 244 |
tmpTaskScheduleItem->initTaskScheduleItem((CConcreteTaskSchedulerCommunicator*)communicator,mWaitingSchedulerItemLinker); |
| 245 |
mWaitingSchedulerItemLinker = tmpTaskScheduleItem; |
| 246 |
mDeliveringWaitingCount++; |
| 247 |
|
| 248 |
processTaskScheduling(); |
| 249 |
return true; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
bool CTaskProcessorSchedulerThread::processSchedulerCriticalScheduleTask(CTaskSchedulerCommunicator* communicator) { |
| 254 |
mProcessorWithCriticalScheduleTask = true; |
| 255 |
processTaskScheduling(); |
| 256 |
return true; |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
bool CTaskProcessorSchedulerThread::processSchedulerResponseScheduleTask(CTask* task, CTaskSchedulerCommunicator* communicator, CTaskScheduleItem* taskScheduleItem, bool schedulingTask) { |
| 261 |
CConcreteTaskSchedulerCommunicator* concreteCommunicator = (CConcreteTaskSchedulerCommunicator*)communicator; |
| 262 |
concreteCommunicator->decRequestProcessingTask(); |
| 263 |
--mRequestingTaskCount; |
| 264 |
processSchedulerScheduleTask(task,schedulingTask); |
| 265 |
return true; |
| 266 |
} |
| 267 |
|
| 268 |
bool CTaskProcessorSchedulerThread::processTaskScheduling() { |
| 269 |
bool requestingTasks = false; |
| 270 |
bool canContinueRequestProcessTask = true; |
| 271 |
bool canContinueRequestScheduleTask = true; |
| 272 |
if (mConfUseReserveTasksQueue && mTaskReserveQueueConsumer && mWaitingSchedulerItemLinker) { |
| 273 |
CTask* task = nullptr; |
| 274 |
do { |
| 275 |
task = mTaskReserveQueueConsumer->getTask(); |
| 276 |
processSchedulerScheduleTask(task,true); |
| 277 |
} while (task && mWaitingSchedulerItemLinker); |
| 278 |
} |
| 279 |
while (canContinueRequestScheduleTask && mDeliveringWaitingCount > mRequestingTaskCount) { |
| 280 |
canContinueRequestScheduleTask = false; |
| 281 |
cint64 maxSchedTasks = 0; |
| 282 |
CConcreteTaskSchedulerCommunicator* maxSchedComm = nullptr; |
| 283 |
CXLinker<CConcreteTaskSchedulerCommunicator*>* schedulerCommunicatorLinkerIt = mSchedulerCommunicatorLinker; |
| 284 |
while (schedulerCommunicatorLinkerIt && mDeliveringWaitingCount > mRequestingTaskCount) { |
| 285 |
CConcreteTaskSchedulerCommunicator* communicator = schedulerCommunicatorLinkerIt->getData(); |
| 286 |
cint64 schedTasks = communicator->getRequestUpdatedDispensableSchedulingTasksCount(); |
| 287 |
if (schedTasks > 0) { |
| 288 |
if (!maxSchedComm || schedTasks > maxSchedTasks) { |
| 289 |
maxSchedComm = communicator; |
| 290 |
maxSchedTasks = schedTasks; |
| 291 |
} |
| 292 |
} |
| 293 |
schedulerCommunicatorLinkerIt = schedulerCommunicatorLinkerIt->getNext(); |
| 294 |
} |
| 295 |
if (maxSchedComm) { |
| 296 |
maxSchedComm->communicateRequestScheduleTask(nullptr,mMemoryAllocator); |
| 297 |
maxSchedComm->incRequestProcessingTask(); |
| 298 |
canContinueRequestScheduleTask = true; |
| 299 |
++mRequestingTaskCount; |
| 300 |
requestingTasks = true; |
| 301 |
} |
| 302 |
} |
| 303 |
while (canContinueRequestProcessTask && mDeliveringWaitingCount > mRequestingTaskCount) { |
| 304 |
canContinueRequestProcessTask = false; |
| 305 |
CXLinker<CConcreteTaskSchedulerCommunicator*>* schedulerCommunicatorLinkerIt = mSchedulerCommunicatorLinker; |
| 306 |
while (schedulerCommunicatorLinkerIt && mDeliveringWaitingCount > mRequestingTaskCount) { |
| 307 |
CConcreteTaskSchedulerCommunicator* communicator = schedulerCommunicatorLinkerIt->getData(); |
| 308 |
if (mConfProcessingTasksDistribution && communicator->getRequestUpdatedDispensableProcessingAndSchedulingTasksCount() > 1) { |
| 309 |
communicator->communicateRequestScheduleTask(nullptr,mMemoryAllocator); |
| 310 |
communicator->incRequestProcessingTask(); |
| 311 |
canContinueRequestProcessTask = true; |
| 312 |
++mRequestingTaskCount; |
| 313 |
requestingTasks = true; |
| 314 |
} |
| 315 |
schedulerCommunicatorLinkerIt = schedulerCommunicatorLinkerIt->getNext(); |
| 316 |
} |
| 317 |
} |
| 318 |
if (mDeliveringWaitingCount > mRequestingTaskCount) { |
| 319 |
++mSchedulerDispenseNotificationTag; |
| 320 |
mRequiresTaskDispenseNotification = true; |
| 321 |
} else { |
| 322 |
mRequiresTaskDispenseNotification = false; |
| 323 |
} |
| 324 |
return requestingTasks; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
bool CTaskProcessorSchedulerThread::processSchedulingScheduleTasks() { |
| 330 |
bool requiringSchedulingTask = true; |
| 331 |
if (mConfScheduleTasksDistribution) { |
| 332 |
while (requiringSchedulingTask && mTaskSchedulingCount > mCriticalSchedulingThresholdCount && mTaskSchedulingQueue) { |
| 333 |
requiringSchedulingTask = false; |
| 334 |
cint64 minSchedTasks = 1; |
| 335 |
CConcreteTaskSchedulerCommunicator* minSchedulerComm = nullptr; |
| 336 |
for (CXLinker<CConcreteTaskSchedulerCommunicator*>* schedulerCommunicatorLinkerIt = mSchedulerCommunicatorLinker; schedulerCommunicatorLinkerIt && minSchedTasks > 0; schedulerCommunicatorLinkerIt = schedulerCommunicatorLinkerIt->getNext()) { |
| 337 |
CConcreteTaskSchedulerCommunicator* schedulerComm = schedulerCommunicatorLinkerIt->getData(); |
| 338 |
if (schedulerComm->requiresSchedulingTasks()) { |
| 339 |
requiringSchedulingTask = true; |
| 340 |
cint64 schedTasks = schedulerComm->getRequestUpdatedRemainingSchedulingTasksCount(); |
| 341 |
if (schedTasks <= mCriticalSchedulingThresholdCount) { |
| 342 |
if (!minSchedulerComm || schedTasks < minSchedTasks) { |
| 343 |
minSchedTasks = schedTasks; |
| 344 |
minSchedulerComm = schedulerComm; |
| 345 |
} |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
if (minSchedulerComm) { |
| 350 |
requiringSchedulingTask = true; |
| 351 |
CTask* task = mTaskSchedulingQueue; |
| 352 |
mTaskSchedulingQueue = mTaskSchedulingQueue->getNext(); |
| 353 |
--mTaskSchedulingCount; |
| 354 |
task->clearNext(); |
| 355 |
minSchedulerComm->communicateProcessTask(task,true,mMemoryAllocator); |
| 356 |
minSchedulerComm->incSendedTasks(); |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
return true; |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
bool CTaskProcessorSchedulerThread::processSchedulerScheduleTask(CTask* task, bool schedulingTask) { |
| 365 |
if (task) { |
| 366 |
if (mWaitingSchedulerItemLinker) { |
| 367 |
CConcreteTaskScheduleItem* concreteTaskScheduleItem = mWaitingSchedulerItemLinker; |
| 368 |
mWaitingSchedulerItemLinker = mWaitingSchedulerItemLinker->getNext(); |
| 369 |
CConcreteTaskSchedulerCommunicator* communicator = concreteTaskScheduleItem->getCommunicator(); |
| 370 |
communicator->communicateProcessTask(task,schedulingTask,mMemoryAllocator); |
| 371 |
communicator->incSendedTasks(); |
| 372 |
mLastScheduledTask = task; |
| 373 |
--mDeliveringWaitingCount; |
| 374 |
mFreeSchedulerItemLinker = concreteTaskScheduleItem->setNext(mFreeSchedulerItemLinker); |
| 375 |
} else { |
| 376 |
if (!schedulingTask) { |
| 377 |
addProcessingTask(task); |
| 378 |
} else { |
| 379 |
if (mConfUseReserveTasksQueue) { |
| 380 |
mTaskReserveQueue->tryAddTasks(task); |
| 381 |
++mTaskReserveQueueCount; |
| 382 |
} |
| 383 |
if (task) { |
| 384 |
if (!mTaskProcessingQueue && !mTaskSchedulingQueue) { |
| 385 |
addProcessingTask(task); |
| 386 |
} else { |
| 387 |
mTaskSchedulingCount += task->getCount(); |
| 388 |
if (mTaskSchedulingQueue) { |
| 389 |
mTaskSchedulingQueue = task->append(mTaskSchedulingQueue); |
| 390 |
} else { |
| 391 |
mTaskSchedulingQueue = task; |
| 392 |
} |
| 393 |
if (mTaskSchedulingCount >= mCriticalSchedulingThresholdCount) { |
| 394 |
processSchedulingScheduleTasks(); |
| 395 |
} |
| 396 |
} |
| 397 |
} |
| 398 |
} |
| 399 |
} |
| 400 |
} |
| 401 |
return true; |
| 402 |
} |
| 403 |
|
| 404 |
bool CTaskProcessorSchedulerThread::processSchedulerDispenseNotification(CTaskSchedulerCommunicator* communicator) { |
| 405 |
processTaskScheduling(); |
| 406 |
return true; |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
bool CTaskProcessorSchedulerThread::processDispenseNotification() { |
| 411 |
if (canDispenseProcessingTasks() && requiresTaskDispenseNotification(mDispenseNotificationTag)) { |
| 412 |
processSchedulerDispenseNotification(mSchedulerCommunicator); |
| 413 |
} |
| 414 |
return true; |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
bool CTaskProcessorSchedulerThread::processRequestProcessTask() { |
| 419 |
processSchedulerRequestProcessTask(mSchedulerCommunicator); |
| 420 |
return true; |
| 421 |
} |
| 422 |
|
| 423 |
bool CTaskProcessorSchedulerThread::processCriticalScheduleTask() { |
| 424 |
return true; |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
bool CTaskProcessorSchedulerThread::processCompleteTask(CTask* task) { |
| 429 |
// try locale to complete task |
| 430 |
cint64 completedCount = 0; |
| 431 |
mTaskCompletionQueue = task->getLastListLink()->setNext(mTaskCompletionQueue); |
| 432 |
while (mTaskCompletionQueue) { |
| 433 |
CTask* completionTask = mTaskCompletionQueue; |
| 434 |
mTaskCompletionQueue = mTaskCompletionQueue->getNext(); |
| 435 |
|
| 436 |
if (completionTask && !completionTask->hasActiveReferencedTask()) { |
| 437 |
CTask* parentTask = completionTask->getParentTask(); |
| 438 |
if (!parentTask || parentTask->hasNoTaskOwnerAndNoParentTask() || parentTask->hasTaskOwner(this)) { |
| 439 |
// locale task completion |
| 440 |
bool upPropagation = false; |
| 441 |
if (mTaskStatusPropagator && mTaskStatusPropagator->completeTaskStatus(completionTask,upPropagation)) { |
| 442 |
if (parentTask && upPropagation) { |
| 443 |
processUpdateTaskStatus(parentTask); |
| 444 |
} |
| 445 |
} |
| 446 |
completionTask->completeTask(); |
| 447 |
completionTask->getTaskStatus()->setTaskCOMPLETEDState(); |
| 448 |
bool memoryReleaseable = completionTask->getTaskStatus()->isMemoryReleaseable(); |
| 449 |
if (parentTask) { |
| 450 |
parentTask->decActiveReferenceCount(); |
| 451 |
if (!parentTask->hasActiveReferencedTask()) { |
| 452 |
mTaskCompletionQueue = parentTask->setNext(mTaskCompletionQueue); |
| 453 |
} |
| 454 |
} |
| 455 |
if (completionTask) { |
| 456 |
// callbacks |
| 457 |
CCallbackData* callbackLinkerIt = completionTask->getCallbackLinker(); |
| 458 |
while (callbackLinkerIt) { |
| 459 |
CCallbackData* callback = callbackLinkerIt; |
| 460 |
callbackLinkerIt = callbackLinkerIt->getNext(); |
| 461 |
if (mCallbackExecuter) { |
| 462 |
mCallbackExecuter->executeCallback(completionTask,callback); |
| 463 |
INCTASKPROCESSINGSTAT(mStats.incStatisticCallbacksExecutedCount(1)); |
| 464 |
} else { |
| 465 |
callback->doCallback(); |
| 466 |
} |
| 467 |
} |
| 468 |
} |
| 469 |
#ifndef KONCLUDE_SCHEDULER_DEBUG_TASK_MEMORY_RELEASE |
| 470 |
if (memoryReleaseable) { |
| 471 |
for (CDeletionLinker* deletionLinkerIt = completionTask->takeDeletionLinker(); deletionLinkerIt; deletionLinkerIt = deletionLinkerIt->getNext()) { |
| 472 |
deletionLinkerIt->deleteObject(); |
| 473 |
} |
| 474 |
mMemoryAllocator->releaseMemoryPoolContainer(completionTask); |
| 475 |
} |
| 476 |
#endif |
| 477 |
completedCount++; |
| 478 |
} else { |
| 479 |
// task completion by completer |
| 480 |
mDistributorCompletorCommunicator->communicateTaskComplete(completionTask,mMemoryAllocator); |
| 481 |
} |
| 482 |
} |
| 483 |
} |
| 484 |
INCTASKPROCESSINGSTAT(mStats.incStatisticTasksCompletedCount(completedCount)); |
| 485 |
return true; |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
bool CTaskProcessorSchedulerThread::processAdditionalTaskAllocation(CTask* task, CMemoryPool* memoryPool) { |
| 490 |
CTask* parentTask = task->getParentTask(); |
| 491 |
if (!parentTask || parentTask->hasNoTaskOwnerAndNoParentTask() || parentTask->hasTaskOwner(this)) { |
| 492 |
task->appendMemoryPool(memoryPool); |
| 493 |
} else { |
| 494 |
mDistributorCompletorCommunicator->communicateAdditionalAllocationTask(task,memoryPool,mMemoryAllocator); |
| 495 |
} |
| 496 |
return true; |
| 497 |
} |
| 498 |
|
| 499 |
bool CTaskProcessorSchedulerThread::processResponseScheduleTask(CTask* task, CTaskScheduleItem* taskScheduleItem, bool schedulingTask) { |
| 500 |
processSchedulerResponseScheduleTask(task,mSchedulerCommunicator,taskScheduleItem,schedulingTask); |
| 501 |
return true; |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
}; // end namespace Scheduler |
| 507 |
|
| 508 |
}; // end namespace Konclude |