2012-07-14 21:30:31 +02:00
|
|
|
/****************************************************************************
|
2014-08-08 22:21:48 +02:00
|
|
|
* sched/pthread/pthread_setschedparam.c
|
2007-02-18 00:21:28 +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-02-18 00:21:28 +01:00
|
|
|
*
|
2020-05-09 17:05:29 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +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-02-18 00:21:28 +01:00
|
|
|
*
|
2012-07-14 21:30:31 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2012-07-14 21:30:31 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-01-30 23:16:41 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2018-01-30 23:16:41 +01:00
|
|
|
#include <nuttx/sched.h>
|
|
|
|
|
2014-08-08 20:55:02 +02:00
|
|
|
#include "pthread/pthread.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2012-07-14 21:30:31 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: pthread_setschedparam
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2012-07-14 21:30:31 +02:00
|
|
|
* The pthread_setschedparam() functions will set the scheduling policy
|
|
|
|
* and parameters of threads. For SCHED_FIFO and SCHED_RR, the only
|
|
|
|
* required member of the sched_param structure is the priority
|
|
|
|
* sched_priority.
|
2007-03-24 16:51:50 +01:00
|
|
|
*
|
2012-07-14 21:30:31 +02:00
|
|
|
* The pthread_setschedparam() function will set the scheduling policy
|
|
|
|
* and associated scheduling parameters for the thread whose thread ID
|
|
|
|
* is given by 'thread' to the policy and associated parameters provided
|
|
|
|
* in 'policy' and 'param', respectively.
|
2007-03-24 16:51:50 +01:00
|
|
|
*
|
|
|
|
* The policy parameter may have the value SCHED_FIFO, or SCHED_RR
|
|
|
|
* (SCHED_OTHER and SCHED_SPORADIC, in particular, are not supported).
|
|
|
|
* The SCHED_FIFO and SCHED_RR policies will have a single scheduling
|
|
|
|
* parameter, sched_priority.
|
|
|
|
*
|
|
|
|
* If the pthread_setschedparam() function fails, the scheduling parameters
|
|
|
|
* will not be changed for the target thread.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2007-03-24 16:51:50 +01:00
|
|
|
* thread - The ID of thread whose scheduling parameters will be modified.
|
|
|
|
* policy - The new scheduling policy of the thread. Either SCHED_FIFO or
|
|
|
|
* SCHED_RR. SCHED_OTHER and SCHED_SPORADIC are not supported.
|
|
|
|
* param - Provides the new priority of the thread.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-03-24 16:51:50 +01:00
|
|
|
* 0 if successful. Otherwise, an error code identifying the cause of the
|
|
|
|
* failure:
|
|
|
|
*
|
2012-07-14 21:30:31 +02:00
|
|
|
* EINVAL The value specified by 'policy' or one of the scheduling
|
|
|
|
* parameters associated with the scheduling policy 'policy' is
|
|
|
|
* invalid.
|
2007-03-24 16:51:50 +01:00
|
|
|
* ENOTSUP An attempt was made to set the policy or scheduling parameters
|
|
|
|
* to an unsupported value (SCHED_OTHER and SCHED_SPORADIC in
|
|
|
|
* particular are not supported)
|
2020-05-09 17:05:29 +02:00
|
|
|
* EPERM The caller does not have the appropriate permission to set
|
|
|
|
* either the scheduling parameters or the scheduling policy of
|
|
|
|
* the specified thread. Or, the implementation does not allow
|
|
|
|
* the application to modify one of the parameters to the value
|
2007-03-24 16:51:50 +01:00
|
|
|
* specified.
|
2020-05-09 17:05:29 +02:00
|
|
|
* ESRCH The value specified by thread does not refer to a existing
|
|
|
|
* thread.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2012-07-14 21:30:31 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-07-23 21:16:32 +02:00
|
|
|
int pthread_setschedparam(pthread_t thread, int policy,
|
|
|
|
FAR const struct sched_param *param)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-03-24 16:51:50 +01:00
|
|
|
int ret;
|
|
|
|
|
2022-06-30 19:34:24 +02:00
|
|
|
sinfo("thread ID=%d policy=%d param=%p\n", thread, policy, param);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
/* Let nxsched_set_scheduler do all of the work */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
ret = nxsched_set_scheduler((pid_t)thread, policy, param);
|
2018-01-30 23:16:41 +01:00
|
|
|
if (ret < 0)
|
2007-03-24 16:51:50 +01:00
|
|
|
{
|
2020-05-09 16:04:45 +02:00
|
|
|
/* If nxsched_set_scheduler() fails, return the positive errno value */
|
2007-03-24 16:51:50 +01:00
|
|
|
|
2018-01-30 23:16:41 +01:00
|
|
|
ret = -ret;
|
2007-03-24 16:51:50 +01:00
|
|
|
}
|
2012-04-18 15:24:39 +02:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
return ret;
|
|
|
|
}
|