|
58 | 58 | #include <stdio.h> |
59 | 59 | #endif /* configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) */ |
60 | 60 |
|
61 | | -#if ( configNUMBER_OF_CORES == 1 ) |
62 | | - #if ( configUSE_PREEMPTION == 0 ) |
| 61 | +#if ( configUSE_PREEMPTION == 0 ) |
63 | 62 |
|
64 | 63 | /* If the cooperative scheduler is being used then a yield should not be |
65 | 64 | * performed just because a higher priority task has been woken. */ |
66 | | - #define taskYIELD_IF_USING_PREEMPTION() |
67 | | - #else |
68 | | - #define taskYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API() |
69 | | - #endif |
70 | | -#endif /* if ( configNUMBER_OF_CORES == 1 ) */ |
| 65 | + #define taskYIELD_TASK_CORE_IF_USING_PREEMPTION( pxTCB ) |
| 66 | + #define taskYIELD_ANY_CORE_IF_USING_PREEMPTION( pxTCB ) |
| 67 | +#else |
| 68 | + |
| 69 | + #if ( configNUMBER_OF_CORES == 1 ) |
| 70 | + |
| 71 | +/* This macro requests the running task pxTCB to yield. In single core |
| 72 | + * scheduler, a running task always runs on core 0 and portYIELD_WITHIN_API() |
| 73 | + * can be used to request the task running on core 0 to yield. Therefore, pxTCB |
| 74 | + * is not used in this macro. */ |
| 75 | + #define taskYIELD_TASK_CORE_IF_USING_PREEMPTION( pxTCB ) \ |
| 76 | + do { \ |
| 77 | + ( void ) ( pxTCB ); \ |
| 78 | + portYIELD_WITHIN_API(); \ |
| 79 | + } while( 0 ) |
| 80 | + |
| 81 | + #define taskYIELD_ANY_CORE_IF_USING_PREEMPTION( pxTCB ) \ |
| 82 | + do { \ |
| 83 | + if( pxCurrentTCB->uxPriority < ( pxTCB )->uxPriority ) \ |
| 84 | + { \ |
| 85 | + portYIELD_WITHIN_API(); \ |
| 86 | + } \ |
| 87 | + else \ |
| 88 | + { \ |
| 89 | + mtCOVERAGE_TEST_MARKER(); \ |
| 90 | + } \ |
| 91 | + } while( 0 ) |
| 92 | + |
| 93 | + #else /* if ( configNUMBER_OF_CORES == 1 ) */ |
| 94 | + |
| 95 | +/* Yield the core on which this task is running. */ |
| 96 | + #define taskYIELD_TASK_CORE_IF_USING_PREEMPTION( pxTCB ) prvYieldCore( ( pxTCB )->xTaskRunState ) |
| 97 | + |
| 98 | +/* Yield for the task if a running task has priority lower than this task. */ |
| 99 | + #define taskYIELD_ANY_CORE_IF_USING_PREEMPTION( pxTCB ) prvYieldForTask( pxTCB ) |
| 100 | + |
| 101 | + #endif /* #if ( configNUMBER_OF_CORES == 1 ) */ |
| 102 | + |
| 103 | +#endif /* if ( configUSE_PREEMPTION == 0 ) */ |
71 | 104 |
|
72 | 105 | /* Values that can be assigned to the ucNotifyState member of the TCB. */ |
73 | 106 | #define taskNOT_WAITING_NOTIFICATION ( ( uint8_t ) 0 ) /* Must be zero as it is the initialised value. */ |
@@ -1776,14 +1809,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, |
1776 | 1809 | { |
1777 | 1810 | /* If the created task is of a higher priority than the current task |
1778 | 1811 | * then it should run now. */ |
1779 | | - if( pxCurrentTCB->uxPriority < pxNewTCB->uxPriority ) |
1780 | | - { |
1781 | | - taskYIELD_IF_USING_PREEMPTION(); |
1782 | | - } |
1783 | | - else |
1784 | | - { |
1785 | | - mtCOVERAGE_TEST_MARKER(); |
1786 | | - } |
| 1812 | + taskYIELD_ANY_CORE_IF_USING_PREEMPTION( pxNewTCB ); |
1787 | 1813 | } |
1788 | 1814 | else |
1789 | 1815 | { |
@@ -1859,9 +1885,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, |
1859 | 1885 | /* If the created task is of a higher priority than another |
1860 | 1886 | * currently running task and preemption is on then it should |
1861 | 1887 | * run now. */ |
1862 | | - #if ( configUSE_PREEMPTION == 1 ) |
1863 | | - prvYieldForTask( pxNewTCB ); |
1864 | | - #endif |
| 1888 | + taskYIELD_ANY_CORE_IF_USING_PREEMPTION( pxNewTCB ); |
1865 | 1889 | } |
1866 | 1890 | else |
1867 | 1891 | { |
@@ -2525,37 +2549,27 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, |
2525 | 2549 | #endif |
2526 | 2550 | } |
2527 | 2551 |
|
2528 | | - #if ( configNUMBER_OF_CORES == 1 ) |
| 2552 | + if( xYieldRequired != pdFALSE ) |
2529 | 2553 | { |
2530 | | - if( xYieldRequired != pdFALSE ) |
2531 | | - { |
2532 | | - taskYIELD_IF_USING_PREEMPTION(); |
2533 | | - } |
2534 | | - else |
2535 | | - { |
2536 | | - mtCOVERAGE_TEST_MARKER(); |
2537 | | - } |
| 2554 | + /* The running task priority is set down. Request the task to yield. */ |
| 2555 | + taskYIELD_TASK_CORE_IF_USING_PREEMPTION( pxTCB ); |
2538 | 2556 | } |
2539 | | - #else /* #if ( configNUMBER_OF_CORES == 1 ) */ |
| 2557 | + else |
2540 | 2558 | { |
2541 | | - #if ( configUSE_PREEMPTION == 1 ) |
2542 | | - { |
2543 | | - if( xYieldRequired != pdFALSE ) |
2544 | | - { |
2545 | | - prvYieldCore( pxTCB->xTaskRunState ); |
2546 | | - } |
2547 | | - else if( xYieldForTask != pdFALSE ) |
| 2559 | + #if ( configNUMBER_OF_CORES > 1 ) |
| 2560 | + if( xYieldForTask != pdFALSE ) |
2548 | 2561 | { |
2549 | | - prvYieldForTask( pxTCB ); |
| 2562 | + /* The priority of the task is being raised. If a running |
| 2563 | + * task has priority lower than this task, it should yield |
| 2564 | + * for this task. */ |
| 2565 | + taskYIELD_ANY_CORE_IF_USING_PREEMPTION( pxTCB ); |
2550 | 2566 | } |
2551 | 2567 | else |
2552 | | - { |
2553 | | - mtCOVERAGE_TEST_MARKER(); |
2554 | | - } |
| 2568 | + #endif /* if ( configNUMBER_OF_CORES > 1 ) */ |
| 2569 | + { |
| 2570 | + mtCOVERAGE_TEST_MARKER(); |
2555 | 2571 | } |
2556 | | - #endif /* #if ( configUSE_PREEMPTION == 1 ) */ |
2557 | 2572 | } |
2558 | | - #endif /* #if ( configNUMBER_OF_CORES == 1 ) */ |
2559 | 2573 |
|
2560 | 2574 | /* Remove compiler warning about unused variables when the port |
2561 | 2575 | * optimised task selection is not being used. */ |
@@ -2939,30 +2953,10 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, |
2939 | 2953 | ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); |
2940 | 2954 | prvAddTaskToReadyList( pxTCB ); |
2941 | 2955 |
|
2942 | | - #if ( configNUMBER_OF_CORES == 1 ) |
2943 | | - { |
2944 | | - /* A higher priority task may have just been resumed. */ |
2945 | | - if( pxTCB->uxPriority > pxCurrentTCB->uxPriority ) |
2946 | | - { |
2947 | | - /* This yield may not cause the task just resumed to run, |
2948 | | - * but will leave the lists in the correct state for the |
2949 | | - * next yield. */ |
2950 | | - taskYIELD_IF_USING_PREEMPTION(); |
2951 | | - } |
2952 | | - else |
2953 | | - { |
2954 | | - mtCOVERAGE_TEST_MARKER(); |
2955 | | - } |
2956 | | - } |
2957 | | - #else /* #if ( configNUMBER_OF_CORES == 1 ) */ |
2958 | | - { |
2959 | | - #if ( configUSE_PREEMPTION == 1 ) |
2960 | | - { |
2961 | | - prvYieldForTask( pxTCB ); |
2962 | | - } |
2963 | | - #endif /* #if ( configUSE_PREEMPTION == 1 ) */ |
2964 | | - } |
2965 | | - #endif /* #if ( configNUMBER_OF_CORES == 1 ) */ |
| 2956 | + /* This yield may not cause the task just resumed to run, |
| 2957 | + * but will leave the lists in the correct state for the |
| 2958 | + * next yield. */ |
| 2959 | + taskYIELD_ANY_CORE_IF_USING_PREEMPTION( pxTCB ); |
2966 | 2960 | } |
2967 | 2961 | else |
2968 | 2962 | { |
@@ -3618,7 +3612,7 @@ BaseType_t xTaskResumeAll( void ) |
3618 | 3612 |
|
3619 | 3613 | #if ( configNUMBER_OF_CORES == 1 ) |
3620 | 3614 | { |
3621 | | - taskYIELD_IF_USING_PREEMPTION(); |
| 3615 | + taskYIELD_TASK_CORE_IF_USING_PREEMPTION( pxCurrentTCB ); |
3622 | 3616 | } |
3623 | 3617 | #endif /* #if ( configNUMBER_OF_CORES == 1 ) */ |
3624 | 3618 | } |
@@ -7063,28 +7057,9 @@ TickType_t uxTaskResetEventItemValue( void ) |
7063 | 7057 | } |
7064 | 7058 | #endif |
7065 | 7059 |
|
7066 | | - #if ( configNUMBER_OF_CORES == 1 ) |
7067 | | - { |
7068 | | - if( pxTCB->uxPriority > pxCurrentTCB->uxPriority ) |
7069 | | - { |
7070 | | - /* The notified task has a priority above the currently |
7071 | | - * executing task so a yield is required. */ |
7072 | | - taskYIELD_IF_USING_PREEMPTION(); |
7073 | | - } |
7074 | | - else |
7075 | | - { |
7076 | | - mtCOVERAGE_TEST_MARKER(); |
7077 | | - } |
7078 | | - } |
7079 | | - #else /* #if ( configNUMBER_OF_CORES == 1 ) */ |
7080 | | - { |
7081 | | - #if ( configUSE_PREEMPTION == 1 ) |
7082 | | - { |
7083 | | - prvYieldForTask( pxTCB ); |
7084 | | - } |
7085 | | - #endif |
7086 | | - } |
7087 | | - #endif /* #if ( configNUMBER_OF_CORES == 1 ) */ |
| 7060 | + /* Check if the notified task has a priority above the currently |
| 7061 | + * executing task. */ |
| 7062 | + taskYIELD_ANY_CORE_IF_USING_PREEMPTION( pxTCB ); |
7088 | 7063 | } |
7089 | 7064 | else |
7090 | 7065 | { |
|
0 commit comments