1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Fixed static inline declaration of queue iterators. Minor tidy of case when selectedTask == NULL

This commit is contained in:
Martin Budden 2016-01-21 08:46:37 +00:00 committed by borisbstyle
parent 757fb54512
commit 2b8e75a761
2 changed files with 12 additions and 15 deletions

View file

@ -21,11 +21,14 @@
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
#ifdef UNIT_TEST #ifdef UNIT_TEST
#define STATIC_UNIT_TESTED // make visible to unit test // make these visible to unit test
#define INLINE_UNIT_TESTED // make visible to unit test #define STATIC_UNIT_TESTED
#define STATIC_INLINE_UNIT_TESTED
#define INLINE_UNIT_TESTED
#define UNIT_TESTED #define UNIT_TESTED
#else #else
#define STATIC_UNIT_TESTED static #define STATIC_UNIT_TESTED static
#define STATIC_INLINE_UNIT_TESTED static inline
#define INLINE_UNIT_TESTED inline #define INLINE_UNIT_TESTED inline
#define UNIT_TESTED #define UNIT_TESTED
#endif #endif

View file

@ -115,7 +115,7 @@ STATIC_UNIT_TESTED void queueRemove(cfTask_t *task)
/* /*
* Returns first item queue or NULL if queue empty * Returns first item queue or NULL if queue empty
*/ */
INLINE_UNIT_TESTED cfTask_t *queueFirst(void) STATIC_INLINE_UNIT_TESTED cfTask_t *queueFirst(void)
{ {
taskQueuePos = 0; taskQueuePos = 0;
return taskQueueArray[0]; // guaranteed to be NULL if queue is empty return taskQueueArray[0]; // guaranteed to be NULL if queue is empty
@ -124,7 +124,7 @@ INLINE_UNIT_TESTED cfTask_t *queueFirst(void)
/* /*
* Returns next item in queue or NULL if at end of queue * Returns next item in queue or NULL if at end of queue
*/ */
INLINE_UNIT_TESTED cfTask_t *queueNext(void) STATIC_INLINE_UNIT_TESTED cfTask_t *queueNext(void)
{ {
return taskQueueArray[++taskQueuePos]; // guaranteed to be NULL at end of queue return taskQueueArray[++taskQueuePos]; // guaranteed to be NULL at end of queue
} }
@ -259,7 +259,7 @@ void scheduler(void)
if (task->dynamicPriority > selectedTaskDynPrio) { if (task->dynamicPriority > selectedTaskDynPrio) {
const bool outsideRealtimeGuardInterval = (timeToNextRealtimeTask > realtimeGuardInterval); const bool outsideRealtimeGuardInterval = (timeToNextRealtimeTask > realtimeGuardInterval);
bool taskCanBeChosenForScheduling = const bool taskCanBeChosenForScheduling =
(outsideRealtimeGuardInterval) || (outsideRealtimeGuardInterval) ||
(task->taskAgeCycles > 1) || (task->taskAgeCycles > 1) ||
(task->staticPriority == TASK_PRIORITY_REALTIME); (task->staticPriority == TASK_PRIORITY_REALTIME);
@ -273,19 +273,17 @@ void scheduler(void)
totalWaitingTasksSamples++; totalWaitingTasksSamples++;
totalWaitingTasks += waitingTasks; totalWaitingTasks += waitingTasks;
currentTask = selectedTask;
/* Found a task that should be run */ /* Found a task that should be run */
if (selectedTask != NULL) { if (selectedTask != NULL) {
selectedTask->taskLatestDeltaTime = currentTime - selectedTask->lastExecutedAt; selectedTask->taskLatestDeltaTime = currentTime - selectedTask->lastExecutedAt;
selectedTask->lastExecutedAt = currentTime; selectedTask->lastExecutedAt = currentTime;
selectedTask->dynamicPriority = 0; selectedTask->dynamicPriority = 0;
currentTask = selectedTask;
const uint32_t currentTimeBeforeTaskCall = micros();
/* Execute task */ /* Execute task */
const uint32_t currentTimeBeforeTaskCall = micros();
selectedTask->taskFunc(); selectedTask->taskFunc();
const uint32_t taskExecutionTime = micros() - currentTimeBeforeTaskCall; const uint32_t taskExecutionTime = micros() - currentTimeBeforeTaskCall;
selectedTask->averageExecutionTime = ((uint32_t)selectedTask->averageExecutionTime * 31 + taskExecutionTime) / 32; selectedTask->averageExecutionTime = ((uint32_t)selectedTask->averageExecutionTime * 31 + taskExecutionTime) / 32;
@ -295,11 +293,7 @@ void scheduler(void)
#endif #endif
#if defined SCHEDULER_DEBUG #if defined SCHEDULER_DEBUG
debug[3] = (micros() - currentTime) - taskExecutionTime; debug[3] = (micros() - currentTime) - taskExecutionTime;
#endif } else {
}
else {
currentTask = NULL;
#if defined SCHEDULER_DEBUG
debug[3] = (micros() - currentTime); debug[3] = (micros() - currentTime);
#endif #endif
} }