nuttx/sched/signal/sig_unmaskpendingsignal.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

118 lines
3.9 KiB
C

/****************************************************************************
* sched/signal/sig_unmaskpendingsignal.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 <nuttx/signal.h>
#include "sched/sched.h"
#include "signal/signal.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxsig_unmask_pendingsignal
*
* Description:
* Based upon the current setting of the sigprocmask, this function
* unmasks and processes any pending signals. This function should
* be called whenever the sigprocmask is changed.
*
****************************************************************************/
bool nxsig_unmask_pendingsignal(void)
{
FAR struct tcb_s *rtcb = this_task();
sigset_t unmaskedset;
FAR sigpendq_t *pendingsig;
int signo;
/* Prohibit any context switches until we are done with this.
* We may still be performing signal operations from interrupt
* handlers, however, none of the pending signals that we
* are concerned with here should be effected.
*/
sched_lock();
/* Get the set of pending signals that were just unmasked. The
* following operation should be safe because the sigprocmask
* can only be changed on this thread of execution.
*/
unmaskedset = nxsig_pendingset(rtcb);
nxsig_nandset(&unmaskedset, &unmaskedset, &rtcb->sigprocmask);
if (sigisemptyset(&unmaskedset))
{
sched_unlock();
return false;
}
/* Loop while there are unmasked pending signals to be processed. */
do
{
/* Pending signals will be processed from lowest numbered signal
* to highest
*/
signo = nxsig_lowest(&unmaskedset);
if (signo != ERROR)
{
/* Remove the signal from the set of unmasked signals. NOTE:
* this implicitly assumes that only one instance for a given
* signal number is pending.
*/
nxsig_delset(&unmaskedset, signo);
/* Remove the pending signal from the list of pending signals */
if ((pendingsig = nxsig_remove_pendingsignal(rtcb, signo)) != NULL)
{
/* If there is one, then process it like a normal signal.
* Since the signal was pending, then unblocked on this
* thread, we can skip the normal group signal dispatching
* rules; there can be no other recipient for the signal
* other than this thread.
*/
nxsig_tcbdispatch(rtcb, &pendingsig->info);
/* Then remove it from the pending signal list */
nxsig_release_pendingsignal(pendingsig);
}
}
}
while (!sigisemptyset(&unmaskedset));
sched_unlock();
return true;
}