mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 18:56:10 +08:00
net/usrsock: replace net_lock with usrsock_lock
Build Documentation / build-html (push) Has been cancelled
Build Documentation / build-html (push) Has been cancelled
remove the use of net_lock in the usrsock module and decouple it from other network modules. Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
committed by
Alan C. Assis
parent
24ee7cba86
commit
f27a9bbc27
@@ -411,30 +411,6 @@ void net_unlock(void);
|
||||
|
||||
int net_sem_timedwait(FAR 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(FAR mutex_t *mutex, unsigned int timeout);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_sem_wait
|
||||
*
|
||||
@@ -457,28 +433,6 @@ int net_mutex_timedlock(FAR mutex_t *mutex, unsigned int timeout);
|
||||
|
||||
int net_sem_wait(FAR 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(FAR mutex_t *mutex);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_sem_timedwait_uninterruptible
|
||||
*
|
||||
|
||||
@@ -34,8 +34,10 @@
|
||||
#include <sys/uio.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/compiler.h>
|
||||
#include <nuttx/mutex.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@@ -267,6 +269,121 @@ begin_packed_struct struct usrsock_message_socket_event_s
|
||||
int16_t usockid;
|
||||
} end_packed_struct;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* Global protection lock for usrsock socket */
|
||||
|
||||
#ifdef CONFIG_NET_USRSOCK
|
||||
extern rmutex_t g_usrsock_lock;
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_lock
|
||||
*
|
||||
* Description:
|
||||
* Take the global usrsock socket lock
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline_function void usrsock_lock(void)
|
||||
{
|
||||
nxrmutex_lock(&g_usrsock_lock);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_unlock
|
||||
*
|
||||
* Description:
|
||||
* Release the global usrsock socket lock
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline_function void usrsock_unlock(void)
|
||||
{
|
||||
nxrmutex_unlock(&g_usrsock_lock);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_sem_timedwait
|
||||
*
|
||||
* Description:
|
||||
* Wait for sem while temporarily releasing the usrsock lock.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline_function int
|
||||
usrsock_sem_timedwait(FAR sem_t *sem, bool interruptible,
|
||||
unsigned int timeout)
|
||||
{
|
||||
return net_sem_timedwait2(sem, interruptible, timeout, &g_usrsock_lock,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_mutex_timedlock
|
||||
*
|
||||
* Description:
|
||||
* Atomically wait for mutex (or a timeout) while temporarily releasing
|
||||
* the lock on the usrsock.
|
||||
*
|
||||
* Caution should be utilized. Because the usrsock lock is relinquished
|
||||
* during the wait, there could be changes in the usrsock 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.
|
||||
* brkmutex - A reference to the mutex to be temporarily released while
|
||||
* waiting.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline_function int
|
||||
usrsock_mutex_timedlock(FAR mutex_t *mutex, unsigned int timeout)
|
||||
{
|
||||
unsigned int count;
|
||||
int blresult;
|
||||
int ret;
|
||||
|
||||
/* Release the network lock, remembering my count. net_breaklock will
|
||||
* return a negated value if the caller does not hold the network lock.
|
||||
*/
|
||||
|
||||
blresult = nxrmutex_breaklock(&g_usrsock_lock, &count);
|
||||
|
||||
/* Now take the mutex, waiting if so requested. */
|
||||
|
||||
if (timeout != UINT_MAX)
|
||||
{
|
||||
ret = nxmutex_timedlock(mutex, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Wait as long as necessary to get the lock */
|
||||
|
||||
ret = nxmutex_lock(mutex);
|
||||
}
|
||||
|
||||
/* Recover the network lock at the proper count (if we held it before) */
|
||||
|
||||
if (blresult >= 0)
|
||||
{
|
||||
nxrmutex_restorelock(&g_usrsock_lock, count);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_iovec_get() - copy from iovec to buffer.
|
||||
****************************************************************************/
|
||||
@@ -310,5 +427,6 @@ int usrsock_request(FAR struct iovec *iov, unsigned int iovcnt);
|
||||
****************************************************************************/
|
||||
|
||||
void usrsock_register(void);
|
||||
#endif /* CONFIG_NET_USRSOCK */
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_NET_USRSOCK_H */
|
||||
|
||||
Reference in New Issue
Block a user