From 6c3538618668b4ac8aec21d9476a148c6d90200e Mon Sep 17 00:00:00 2001 From: richardbarry Date: Thu, 23 Sep 2010 18:07:41 +0000 Subject: [PATCH] Update to FreeRTOS V6.1.0 release candidate. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1135 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- Source/tasks.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/Source/tasks.c b/Source/tasks.c index fafd9ceb7..7b7d64136 100644 --- a/Source/tasks.c +++ b/Source/tasks.c @@ -460,15 +460,19 @@ tskTCB * pxNewTCB; portENTER_CRITICAL(); { uxCurrentNumberOfTasks++; - if( uxCurrentNumberOfTasks == ( unsigned portBASE_TYPE ) 1 ) + if( pxCurrentTCB == NULL ) { - /* As this is the first task it must also be the current task. */ + /* There are no other tasks, or all the other tasks are in + the suspended state - make this the current task. */ pxCurrentTCB = pxNewTCB; - /* This is the first task to be created so do the preliminary - initialisation required. We will not recover if this call - fails, but we will report the failure. */ - prvInitialiseTaskLists(); + if( uxCurrentNumberOfTasks == ( unsigned portBASE_TYPE ) 1 ) + { + /* This is the first task to be created so do the preliminary + initialisation required. We will not recover if this call + fails, but we will report the failure. */ + prvInitialiseTaskLists(); + } } else { @@ -893,10 +897,31 @@ tskTCB * pxNewTCB; } portEXIT_CRITICAL(); - /* We may have just suspended the current task. */ - if( ( ( void * ) pxTaskToSuspend == NULL ) && ( xSchedulerRunning != pdFALSE ) ) + if( ( void * ) pxTaskToSuspend == NULL ) { - portYIELD_WITHIN_API(); + if( xSchedulerRunning != pdFALSE ) + { + /* We have just suspended the current task. */ + portYIELD_WITHIN_API(); + } + else + { + /* The scheduler is not running, but the task that was pointed + to by pxCurrentTCB has just been suspended and pxCurrentTCB + must be adjusted to point to a different task. */ + if( uxCurrentNumberOfTasks == 1 ) + { + /* No other tasks are defined, so set pxCurrentTCB back to + NULL so when the next task is created pxCurrentTCB will + be set to point to it no matter what its relative priority + is. */ + pxCurrentTCB = NULL; + } + else + { + vTaskSwitchContext(); + } + } } } -- 2.39.5