task-list-32-tasks.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "all-headers.h"
  2. #define ENABLE_TASK_LIST_ASSERTIONS
  3. #ifdef ENABLE_TASK_LIST_ASSERTIONS
  4. #define TASK_LIST_ASSERT_NON_NULL_POINTER(ptr) assertNonNullPointer (ptr, __FILE__, __LINE__) ;
  5. #else
  6. #define TASK_LIST_ASSERT_NON_NULL_POINTER(ptr)
  7. #endif
  8. #ifdef ENABLE_TASK_LIST_ASSERTIONS
  9. #define TASK_LIST_ASSERT(condition,value) assertion (condition, value, __FILE__, __LINE__) ;
  10. #else
  11. #define TASK_LIST_ASSERT(condition,value)
  12. #endif
  13. // ENTER TASK IN LIST: inTask should be not null
  14. void TaskList::enterTask (SECTION_MODE_ TaskControlBlock * inTaskPtr) {
  15. TASK_LIST_ASSERT_NON_NULL_POINTER (inTaskPtr) ;
  16. const uint32_t taskIndex = indexForDescriptorTask (inTaskPtr) ;
  17. TASK_LIST_ASSERT (taskIndex < TASK_COUNT, taskIndex) ;
  18. const uint32_t mask = 1U << taskIndex ;
  19. mList |= mask ;
  20. }
  21. // REMOVE FIRST TASK FROM LIST: returns nullptr if list is empty *
  22. TaskControlBlock * TaskList::removeFirstTask (IRQ_MODE) {
  23. TaskControlBlock * taskPtr = nullptr ;
  24. if (mList != 0) {
  25. const uint32_t taskIndex = (uint32_t) __builtin_ctz (mList) ;
  26. TASK_LIST_ASSERT (taskIndex < TASK_COUNT, taskIndex) ;
  27. const uint32_t mask = 1U << taskIndex ;
  28. mList &= ~ mask ;
  29. taskPtr = descriptorPointerForTaskIndex (taskIndex) ;
  30. }
  31. return taskPtr ;
  32. }
  33. // REMOVE A TASK FROM LIST
  34. void TaskList::removeTask (SECTION_MODE_ TaskControlBlock * inTaskPtr) {
  35. TASK_LIST_ASSERT_NON_NULL_POINTER (inTaskPtr) ;
  36. const uint32_t taskIndex = indexForDescriptorTask (inTaskPtr) ;
  37. TASK_LIST_ASSERT (taskIndex < TASK_COUNT, taskIndex) ;
  38. const uint32_t mask = 1U << taskIndex ;
  39. mList &= ~ mask ;
  40. }
  41. // REMOVE FIRST TASK FROM LIST: returns nullptr if list is empty *
  42. TaskControlBlock * TaskList::Iterator::nextTask (IRQ_MODE) {
  43. TaskControlBlock * taskPtr = nullptr ;
  44. if (mIteratedList != 0) {
  45. const uint32_t taskIndex = (uint32_t) __builtin_ctz (mIteratedList) ;
  46. TASK_LIST_ASSERT (taskIndex < TASK_COUNT, taskIndex) ;
  47. const uint32_t mask = 1U << taskIndex ;
  48. mIteratedList &= ~ mask ;
  49. taskPtr = descriptorPointerForTaskIndex (taskIndex) ;
  50. }
  51. return taskPtr ;
  52. }