Skip to content
Merged
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 net/arp/arp_notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ int arp_wait(FAR struct arp_notify_s *notify, unsigned int timeout)

/* And wait for the ARP response (or a timeout). */

net_sem_timedwait_uninterruptible(&notify->nt_sem, timeout);
nxsem_tickwait_uninterruptible(&notify->nt_sem, MSEC2TICK(timeout));

/* Then get the real result of the transfer */

Expand Down
6 changes: 3 additions & 3 deletions net/arp/arp_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,15 @@ int arp_send(in_addr_t ipaddr)
netdev_txnotify_dev(dev, ARP_POLL);

/* Wait for the send to complete or an error to occur.
* net_sem_wait will also terminate if a signal is received.
* nxsem_tickwait will also terminate if a signal is received.
*/

netdev_unlock(dev);

do
{
ret = net_sem_timedwait_uninterruptible(&state.snd_sem,
CONFIG_ARP_SEND_DELAYMSEC);
ret = nxsem_tickwait(&state.snd_sem,
MSEC2TICK(CONFIG_ARP_SEND_DELAYMSEC));
if (ret == -ETIMEDOUT)
{
arp_wait_cancel(&notify);
Expand Down
35 changes: 35 additions & 0 deletions net/bluetooth/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <sys/types.h>
#include <sys/socket.h>

#include <nuttx/mutex.h>
#include <nuttx/net/net.h>

#include <nuttx/wireless/bluetooth/bt_hci.h>
Expand Down Expand Up @@ -119,6 +120,40 @@ extern "C"

EXTERN const struct sock_intf_s g_bluetooth_sockif;

/* The Bluetooth connections rmutex */

extern rmutex_t g_bluetooth_connections_lock;

/****************************************************************************
* Inline Functions
****************************************************************************/

/****************************************************************************
* Name: bluetooth_conn_list_lock
*
* Description:
* Lock the Bluetooth connection list.
*
****************************************************************************/

static inline_function void bluetooth_conn_list_lock(void)
{
nxrmutex_lock(&g_bluetooth_connections_lock);
}

/****************************************************************************
* Name: bluetooth_conn_list_unlock
*
* Description:
* Unlock the Bluetooth connection list.
*
****************************************************************************/

static inline_function void bluetooth_conn_list_unlock(void)
{
nxrmutex_unlock(&g_bluetooth_connections_lock);
}

/****************************************************************************
* Public Function Prototypes
****************************************************************************/
Expand Down
3 changes: 3 additions & 0 deletions net/bluetooth/bluetooth_callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <nuttx/net/bluetooth.h>

#include "devif/devif.h"
#include "utils/utils.h"
#include "bluetooth/bluetooth.h"

#ifdef CONFIG_NET_BLUETOOTH
Expand Down Expand Up @@ -71,7 +72,9 @@ uint32_t bluetooth_callback(FAR struct radio_driver_s *radio,
{
/* Perform the callback */

conn_lock(&conn->bc_conn);
flags = devif_conn_event(&radio->r_dev, flags, conn->bc_conn.list);
conn_unlock(&conn->bc_conn);
}

return flags;
Expand Down
16 changes: 12 additions & 4 deletions net/bluetooth/bluetooth_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
# define CONFIG_NET_BLUETOOTH_MAX_CONNS 0
#endif

/****************************************************************************
* Public Data
****************************************************************************/

/* The Bluetooth connections rmutex */

rmutex_t g_bluetooth_connections_lock = NXRMUTEX_INITIALIZER;

/****************************************************************************
* Private Data
****************************************************************************/
Expand Down Expand Up @@ -96,7 +104,7 @@ FAR struct bluetooth_conn_s *bluetooth_conn_alloc(void)

/* The free list is protected by the network lock */

net_lock();
bluetooth_conn_list_lock();

conn = NET_BUFPOOL_TRYALLOC(g_bluetooth_connections);
if (conn)
Expand All @@ -110,7 +118,7 @@ FAR struct bluetooth_conn_s *bluetooth_conn_alloc(void)
dq_addlast(&conn->bc_conn.node, &g_active_bluetooth_connections);
}

net_unlock();
bluetooth_conn_list_unlock();
return conn;
}

Expand All @@ -134,7 +142,7 @@ void bluetooth_conn_free(FAR struct bluetooth_conn_s *conn)

/* Remove the connection from the active list */

net_lock();
bluetooth_conn_list_lock();
dq_rem(&conn->bc_conn.node, &g_active_bluetooth_connections);

/* Check if there any any frames attached to the container */
Expand Down Expand Up @@ -162,7 +170,7 @@ void bluetooth_conn_free(FAR struct bluetooth_conn_s *conn)

NET_BUFPOOL_FREE(g_bluetooth_connections, conn);

net_unlock();
bluetooth_conn_list_unlock();
}

/****************************************************************************
Expand Down
12 changes: 6 additions & 6 deletions net/bluetooth/bluetooth_container.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ FAR struct bluetooth_container_s *bluetooth_container_allocate(void)

/* Try the free list first */

net_lock();
bluetooth_conn_list_lock();
if (g_free_container != NULL)
{
container = g_free_container;
g_free_container = container->bn_flink;
pool = BLUETOOTH_POOL_PREALLOCATED;
net_unlock();
bluetooth_conn_list_unlock();
}
else
{
net_unlock();
bluetooth_conn_list_unlock();
container = (FAR struct bluetooth_container_s *)
kmm_malloc((sizeof(struct bluetooth_container_s)));
pool = BLUETOOTH_POOL_DYNAMIC;
Expand Down Expand Up @@ -188,20 +188,20 @@ void bluetooth_container_free(FAR struct bluetooth_container_s *container)
* in the free list.
*/

net_lock();
bluetooth_conn_list_lock();
if (container->bn_pool == BLUETOOTH_POOL_PREALLOCATED)
{
container->bn_flink = g_free_container;
g_free_container = container;
net_unlock();
bluetooth_conn_list_unlock();
}
else
{
DEBUGASSERT(container->bn_pool == BLUETOOTH_POOL_DYNAMIC);

/* Otherwise, deallocate it. */

net_unlock();
bluetooth_conn_list_unlock();
kmm_free(container);
}
}
18 changes: 11 additions & 7 deletions net/bluetooth/bluetooth_recvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "netdev/netdev.h"
#include "devif/devif.h"
#include "socket/socket.h"
#include "utils/utils.h"
#include "bluetooth/bluetooth.h"

#ifdef CONFIG_NET_BLUETOOTH
Expand Down Expand Up @@ -341,7 +342,6 @@ ssize_t bluetooth_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
* locked because we don't want anything to happen until we are ready.
*/

net_lock();
memset(&state, 0, sizeof(struct bluetooth_recvfrom_s));

state.ir_buflen = len;
Expand All @@ -358,6 +358,8 @@ ssize_t bluetooth_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
goto errout_with_lock;
}

conn_dev_lock(&conn->bc_conn, &radio->r_dev);

/* Before we wait for data, let's check if there are already frame(s)
* waiting in the RX queue.
*/
Expand All @@ -367,7 +369,7 @@ ssize_t bluetooth_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
{
/* Good newe! We have a frame and we are done. */

net_unlock();
conn_dev_unlock(&conn->bc_conn, &radio->r_dev);
return ret;
}

Expand All @@ -383,12 +385,14 @@ ssize_t bluetooth_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
state.ir_cb->event = bluetooth_recvfrom_eventhandler;

/* Wait for either the receive to complete or for an error/timeout to
* occur. NOTES: (1) net_sem_wait will also terminate if a signal
* is received, (2) the network is locked! It will be un-locked while
* the task sleeps and automatically re-locked when the task restarts.
* occur. NOTES: (1) conn_dev_sem_timedwait will also terminate if a
* signal is received, (2) the network is locked! It will be un-locked
* while the task sleeps and automatically re-locked when the task
* restarts.
*/

net_sem_wait(&state.ir_sem);
conn_dev_sem_timedwait(&state.ir_sem, true, UINT_MAX,
&conn->bc_conn, &radio->r_dev);

/* Make sure that no further events are processed */

Expand All @@ -403,7 +407,7 @@ ssize_t bluetooth_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
nxsem_destroy(&state.ir_sem);

errout_with_lock:
net_unlock();
conn_dev_unlock(&conn->bc_conn, &radio->r_dev);
return ret;
}

Expand Down
18 changes: 10 additions & 8 deletions net/bluetooth/bluetooth_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ static ssize_t bluetooth_sendto(FAR struct socket *psock,
* because we don't want anything to happen until we are ready.
*/

net_lock();
conn_dev_lock(&conn->bc_conn, &radio->r_dev);
memset(&state, 0, sizeof(struct bluetooth_sendto_s));
nxsem_init(&state.is_sem, 0, 0); /* Doesn't really fail */

Expand Down Expand Up @@ -347,10 +347,12 @@ static ssize_t bluetooth_sendto(FAR struct socket *psock,
netdev_txnotify_dev(&radio->r_dev, BLUETOOTH_POLL);

/* Wait for the send to complete or an error to occur.
* net_sem_wait will also terminate if a signal is received.
* conn_dev_sem_timedwait will also terminate if a signal is
* received.
*/

ret = net_sem_wait(&state.is_sem);
ret = conn_dev_sem_timedwait(&state.is_sem, true, UINT_MAX,
&conn->bc_conn, &radio->r_dev);

/* Make sure that no further events are processed */

Expand All @@ -359,7 +361,7 @@ static ssize_t bluetooth_sendto(FAR struct socket *psock,
}

nxsem_destroy(&state.is_sem);
net_unlock();
conn_dev_unlock(&conn->bc_conn, &radio->r_dev);

/* Check for a errors, Errors are signaled by negative errno values
* for the send length
Expand All @@ -370,9 +372,9 @@ static ssize_t bluetooth_sendto(FAR struct socket *psock,
return state.is_sent;
}

/* If net_sem_wait failed, then we were probably reawakened by a signal.
* In this case, net_sem_wait will have returned negated errno
* appropriately.
/* If conn_dev_sem_timedwait failed, then we were probably reawakened by
* a signal. In this case, conn_dev_sem_timedwait will have returned
* negated errno appropriately.
*/

if (ret < 0)
Expand All @@ -386,7 +388,7 @@ static ssize_t bluetooth_sendto(FAR struct socket *psock,

err_with_net:
nxsem_destroy(&state.is_sem);
net_unlock();
conn_dev_unlock(&conn->bc_conn, &radio->r_dev);

return ret;
}
Expand Down
21 changes: 11 additions & 10 deletions net/can/can_recvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ static uint32_t can_recvfrom_eventhandler(FAR struct net_driver_s *dev,
* Evaluate the result of the recv operations
*
* Input Parameters:
* result The result of the net_sem_wait operation (may indicate EINTR)
* result The result of the conn_dev_sem_timedwait operation
* (may indicate EINTR)
* pstate A pointer to the state structure to be initialized
*
* Returned Value:
Expand All @@ -384,9 +385,9 @@ static ssize_t can_recvfrom_result(int result,
return pstate->pr_result;
}

/* If net_sem_wait failed, then we were probably reawakened by a signal.
* In this case, net_sem_wait will have returned negated errno
* appropriately.
/* If conn_dev_sem_timedwait failed, then we were probably reawakened by
* a signal. In this case, conn_dev_sem_timedwait will have returned
* negated errno appropriately.
*/

if (result < 0)
Expand Down Expand Up @@ -518,14 +519,14 @@ ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
state.pr_cb->event = can_recvfrom_eventhandler;

/* Wait for either the receive to complete or for an error/timeout to
* occur. NOTES: (1) net_sem_wait will also terminate if a signal
* is received, (2) the network is locked! It will be un-locked while
* the task sleeps and automatically re-locked when the task restarts.
* occur. NOTES: (1) conn_dev_sem_timedwait will also terminate if a
* signal is received, (2) the network is locked! It will be un-locked
* while the task sleeps and automatically re-locked when the task
* restarts.
*/

conn_dev_unlock(&conn->sconn, dev);
ret = net_sem_wait(&state.pr_sem);
conn_dev_lock(&conn->sconn, dev);
ret = conn_dev_sem_timedwait(&state.pr_sem, true, UINT_MAX,
&conn->sconn, dev);

/* Make sure that no further events are processed */

Expand Down
17 changes: 8 additions & 9 deletions net/can/can_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,20 @@ ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
netdev_txnotify_dev(dev, CAN_POLL);

/* Wait for the send to complete or an error to occur.
* net_sem_timedwait will also terminate if a signal is received.
* conn_dev_sem_timedwait will also terminate if a signal is received.
*/

conn_dev_unlock(&conn->sconn, dev);
if (_SS_ISNONBLOCK(conn->sconn.s_flags) || (flags & MSG_DONTWAIT) != 0)
{
ret = net_sem_timedwait(&state.snd_sem, 0);
ret = conn_dev_sem_timedwait(&state.snd_sem, true, 0,
&conn->sconn, dev);
}
else
{
ret = net_sem_timedwait(&state.snd_sem, UINT_MAX);
ret = conn_dev_sem_timedwait(&state.snd_sem, true, UINT_MAX,
&conn->sconn, dev);
}

conn_dev_lock(&conn->sconn, dev);

/* Make sure that no further events are processed */

can_callback_free(dev, conn, state.snd_cb);
Expand All @@ -296,9 +295,9 @@ ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
return state.snd_sent;
}

/* If net_sem_wait failed, then we were probably reawakened by a signal.
* In this case, net_sem_wait will have returned negated errno
* appropriately.
/* If conn_dev_sem_timedwait failed, then we were probably reawakened by
* a signal. In this case, conn_dev_sem_timedwait will have returned
* negated errno appropriately.
*/

if (ret < 0)
Expand Down
Loading
Loading