nuttx/libs/libc/spawn/lib_psa_init.c
Gregory Nutt 717bb04cb7 Increase the number of real time signals. Two is not enough.
Refer to issue #8867 for details and rational.

Convert sigset_t to an array type so that more than 32 signals can be supported.

Why not use a uin64_t?
- Using a uin32_t is more flexible if we decide to increase the number of signals beyound 64.
- 64-bit accesses are not atomic, at least not on 32-bit ARMv7-M and similar
- Keeping the base type as uint32_t does not introduce additional overhead due to padding to achieve 64-bit alignment of uin64_t
- Some architectures still supported by NuttX do not support uin64_t
  types,

Increased the number of signals to 64. This matches Linux. This will support all xsignals defined by Linux and also 32 real time signals (also like Linux).

This is is a work in progress; a draft PR that you are encouraged to comment on.
2023-03-27 16:59:04 +03:00

111 lines
3.3 KiB
C

/****************************************************************************
* libs/libc/spawn/lib_psa_init.c
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sched.h>
#include <spawn.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/sched.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: posix_spawnattr_init
*
* Description:
* The posix_spawnattr_init() function initializes the object referenced
* by attr, to an empty set of spawn attributes for subsequent use in a
* call to posix_spawn() or posix_spawnp().
*
* Input Parameters:
* attr - The address of the spawn attributes to be initialized.
*
* Returned Value:
* On success, these functions return 0; on failure they return an error
* number from <errno.h>.
*
****************************************************************************/
int posix_spawnattr_init(posix_spawnattr_t *attr)
{
struct sched_param param;
int ret;
DEBUGASSERT(attr);
/* Flags: None */
attr->flags = 0;
/* Set the default priority to the same priority as this task */
ret = _SCHED_GETPARAM(0, &param);
if (ret < 0)
{
return _SCHED_ERRNO(ret);
}
attr->priority = param.sched_priority;
/* Set the default scheduler policy to the policy of this task */
ret = _SCHED_GETSCHEDULER(0);
if (ret < 0)
{
return _SCHED_ERRNO(ret);
}
attr->policy = ret;
/* Empty signal mask */
sigemptyset(&attr->sigmask);
#ifdef CONFIG_SCHED_SPORADIC
/* Sporadic scheduling parameters */
attr->low_priority = (uint8_t)param.sched_ss_low_priority;
attr->max_repl = (uint8_t)param.sched_ss_max_repl;
attr->repl_period.tv_sec = param.sched_ss_repl_period.tv_sec;
attr->repl_period.tv_nsec = param.sched_ss_repl_period.tv_nsec;
attr->budget.tv_sec = param.sched_ss_init_budget.tv_sec;
attr->budget.tv_nsec = param.sched_ss_init_budget.tv_nsec;
#endif
/* Default stack size */
attr->stacksize = CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE;
#ifndef CONFIG_BUILD_KERNEL
attr->stackaddr = NULL;
#endif
return OK;
}