sched: Disable priority inheritance on all semaphores used for signaling

This commit is contained in:
Gregory Nutt 2016-11-03 12:42:02 -06:00
parent dbbe46a2bc
commit 1da3a5fa61
3 changed files with 24 additions and 3 deletions

View File

@ -205,7 +205,7 @@ int sem_getprotocol(FAR sem_t *sem, FAR int *protocol);
#ifdef CONFIG_PRIORITY_INHERITANCE
int sem_setprotocol(FAR sem_t *sem, int protocol);
#else
# define sem_setprotocol(s,p) DEBUGASSERT((p) == SEM_PRIO_NONE);
# define sem_setprotocol(s,p) ((p) == SEM_PRIO_NONE ? 0 : -ENOSYS);
#endif
#undef EXTERN

View File

@ -46,6 +46,7 @@
#include <nuttx/irq.h>
#include <nuttx/kmalloc.h>
#include <nuttx/semaphore.h>
#include "environ/environ.h"
#include "group/group.h"
@ -248,9 +249,14 @@ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype)
#endif
#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT)
/* Initialize the exit/wait semaphores */
/* Initialize the exit/wait semaphores
*
* This semaphore is used for signaling and, hence, should not have
* priority inheritance enabled.
*/
(void)sem_init(&group->tg_exitsem, 0, 0);
(void)sem_setprotocol(&group->tg_exitsem, SEM_PRIO_NONE);
#endif
return OK;

View File

@ -49,9 +49,10 @@
#include <errno.h>
#include <queue.h>
#include <nuttx/arch.h>
#include <nuttx/sempahore.h>
#include <nuttx/kmalloc.h>
#include <nuttx/pthread.h>
#include <nuttx/arch.h>
#include "sched/sched.h"
#include "group/group.h"
@ -498,6 +499,20 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
ret = sem_init(&pjoin->exit_sem, 0, 0);
}
/* Thse semaphores are used for signaling and, hence, should not have
* priority inheritance enabled.
*/
if (ret == OK)
{
ret = sem_setprotocol(&pjoin->data_sem, SEM_PRIO_NONE);
}
if (ret == OK)
{
ret = sem_setprotocol(&pjoin->exit_sem, SEM_PRIO_NONE);
}
/* If the priority of the new pthread is lower than the priority of the
* parent thread, then starting the pthread could result in both the
* parent and the pthread to be blocked. This is a recipe for priority