2007-03-24 16:51:01 +01:00
|
|
|
/****************************************************************************
|
2014-08-08 22:21:48 +02:00
|
|
|
* sched/pthread/pthread_setschedprio.c
|
2007-03-24 16:51:01 +01:00
|
|
|
*
|
2024-09-11 13:45:11 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2020-05-09 17:05:29 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-03-24 16:51:01 +01:00
|
|
|
*
|
2020-05-09 17:05:29 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-03-24 16:51:01 +01:00
|
|
|
*
|
2020-05-09 17:05:29 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-03-24 16:51:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2018-01-30 18:07:36 +01:00
|
|
|
|
2007-03-24 16:51:01 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <errno.h>
|
2018-01-30 18:07:36 +01:00
|
|
|
|
|
|
|
#include <nuttx/sched.h>
|
2007-03-24 16:51:01 +01:00
|
|
|
#include <nuttx/arch.h>
|
2018-01-30 18:07:36 +01:00
|
|
|
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2007-03-24 16:51:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pthread_setsetprio
|
|
|
|
*
|
|
|
|
* Description:
|
2020-05-09 17:05:29 +02:00
|
|
|
* The pthread_setschedprio() function sets the scheduling priority for
|
|
|
|
* the thread whose thread ID is given by 'thread' to the value given by
|
|
|
|
* 'prio'. If the thread_setschedprio() function fails, the scheduling
|
|
|
|
* priority of the target thread will not be changed.
|
2007-03-24 16:51:01 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2007-03-24 16:51:01 +01:00
|
|
|
* thread - the thread ID of the task to reprioritize.
|
|
|
|
* prio - The new thread priority. The range of valid priority numbers is
|
|
|
|
* from SCHED_PRIORITY_MIN through SCHED_PRIORITY_MAX.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-03-24 16:51:01 +01:00
|
|
|
* OK if successful, otherwise an error number. This function can
|
|
|
|
* fail for the following reasons:
|
|
|
|
*
|
|
|
|
* EINVAL - prio is out of range.
|
|
|
|
* ESRCH - thread ID does not correspond to any thread.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int pthread_setschedprio(pthread_t thread, int prio)
|
|
|
|
{
|
|
|
|
struct sched_param param;
|
|
|
|
int ret;
|
|
|
|
|
2015-07-23 21:16:32 +02:00
|
|
|
#ifdef CONFIG_SCHED_SPORADIC
|
|
|
|
/* Get the current sporadic scheduling parameters. Those will not be
|
|
|
|
* modified.
|
|
|
|
*/
|
2007-03-24 16:51:01 +01:00
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
ret = nxsched_get_param((pid_t)thread, ¶m);
|
2015-07-23 21:16:32 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2018-01-30 18:07:36 +01:00
|
|
|
return -ret;
|
2015-07-23 21:16:32 +02:00
|
|
|
}
|
|
|
|
#endif
|
2007-03-24 16:51:01 +01:00
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
/* Call nxsched_set_param() to change the priority */
|
2007-03-24 16:51:01 +01:00
|
|
|
|
|
|
|
param.sched_priority = prio;
|
2020-05-09 16:04:45 +02:00
|
|
|
ret = nxsched_set_param((pid_t)thread, ¶m);
|
2018-01-30 18:07:36 +01:00
|
|
|
if (ret < 0)
|
2007-03-24 16:51:01 +01:00
|
|
|
{
|
2018-01-30 18:07:36 +01:00
|
|
|
return -ret;
|
2007-03-24 16:51:01 +01:00
|
|
|
}
|
2014-08-29 01:00:24 +02:00
|
|
|
|
2018-01-30 18:07:36 +01:00
|
|
|
return OK;
|
2007-03-24 16:51:01 +01:00
|
|
|
}
|