Add support for priority inheritance

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1581 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2009-03-08 23:33:41 +00:00
parent 84ec1dd3a3
commit 6b22b2c441
6 changed files with 135 additions and 39 deletions

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/common/up_reprioritizertr.c * arch/arm/src/common/up_reprioritizertr.c
* *
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -85,14 +85,27 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority)
{ {
/* Verify that the caller is sane */ /* Verify that the caller is sane */
if (tcb->task_state < FIRST_READY_TO_RUN_STATE || #if CONFIG_DEBUG /* We only check parameters when debug is enabled */
tcb->task_state > LAST_READY_TO_RUN_STATE || if (priority < SCHED_PRIORITY_MIN ||
priority < SCHED_PRIORITY_MIN ||
priority > SCHED_PRIORITY_MAX) priority > SCHED_PRIORITY_MAX)
{ {
PANIC(OSERR_BADREPRIORITIZESTATE); PANIC(OSERR_BADREPRIORITIZESTATE);
} }
else else
#endif
if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
tcb->task_state > LAST_READY_TO_RUN_STATE)
{
/* This is a hack and needs to be fixed.. here some taks is reprioritizing
* another task that is not running. Here we just set the priority of
* the task -- BUT some of the other states are also prioritized and the
* waiting task should also be re-ordered in the prioritized wiating list.
* As a consequence, the other task is still waiting at the lower priority.
*/
tcb->sched_priority = priority;
}
else
{ {
_TCB *rtcb = (_TCB*)g_readytorun.head; _TCB *rtcb = (_TCB*)g_readytorun.head;
boolean switch_needed; boolean switch_needed;
@ -109,6 +122,9 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority)
/* Setup up the new task priority */ /* Setup up the new task priority */
tcb->sched_priority = (ubyte)priority; tcb->sched_priority = (ubyte)priority;
#ifdef CONFIG_PRIORITY_INHERITANCE
tcb->base_priority = (ubyte)priority;
#endif
/* Return the task to the specified blocked task list. /* Return the task to the specified blocked task list.
* sched_addreadytorun will return TRUE if the task was * sched_addreadytorun will return TRUE if the task was

View File

@ -1,7 +1,7 @@
/************************************************************ /****************************************************************************
* up_reprioritizertr.c * up_reprioritizertr.c
* *
* Copyright (C) 2007 Gregory Nutt. All rights reserved. * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -14,7 +14,7 @@
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* 3. Neither the name Gregory Nutt nor the names of its contributors may be * 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software * used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
@ -31,11 +31,11 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Included Files * Included Files
************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
@ -45,23 +45,23 @@
#include "os_internal.h" #include "os_internal.h"
#include "up_internal.h" #include "up_internal.h"
/************************************************************ /****************************************************************************
* Private Definitions * Private Definitions
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Private Data * Private Data
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Private Funtions * Private Funtions
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Public Funtions * Public Funtions
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Name: up_reprioritize_rtr * Name: up_reprioritize_rtr
* *
* Description: * Description:
@ -79,20 +79,33 @@
* tcb: The TCB of the task that has been reprioritized * tcb: The TCB of the task that has been reprioritized
* priority: The new task priority * priority: The new task priority
* *
************************************************************/ ****************************************************************************/
void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority) void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority)
{ {
/* Verify that the caller is sane */ /* Verify that the caller is sane */
if (tcb->task_state < FIRST_READY_TO_RUN_STATE || #if CONFIG_DEBUG /* We only check parameters when debug is enabled */
tcb->task_state > LAST_READY_TO_RUN_STATE || if (priority < SCHED_PRIORITY_MIN ||
priority < SCHED_PRIORITY_MIN ||
priority > SCHED_PRIORITY_MAX) priority > SCHED_PRIORITY_MAX)
{ {
PANIC(OSERR_BADREPRIORITIZESTATE); PANIC(OSERR_BADREPRIORITIZESTATE);
} }
else else
#endif
if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
tcb->task_state > LAST_READY_TO_RUN_STATE)
{
/* This is a hack and needs to be fixed.. here some taks is reprioritizing
* another task that is not running. Here we just set the priority of
* the task -- BUT some of the other states are also prioritized and the
* waiting task should also be re-ordered in the prioritized wiating list.
* As a consequence, the other task is still waiting at the lower priority.
*/
tcb->sched_priority = priority;
}
else
{ {
FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
boolean switch_needed; boolean switch_needed;
@ -109,6 +122,9 @@ void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority)
/* Setup up the new task priority */ /* Setup up the new task priority */
tcb->sched_priority = (ubyte)priority; tcb->sched_priority = (ubyte)priority;
#ifdef CONFIG_PRIORITY_INHERITANCE
tcb->base_priority = (ubyte)priority;
#endif
/* Return the task to the specified blocked task list. /* Return the task to the specified blocked task list.
* sched_addreadytorun will return TRUE if the task was * sched_addreadytorun will return TRUE if the task was

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/sh/src/common/up_reprioritizertr.c * arch/sh/src/common/up_reprioritizertr.c
* *
* Copyright (C) 2008 Gregory Nutt. All rights reserved. * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -85,14 +85,27 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority)
{ {
/* Verify that the caller is sane */ /* Verify that the caller is sane */
if (tcb->task_state < FIRST_READY_TO_RUN_STATE || #if CONFIG_DEBUG /* We only check parameters when debug is enabled */
tcb->task_state > LAST_READY_TO_RUN_STATE || if (priority < SCHED_PRIORITY_MIN ||
priority < SCHED_PRIORITY_MIN ||
priority > SCHED_PRIORITY_MAX) priority > SCHED_PRIORITY_MAX)
{ {
PANIC(OSERR_BADREPRIORITIZESTATE); PANIC(OSERR_BADREPRIORITIZESTATE);
} }
else else
#endif
if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
tcb->task_state > LAST_READY_TO_RUN_STATE)
{
/* This is a hack and needs to be fixed.. here some taks is reprioritizing
* another task that is not running. Here we just set the priority of
* the task -- BUT some of the other states are also prioritized and the
* waiting task should also be re-ordered in the prioritized wiating list.
* As a consequence, the other task is still waiting at the lower priority.
*/
tcb->sched_priority = priority;
}
else
{ {
_TCB *rtcb = (_TCB*)g_readytorun.head; _TCB *rtcb = (_TCB*)g_readytorun.head;
boolean switch_needed; boolean switch_needed;
@ -109,6 +122,9 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority)
/* Setup up the new task priority */ /* Setup up the new task priority */
tcb->sched_priority = (ubyte)priority; tcb->sched_priority = (ubyte)priority;
#ifdef CONFIG_PRIORITY_INHERITANCE
tcb->base_priority = (ubyte)priority;
#endif
/* Return the task to the specified blocked task list. /* Return the task to the specified blocked task list.
* sched_addreadytorun will return TRUE if the task was * sched_addreadytorun will return TRUE if the task was

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* up_reprioritizertr.c * up_reprioritizertr.c
* *
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -85,14 +85,27 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority)
{ {
/* Verify that the caller is sane */ /* Verify that the caller is sane */
if (tcb->task_state < FIRST_READY_TO_RUN_STATE || #if CONFIG_DEBUG /* We only check parameters when debug is enabled */
tcb->task_state > LAST_READY_TO_RUN_STATE || if (priority < SCHED_PRIORITY_MIN ||
priority < SCHED_PRIORITY_MIN ||
priority > SCHED_PRIORITY_MAX) priority > SCHED_PRIORITY_MAX)
{ {
PANIC(OSERR_BADREPRIORITIZESTATE); PANIC(OSERR_BADREPRIORITIZESTATE);
} }
else else
#endif
if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
tcb->task_state > LAST_READY_TO_RUN_STATE)
{
/* This is a hack and needs to be fixed.. here some taks is reprioritizing
* another task that is not running. Here we just set the priority of
* the task -- BUT some of the other states are also prioritized and the
* waiting task should also be re-ordered in the prioritized wiating list.
* As a consequence, the other task is still waiting at the lower priority.
*/
tcb->sched_priority = priority;
}
else
{ {
_TCB *rtcb = (_TCB*)g_readytorun.head; _TCB *rtcb = (_TCB*)g_readytorun.head;
boolean switch_needed; boolean switch_needed;
@ -109,6 +122,9 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority)
/* Setup up the new task priority */ /* Setup up the new task priority */
tcb->sched_priority = (ubyte)priority; tcb->sched_priority = (ubyte)priority;
#ifdef CONFIG_PRIORITY_INHERITANCE
tcb->base_priority = (ubyte)priority;
#endif
/* Return the task to the specified blocked task list. /* Return the task to the specified blocked task list.
* sched_addreadytorun will return TRUE if the task was * sched_addreadytorun will return TRUE if the task was

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* common/up_reprioritizertr.c * common/up_reprioritizertr.c
* *
* Copyright (C) 2008 Gregory Nutt. All rights reserved. * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -89,14 +89,27 @@ void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority)
{ {
/* Verify that the caller is sane */ /* Verify that the caller is sane */
if (tcb->task_state < FIRST_READY_TO_RUN_STATE || #if CONFIG_DEBUG /* We only check parameters when debug is enabled */
tcb->task_state > LAST_READY_TO_RUN_STATE || if (priority < SCHED_PRIORITY_MIN ||
priority < SCHED_PRIORITY_MIN ||
priority > SCHED_PRIORITY_MAX) priority > SCHED_PRIORITY_MAX)
{ {
PANIC(OSERR_BADREPRIORITIZESTATE); PANIC(OSERR_BADREPRIORITIZESTATE);
} }
else else
#endif
if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
tcb->task_state > LAST_READY_TO_RUN_STATE)
{
/* This is a hack and needs to be fixed.. here some taks is reprioritizing
* another task that is not running. Here we just set the priority of
* the task -- BUT some of the other states are also prioritized and the
* waiting task should also be re-ordered in the prioritized wiating list.
* As a consequence, the other task is still waiting at the lower priority.
*/
tcb->sched_priority = priority;
}
else
{ {
FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
boolean switch_needed; boolean switch_needed;
@ -113,6 +126,9 @@ void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority)
/* Setup up the new task priority */ /* Setup up the new task priority */
tcb->sched_priority = (ubyte)priority; tcb->sched_priority = (ubyte)priority;
#ifdef CONFIG_PRIORITY_INHERITANCE
tcb->base_priority = (ubyte)priority;
#endif
/* Return the task to the specified blocked task list. /* Return the task to the specified blocked task list.
* sched_addreadytorun will return TRUE if the task was * sched_addreadytorun will return TRUE if the task was

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/z80/src/common/up_reprioritizertr.c * arch/z80/src/common/up_reprioritizertr.c
* *
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -90,14 +90,27 @@ void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority)
{ {
/* Verify that the caller is sane */ /* Verify that the caller is sane */
if (tcb->task_state < FIRST_READY_TO_RUN_STATE || #if CONFIG_DEBUG /* We only check parameters when debug is enabled */
tcb->task_state > LAST_READY_TO_RUN_STATE || if (priority < SCHED_PRIORITY_MIN ||
priority < SCHED_PRIORITY_MIN ||
priority > SCHED_PRIORITY_MAX) priority > SCHED_PRIORITY_MAX)
{ {
PANIC(OSERR_BADREPRIORITIZESTATE); PANIC(OSERR_BADREPRIORITIZESTATE);
} }
else else
#endif
if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
tcb->task_state > LAST_READY_TO_RUN_STATE)
{
/* This is a hack and needs to be fixed.. here some taks is reprioritizing
* another task that is not running. Here we just set the priority of
* the task -- BUT some of the other states are also prioritized and the
* waiting task should also be re-ordered in the prioritized wiating list.
* As a consequence, the other task is still waiting at the lower priority.
*/
tcb->sched_priority = priority;
}
else
{ {
FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
boolean switch_needed; boolean switch_needed;
@ -114,6 +127,9 @@ void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority)
/* Setup up the new task priority */ /* Setup up the new task priority */
tcb->sched_priority = (ubyte)priority; tcb->sched_priority = (ubyte)priority;
#ifdef CONFIG_PRIORITY_INHERITANCE
tcb->base_priority = (ubyte)priority;
#endif
/* Return the task to the specified blocked task list. /* Return the task to the specified blocked task list.
* sched_addreadytorun will return TRUE if the task was * sched_addreadytorun will return TRUE if the task was