Skip to content

Commit 078b400

Browse files
RichardBarryyuhui-zheng
authored andcommitted
Updates vCoRoutineSchedule() so it returns without doing anything if if the co-routine internal data structures have not been initialised. The internal data structures are initialised when the first co-routine is created.
NOTE: Co-routines are a deprecated feature. This change was made to close off an old ticket as the source control transitions from SourceForge to Github.
1 parent 326d88f commit 078b400

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

croutine.c

+25-19
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
static List_t pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */
4646
static List_t xDelayedCoRoutineList1; /*< Delayed co-routines. */
4747
static List_t xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */
48-
static List_t * pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */
49-
static List_t * pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
48+
static List_t * pxDelayedCoRoutineList = NULL; /*< Points to the delayed co-routine list currently being used. */
49+
static List_t * pxOverflowDelayedCoRoutineList = NULL; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
5050
static List_t xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */
5151

5252
/* Other file private variables. --------------------------------*/
@@ -277,29 +277,35 @@ CRCB_t *pxCRCB;
277277

278278
void vCoRoutineSchedule( void )
279279
{
280-
/* See if any co-routines readied by events need moving to the ready lists. */
281-
prvCheckPendingReadyList();
280+
/* Only run a co-routine after prvInitialiseCoRoutineLists() has been
281+
called. prvInitialiseCoRoutineLists() is called automatically when a
282+
co-routine is created. */
283+
if( pxDelayedCoRoutineList != NULL )
284+
{
285+
/* See if any co-routines readied by events need moving to the ready lists. */
286+
prvCheckPendingReadyList();
282287

283-
/* See if any delayed co-routines have timed out. */
284-
prvCheckDelayedList();
288+
/* See if any delayed co-routines have timed out. */
289+
prvCheckDelayedList();
285290

286-
/* Find the highest priority queue that contains ready co-routines. */
287-
while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) )
288-
{
289-
if( uxTopCoRoutineReadyPriority == 0 )
291+
/* Find the highest priority queue that contains ready co-routines. */
292+
while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) )
290293
{
291-
/* No more co-routines to check. */
292-
return;
294+
if( uxTopCoRoutineReadyPriority == 0 )
295+
{
296+
/* No more co-routines to check. */
297+
return;
298+
}
299+
--uxTopCoRoutineReadyPriority;
293300
}
294-
--uxTopCoRoutineReadyPriority;
295-
}
296301

297-
/* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines
298-
of the same priority get an equal share of the processor time. */
299-
listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) );
302+
/* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines
303+
of the same priority get an equal share of the processor time. */
304+
listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) );
300305

301-
/* Call the co-routine. */
302-
( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex );
306+
/* Call the co-routine. */
307+
( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex );
308+
}
303309

304310
return;
305311
}

0 commit comments

Comments
 (0)