Make better use of new sched_settcpprio() API

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1588 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2009-03-10 02:03:24 +00:00
parent 327cdee632
commit 8c8f2bfd43
5 changed files with 63 additions and 58 deletions

View File

@ -104,7 +104,7 @@ int pthread_setschedprio(pthread_t thread, int prio)
/* Set the errno to some non-zero value (failsafe) */ /* Set the errno to some non-zero value (failsafe) */
*get_errno_ptr() = EINVAL; errno = EINVAL;
/* Call sched_setparam() to change the priority */ /* Call sched_setparam() to change the priority */
@ -114,7 +114,7 @@ int pthread_setschedprio(pthread_t thread, int prio)
{ {
/* If sched_setparam() fails, return the errno */ /* If sched_setparam() fails, return the errno */
ret = *get_errno_ptr(); ret = errno;
} }
return ret; return ret;
} }

View File

@ -110,9 +110,7 @@ int sched_setparam(pid_t pid, const struct sched_param *param)
/* Verify that the requested priority is in the valid range */ /* Verify that the requested priority is in the valid range */
if (!param || if (!param)
param->sched_priority < SCHED_PRIORITY_MIN ||
param->sched_priority > SCHED_PRIORITY_MAX)
{ {
errno = EINVAL; errno = EINVAL;
return ERROR; return ERROR;

View File

@ -1,7 +1,7 @@
/************************************************************ /****************************************************************************
* sched_setscheduler.c * sched/sched_setscheduler.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>
@ -46,35 +46,35 @@
#include "os_internal.h" #include "os_internal.h"
#include "clock_internal.h" #include "clock_internal.h"
/************************************************************ /****************************************************************************
* Definitions * Definitions
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Private Type Declarations * Private Type Declarations
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Global Variables * Global Variables
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Private Variables * Private Variables
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Private Functions * Private Functions
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Public Functions * Public Functions
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Name:sched_setscheduler * Name:sched_setscheduler
* *
* Description: * Description:
@ -104,7 +104,7 @@
* *
* Assumptions: * Assumptions:
* *
************************************************************/ ****************************************************************************/
int sched_setscheduler(pid_t pid, int policy, int sched_setscheduler(pid_t pid, int policy,
const struct sched_param *param) const struct sched_param *param)
@ -123,7 +123,7 @@ int sched_setscheduler(pid_t pid, int policy,
if (policy != SCHED_FIFO) if (policy != SCHED_FIFO)
#endif #endif
{ {
*get_errno_ptr() = EINVAL; errno = EINVAL;
return ERROR; return ERROR;
} }
@ -139,7 +139,7 @@ int sched_setscheduler(pid_t pid, int policy,
tcb = sched_gettcb(pid); tcb = sched_gettcb(pid);
if (!tcb) if (!tcb)
{ {
*get_errno_ptr() = ESRCH; errno = ESRCH;
return ERROR; return ERROR;
} }
@ -173,7 +173,7 @@ int sched_setscheduler(pid_t pid, int policy,
/* Set the new priority */ /* Set the new priority */
ret = sched_setparam(pid, param); ret = sched_settcbprio(tcb, param->sched_priority);
sched_unlock(); sched_unlock();
if (ret != OK) if (ret != OK)

View File

@ -105,6 +105,15 @@ int sched_settcbprio(FAR _TCB *tcb, int sched_priority)
tstate_t task_state; tstate_t task_state;
irqstate_t saved_state; irqstate_t saved_state;
/* Verify that the requested priority is in the valid range */
if (sched_priority < SCHED_PRIORITY_MIN ||
sched_priority > SCHED_PRIORITY_MAX)
{
errno = EINVAL;
return ERROR;
}
/* We need to assure that there there is no interrupt activity while /* We need to assure that there there is no interrupt activity while
* performing the following. * performing the following.
*/ */

View File

@ -1,7 +1,7 @@
/************************************************************ /****************************************************************************
* sched_yield.c * sched/sched_yield.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,46 +31,46 @@
* 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>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include "os_internal.h" #include "os_internal.h"
/************************************************************ /****************************************************************************
* Definitions * Definitions
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Private Type Declarations * Private Type Declarations
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Global Variables * Global Variables
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Private Variables * Private Variables
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Private Functions * Private Functions
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Public Functions * Public Functions
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Name: sched_yield * Name: sched_yield
* *
* Description: * Description:
@ -85,18 +85,16 @@
* *
* Assumptions: * Assumptions:
* *
************************************************************/ ****************************************************************************/
int sched_yield (void) int sched_yield(void)
{ {
FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
struct sched_param param;
/* This equivalent to just resetting the task priority to /* This equivalent to just resetting the task priority to
* its current value since this will cause the task to * its current value since this will cause the task to
* be rescheduled behind any other tasks at the same priority. * be rescheduled behind any other tasks at the same priority.
*/ */
param.sched_priority = rtcb->sched_priority; return sched_settcbprio(rtcb, rtcb->sched_priority);
return sched_setparam(0, &param);
} }