add holder for mutex

Signed-off-by: lilei19 <lilei19@xiaomi.com>
This commit is contained in:
lilei19
2023-01-17 19:15:34 +08:00
committed by Xiang Xiao
parent 64dd7e6376
commit fc176addeb
13 changed files with 504 additions and 153 deletions
+7 -6
View File
@@ -29,6 +29,7 @@
#include <nuttx/fs/ioctl.h>
#include <nuttx/spi/spi.h>
#include <nuttx/queue.h>
#include <nuttx/mutex.h>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/irq.h>
@@ -285,7 +286,7 @@ typedef struct alt_evtbuf_inst_s
uint16_t altcid;
FAR void **outparam;
size_t outparamlen;
sem_t stat_lock;
mutex_t stat_lock;
alt_evtbuf_state_t stat;
} alt_evtbuf_inst_t;
@@ -323,25 +324,25 @@ typedef struct altcom_fd_set_s altcom_fd_set;
struct alt_queue_s
{
sq_queue_t queue;
sem_t lock;
mutex_t lock;
};
struct alt1250_dev_s
{
FAR struct spi_dev_s *spi;
FAR const struct alt1250_lower_s *lower;
sem_t refslock;
mutex_t refslock;
uint8_t crefs;
struct alt_queue_s waitlist;
struct alt_queue_s replylist;
uint64_t evtbitmap;
sem_t evtmaplock;
sem_t pfdlock;
mutex_t evtmaplock;
mutex_t pfdlock;
FAR struct pollfd *pfd;
pthread_t recvthread;
FAR struct alt_evtbuffer_s *evtbuff;
uint32_t discardcnt;
sem_t senddisablelock;
mutex_t senddisablelock;
bool senddisable;
FAR alt_container_t *select_container;
struct alt_evtbuf_inst_s select_inst;
+312 -95
View File
File diff suppressed because it is too large Load Diff
+47
View File
@@ -35,6 +35,7 @@
#include <semaphore.h>
#include <nuttx/queue.h>
#include <nuttx/mutex.h>
#ifdef CONFIG_MM_IOB
# include <nuttx/mm/iob.h>
#endif
@@ -392,6 +393,30 @@ void net_unlock(void);
int net_sem_timedwait(sem_t *sem, unsigned int timeout);
/****************************************************************************
* Name: net_mutex_timedlock
*
* Description:
* Atomically wait for mutex (or a timeout) while temporarily releasing
* the lock on the network.
*
* Caution should be utilized. Because the network lock is relinquished
* during the wait, there could be changes in the network state that occur
* before the lock is recovered. Your design should account for this
* possibility.
*
* Input Parameters:
* mutex - A reference to the mutex to be taken.
* timeout - The relative time to wait until a timeout is declared.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure.
*
****************************************************************************/
int net_mutex_timedlock(mutex_t *mutex, unsigned int timeout);
/****************************************************************************
* Name: net_sem_wait
*
@@ -414,6 +439,28 @@ int net_sem_timedwait(sem_t *sem, unsigned int timeout);
int net_sem_wait(sem_t *sem);
/****************************************************************************
* Name: net_mutex_lock
*
* Description:
* Atomically wait for mutex while temporarily releasing the network lock.
*
* Caution should be utilized. Because the network lock is relinquished
* during the wait, there could be changes in the network state that occur
* before the lock is recovered. Your design should account for this
* possibility.
*
* Input Parameters:
* mutex - A reference to the mutex to be taken.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure.
*
****************************************************************************/
int net_mutex_lock(mutex_t *mutex);
/****************************************************************************
* Name: net_sem_timedwait_uninterruptible
*
+6 -6
View File
@@ -40,21 +40,21 @@
#ifdef CONFIG_PRIORITY_INHERITANCE
# if CONFIG_SEM_PREALLOCHOLDERS > 0
/* semcount, waitlist, flags, hhead */
/* semcount, flags, waitlist, hhead */
# define NXSEM_INITIALIZER(c, f) \
{(c), SEM_WAITLIST_INITIALIZER, (f), NULL}
{(c), (f), SEM_WAITLIST_INITIALIZER, NULL}
# else
/* semcount, waitlist, flags, holder[2] */
/* semcount, flags, waitlist, holder[2] */
# define NXSEM_INITIALIZER(c, f) \
{(c), SEM_WAITLIST_INITIALIZER, (f), {SEMHOLDER_INITIALIZER, SEMHOLDER_INITIALIZER}}
{(c), (f), SEM_WAITLIST_INITIALIZER, {SEMHOLDER_INITIALIZER, SEMHOLDER_INITIALIZER}}
# endif
#else /* CONFIG_PRIORITY_INHERITANCE */
/* semcount, waitlist */
/* semcount, flags, waitlist */
# define NXSEM_INITIALIZER(c, f) \
{(c), SEM_WAITLIST_INITIALIZER}
{(c), (f), SEM_WAITLIST_INITIALIZER}
#endif /* CONFIG_PRIORITY_INHERITANCE */
/* Most internal nxsem_* interfaces are not available in the user space in
+11 -9
View File
@@ -42,6 +42,7 @@
#define SEM_PRIO_INHERIT 1
#define SEM_PRIO_PROTECT 2
#define SEM_PRIO_MASK 3
#define SEM_PRIO_MUTEX 4
/* Value returned by sem_open() in the event of a failure. */
@@ -99,14 +100,15 @@ struct sem_s
volatile int16_t semcount; /* >0 -> Num counts available */
/* <0 -> Num tasks waiting for semaphore */
dq_queue_t waitlist;
/* If priority inheritance is enabled, then we have to keep track of which
* tasks hold references to the semaphore.
*/
uint8_t flags; /* See SEM_PRIO_* definitions */
dq_queue_t waitlist;
#ifdef CONFIG_PRIORITY_INHERITANCE
uint8_t flags; /* See PRIOINHERIT_FLAGS_* definitions */
# if CONFIG_SEM_PREALLOCHOLDERS > 0
FAR struct semholder_s *hhead; /* List of holders of semaphore counts */
# else
@@ -121,21 +123,21 @@ typedef struct sem_s sem_t;
#ifdef CONFIG_PRIORITY_INHERITANCE
# if CONFIG_SEM_PREALLOCHOLDERS > 0
/* semcount, waitlist, flags, hhead */
/* semcount, flags, waitlist, hhead */
# define SEM_INITIALIZER(c) \
{(c), SEM_WAITLIST_INITIALIZER, 0, NULL}
{(c), 0, SEM_WAITLIST_INITIALIZER, NULL}
# else
/* semcount, waitlist, flags, holder[2] */
/* semcount, flags, waitlist, holder[2] */
# define SEM_INITIALIZER(c) \
{(c), SEM_WAITLIST_INITIALIZER, 0, {SEMHOLDER_INITIALIZER, SEMHOLDER_INITIALIZER}}
{(c), 0, SEM_WAITLIST_INITIALIZER, {SEMHOLDER_INITIALIZER, SEMHOLDER_INITIALIZER}}
# endif
#else
/* semcount, waitlist */
/* semcount, flags, waitlist */
# define SEM_INITIALIZER(c) \
{(c), SEM_WAITLIST_INITIALIZER}
{(c), 0, SEM_WAITLIST_INITIALIZER}
#endif
# define SEM_WAITLIST(sem) (&((sem)->waitlist))