[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Backport semaphore fixes #188

Draft
wants to merge 5 commits into
base: px4_firmware_nuttx-10.1.0+
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/nuttx/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,11 @@ struct tcb_s

#ifdef CONFIG_PRIORITY_INHERITANCE
#if CONFIG_SEM_NNESTPRIO > 0
uint8_t nsem_held; /* used to condition priority restore */
uint8_t npend_reprio; /* Number of nested reprioritizations */
uint8_t pend_reprios[CONFIG_SEM_NNESTPRIO];
#endif
uint8_t base_priority; /* "Normal" priority of the thread */
FAR struct semholder_s *holdsem; /* List of held semaphores */
#endif

uint8_t task_state; /* Current state of the thread */
Expand Down
15 changes: 15 additions & 0 deletions include/nuttx/semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@
* Pre-processor Definitions
****************************************************************************/

/* Initializers */

#ifdef CONFIG_PRIORITY_INHERITANCE
# if CONFIG_SEM_PREALLOCHOLDERS > 0
# define NXSEM_INITIALIZER(c, f) \
{(c), (f), NULL} /* semcount, flags, hhead */
# else
# define NXSEM_INITIALIZER(c, f) \
{(c), (f), {SEMHOLDER_INITIALIZER, SEMHOLDER_INITIALIZER}} /* semcount, flags, holder[2] */
# endif
#else /* CONFIG_PRIORITY_INHERITANCE */
# define NXSEM_INITIALIZER(c, f) \
{(c)} /* semcount, flags */
#endif /* CONFIG_PRIORITY_INHERITANCE */

/* Most internal nxsem_* interfaces are not available in the user space in
* PROTECTED and KERNEL builds. In that context, the application semaphore
* interfaces must be used. The differences between the two sets of
Expand Down
29 changes: 24 additions & 5 deletions include/semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,38 @@

#ifdef CONFIG_PRIORITY_INHERITANCE
struct tcb_s; /* Forward reference */
struct sem_s;

struct semholder_s
{
#if CONFIG_SEM_PREALLOCHOLDERS > 0
struct semholder_s *flink; /* Implements singly linked list */
FAR struct semholder_s *flink; /* List of semaphore's holder */
#endif
FAR struct tcb_s *htcb; /* Holder TCB */
int16_t counts; /* Number of counts owned by this holder */
FAR struct semholder_s *tlink; /* List of task held semaphores */
FAR struct sem_s *sem; /* Ths corresponding semaphore */
FAR struct tcb_s *htcb; /* Ths corresponding TCB */
int16_t counts; /* Number of counts owned by this holder */
};

#if CONFIG_SEM_PREALLOCHOLDERS > 0
# define SEMHOLDER_INITIALIZER {NULL, NULL, 0}
# define SEMHOLDER_INITIALIZER {NULL, NULL, NULL, NULL, 0}
# define INITIALIZE_SEMHOLDER(h) \
do { \
(h)->flink = NULL; \
(h)->tlink = NULL; \
(h)->sem = NULL; \
(h)->htcb = NULL; \
(h)->counts = 0; \
} while (0)
#else
# define SEMHOLDER_INITIALIZER {NULL, 0}
# define SEMHOLDER_INITIALIZER {NULL, NULL, NULL, 0}
# define INITIALIZE_SEMHOLDER(h) \
do { \
(h)->tlink = NULL; \
(h)->sem = NULL; \
(h)->htcb = NULL; \
(h)->counts = 0; \
} while (0)
#endif
#endif /* CONFIG_PRIORITY_INHERITANCE */

Expand Down
6 changes: 2 additions & 4 deletions libs/libc/semaphore/sem_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ int nxsem_init(FAR sem_t *sem, int pshared, unsigned int value)
# if CONFIG_SEM_PREALLOCHOLDERS > 0
sem->hhead = NULL;
# else
sem->holder[0].htcb = NULL;
sem->holder[0].counts = 0;
sem->holder[1].htcb = NULL;
sem->holder[1].counts = 0;
INITIALIZE_SEMHOLDER(&sem->holder[0]);
INITIALIZE_SEMHOLDER(&sem->holder[1]);
# endif
#endif
return OK;
Expand Down
Loading