summaryrefslogtreecommitdiffstats
path: root/nuttx/sched
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/os_internal.h2
-rw-r--r--nuttx/sched/pthread_create.c6
-rw-r--r--nuttx/sched/pthread_setschedprio.c4
-rw-r--r--nuttx/sched/sched_setparam.c58
-rw-r--r--nuttx/sched/sem_destroy.c8
-rw-r--r--nuttx/sched/sem_post.c20
-rw-r--r--nuttx/sched/sem_wait.c40
-rw-r--r--nuttx/sched/task_restart.c49
-rw-r--r--nuttx/sched/task_setup.c7
9 files changed, 135 insertions, 59 deletions
diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h
index 665d05e743..a9b1bfc856 100644
--- a/nuttx/sched/os_internal.h
+++ b/nuttx/sched/os_internal.h
@@ -1,7 +1,7 @@
/****************************************************************************
* sched/os_internal.h
*
- * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c
index f13f76b146..e515125738 100644
--- a/nuttx/sched/pthread_create.c
+++ b/nuttx/sched/pthread_create.c
@@ -1,7 +1,7 @@
/****************************************************************************
- * pthread_create.c
+ * sched/pthread_create.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>
*
* Redistribution and use in source and binary forms, with or without
@@ -303,7 +303,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
if (attr->inheritsched == PTHREAD_INHERIT_SCHED)
{
- /* Get the priority of this thread. */
+ /* Get the priority for this thread. */
struct sched_param param;
status = sched_getparam(0, &param);
diff --git a/nuttx/sched/pthread_setschedprio.c b/nuttx/sched/pthread_setschedprio.c
index d5a5705dcc..6d3beb1de9 100644
--- a/nuttx/sched/pthread_setschedprio.c
+++ b/nuttx/sched/pthread_setschedprio.c
@@ -1,7 +1,7 @@
/****************************************************************************
* pthread_schedsetprio.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>
*
* 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
* the documentation and/or other materials provided with the
* 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
* without specific prior written permission.
*
diff --git a/nuttx/sched/sched_setparam.c b/nuttx/sched/sched_setparam.c
index e5a61c8568..20b0d68318 100644
--- a/nuttx/sched/sched_setparam.c
+++ b/nuttx/sched/sched_setparam.c
@@ -1,7 +1,7 @@
-/************************************************************
- * sched_setparam.c
+/****************************************************************************
+ * sched/sched_setparam.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>
*
* 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
* the documentation and/or other materials provided with the
* 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
* without specific prior written permission.
*
@@ -31,11 +31,11 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Included Files
- ************************************************************/
+ ****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
@@ -44,35 +44,35 @@
#include <nuttx/arch.h>
#include "os_internal.h"
-/************************************************************
+/****************************************************************************
* Definitions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Type Declarations
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Global Variables
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Variables
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Function Prototypes
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Functions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Public Functions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Name: sched_setparam
*
* Description:
@@ -100,7 +100,7 @@
*
* Assumptions:
*
- ************************************************************/
+ ****************************************************************************/
int sched_setparam(pid_t pid, const struct sched_param *param)
{
@@ -185,6 +185,9 @@ int sched_setparam(pid_t pid, const struct sched_param *param)
/* Change the task priority */
tcb->sched_priority = (ubyte)sched_priority;
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ tcb->base_priority = (ubyte)sched_priority;
+#endif
}
break;
@@ -218,6 +221,9 @@ int sched_setparam(pid_t pid, const struct sched_param *param)
/* Change the task priority */
tcb->sched_priority = (ubyte)sched_priority;
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ tcb->base_priority = (ubyte)sched_priority;
+#endif
/* Put it back into the ready-to-run task list */
@@ -241,6 +247,9 @@ int sched_setparam(pid_t pid, const struct sched_param *param)
/* Change the task priority */
tcb->sched_priority = (ubyte)sched_priority;
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ tcb->base_priority = (ubyte)sched_priority;
+#endif
/* Put it back into the prioritized list at the correct
* position
@@ -256,6 +265,9 @@ int sched_setparam(pid_t pid, const struct sched_param *param)
/* Just change the task's priority */
tcb->sched_priority = (ubyte)sched_priority;
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ tcb->base_priority = (ubyte)sched_priority;
+#endif
}
break;
}
diff --git a/nuttx/sched/sem_destroy.c b/nuttx/sched/sem_destroy.c
index 6dd60bc283..6635223038 100644
--- a/nuttx/sched/sem_destroy.c
+++ b/nuttx/sched/sem_destroy.c
@@ -1,7 +1,7 @@
/****************************************************************************
* sched/sem_destroy.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>
*
* Redistribution and use in source and binary forms, with or without
@@ -103,7 +103,8 @@ int sem_destroy (FAR sem_t *sem)
{
/* There is really no particular action that we need
* take to destroy a semaphore. We will just reset
- * the count to some reasonable value (1).
+ * the count to some reasonable value (1) and release
+ * ownership.
*
* Check if other threads are waiting on the semaphore.
* In this case, the behavior is undefined. We will:
@@ -114,6 +115,9 @@ int sem_destroy (FAR sem_t *sem)
{
sem->semcount = 1;
}
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ sem->holder = NULL;
+#endif
ret = OK;
}
diff --git a/nuttx/sched/sem_post.c b/nuttx/sched/sem_post.c
index 186c3b87e1..ca20475989 100644
--- a/nuttx/sched/sem_post.c
+++ b/nuttx/sched/sem_post.c
@@ -1,7 +1,7 @@
/****************************************************************************
* sched/sem_post.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>
*
* Redistribution and use in source and binary forms, with or without
@@ -104,6 +104,9 @@
int sem_post(FAR sem_t *sem)
{
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
+#endif
FAR _TCB *stcb;
STATUS ret = ERROR;
irqstate_t saved_state;
@@ -122,6 +125,9 @@ int sem_post(FAR sem_t *sem)
/* Perform the semaphore unlock operation. */
ASSERT(sem->semcount < SEM_VALUE_MAX);
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ sem->holder = NULL;
+#endif
sem->semcount++;
/* If the result of of semaphore unlock is non-positive, then
@@ -151,6 +157,18 @@ int sem_post(FAR sem_t *sem)
up_unblock_task(stcb);
}
}
+
+ /* Check if we need to drop our priority. Our priority could have
+ * been boosted while we held the semaphore.
+ */
+
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ if (rtcb->sched_priority != rtcb->base_priority)
+ {
+ up_reprioritize_rtr(rtcb, rtcb->base_priority);
+ }
+#endif
+
ret = OK;
/* Interrupts may now be enabled. */
diff --git a/nuttx/sched/sem_wait.c b/nuttx/sched/sem_wait.c
index ba223b1d4b..d0735d76e2 100644
--- a/nuttx/sched/sem_wait.c
+++ b/nuttx/sched/sem_wait.c
@@ -1,7 +1,7 @@
/****************************************************************************
* sched/sem_wait.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>
*
* Redistribution and use in source and binary forms, with or without
@@ -98,6 +98,9 @@
int sem_wait(FAR sem_t *sem)
{
FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ FAR _TCB *htcb;
+#endif
int ret = ERROR;
irqstate_t saved_state;
@@ -125,6 +128,9 @@ int sem_wait(FAR sem_t *sem)
/* It is, let the task take the semaphore. */
sem->semcount--;
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ sem->holder = rtcb;
+#endif
rtcb->waitsem = NULL;
ret = OK;
}
@@ -144,7 +150,7 @@ int sem_wait(FAR sem_t *sem)
PANIC(OSERR_BADWAITSEM);
}
- /* Handle the POSIX semaphore */
+ /* Handle the POSIX semaphore (but don't set the owner yet) */
sem->semcount--;
@@ -152,11 +158,36 @@ int sem_wait(FAR sem_t *sem)
rtcb->waitsem = sem;
+ /* If priority inheritance is enabled, then check the priority of
+ * the holder of the semaphore.
+ */
+
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ /* Disable context switching. The following operations must be
+ * atomic with regard to the scheduler.
+ */
+
+ sched_lock();
+ htcb = sem->holder;
+ if (htcb && htcb->sched_priority < rtcb->sched_priority)
+ {
+ /* Raise the priority of the holder of the semaphore. This
+ * cannot cause a context switch because we have preemption
+ * disabled. The task will be marked "pending" and the switch
+ * will occur during up_block_task() processing.
+ */
+
+ up_reprioritize_rtr(htcb, rtcb->sched_priority);
+ }
+#endif
/* Add the TCB to the prioritized semaphore wait queue */
*get_errno_ptr() = 0;
up_block_task(rtcb, TSTATE_WAIT_SEM);
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ sched_unlock();
+#endif
/* When we resume at this point, either (1) the semaphore has been
* assigned to this thread of execution, or (2) the semaphore wait
* has been interrupted by a signal. We can detect the latter case
@@ -165,6 +196,11 @@ int sem_wait(FAR sem_t *sem)
if (*get_errno_ptr() != EINTR)
{
+ /* We hold the semaphore */
+
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ sem->holder = rtcb;
+#endif
ret = OK;
}
else
diff --git a/nuttx/sched/task_restart.c b/nuttx/sched/task_restart.c
index 3d682eb3d9..c254dd3039 100644
--- a/nuttx/sched/task_restart.c
+++ b/nuttx/sched/task_restart.c
@@ -1,7 +1,7 @@
-/************************************************************
- * task_restart.c
+/****************************************************************************
+ * sched/task_restart.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>
*
* 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
* the documentation and/or other materials provided with the
* 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
* without specific prior written permission.
*
@@ -31,11 +31,11 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Included Files
- ************************************************************/
+ ****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
@@ -44,35 +44,35 @@
#include "os_internal.h"
#include "sig_internal.h"
-/************************************************************
+/****************************************************************************
* Definitions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Type Declarations
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Global Variables
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Variables
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Function Prototypes
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Private Functions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Public Functions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Name: task_restart
*
* Description:
@@ -94,7 +94,7 @@
* (2) The pid is not associated with any task known to
* the system.
*
- ************************************************************/
+ ****************************************************************************/
STATUS task_restart(pid_t pid)
{
@@ -149,6 +149,9 @@ STATUS task_restart(pid_t pid)
/* Reset the task priority */
tcb->sched_priority = tcb->init_priority;
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ tcb->base_priority = tcb->init_priority;
+#endif
/* Re-initialize the processor-specific portion of the TCB
* This will reset the entry point and the start-up parameters
diff --git a/nuttx/sched/task_setup.c b/nuttx/sched/task_setup.c
index 6b80d5db05..25a85394a9 100644
--- a/nuttx/sched/task_setup.c
+++ b/nuttx/sched/task_setup.c
@@ -1,7 +1,7 @@
/****************************************************************************
- * task_setup.c
+ * sched/task_setup.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>
*
* Redistribution and use in source and binary forms, with or without
@@ -184,6 +184,9 @@ STATUS task_schedsetup(FAR _TCB *tcb, int priority,
tcb->init_priority = (ubyte)priority;
tcb->sched_priority = (ubyte)priority;
+#ifdef CONFIG_PRIORITY_INHERITANCE
+ tcb->base_priority = (ubyte)priority;
+#endif
tcb->start = start;
tcb->entry.main = main;