net/can: replace the common connect prologue

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2022-02-07 11:55:18 +08:00 committed by Alan Carvalho de Assis
parent 8366c87c5b
commit 43ca28da36
3 changed files with 11 additions and 18 deletions

View File

@ -33,6 +33,7 @@
#include <netpacket/can.h>
#include <nuttx/semaphore.h>
#include <nuttx/can.h>
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
#include "devif/devif.h"
@ -51,9 +52,9 @@
/* Allocate a new packet socket data callback */
#define can_callback_alloc(dev,conn) \
devif_callback_alloc(dev, &conn->list, &conn->list_tail)
devif_callback_alloc(dev, &conn->sconn.list, &conn->sconn.list_tail)
#define can_callback_free(dev,conn,cb) \
devif_conn_callback_free(dev, cb, &conn->list, &conn->list_tail)
devif_conn_callback_free(dev, cb, &conn->sconn.list, &conn->sconn.list_tail)
/****************************************************************************
* Public Type Definitions
@ -75,15 +76,7 @@ struct can_conn_s
{
/* Common prologue of all connection structures. */
dq_entry_t node; /* Supports a doubly linked list */
/* This is a list of NetLink connection callbacks. Each callback
* represents a thread that is stalled, waiting for a device-specific
* event.
*/
FAR struct devif_callback_s *list; /* NetLink callbacks */
FAR struct devif_callback_s *list_tail; /* NetLink callbacks */
struct socket_conn_s sconn;
FAR struct net_driver_s *dev; /* Reference to CAN device */

View File

@ -139,7 +139,7 @@ uint16_t can_callback(FAR struct net_driver_s *dev,
if (net_trylock() == OK)
{
flags = devif_conn_event(dev, conn, flags, conn->list);
flags = devif_conn_event(dev, conn, flags, conn->sconn.list);
net_unlock();
}

View File

@ -114,7 +114,7 @@ void can_initialize(void)
{
/* Mark the connection closed and move it to the free list */
dq_addlast(&g_can_connections[i].node, &g_free_can_connections);
dq_addlast(&g_can_connections[i].sconn.node, &g_free_can_connections);
}
#endif
}
@ -146,7 +146,7 @@ FAR struct can_conn_s *can_alloc(void)
{
for (i = 0; i < CONFIG_CAN_CONNS; i++)
{
dq_addlast(&conn[i].node, &g_free_can_connections);
dq_addlast(&conn[i].sconn.node, &g_free_can_connections);
}
}
}
@ -175,7 +175,7 @@ FAR struct can_conn_s *can_alloc(void)
/* Enqueue the connection into the active list */
dq_addlast(&conn->node, &g_active_can_connections);
dq_addlast(&conn->sconn.node, &g_active_can_connections);
}
_can_semgive(&g_free_sem);
@ -201,7 +201,7 @@ void can_free(FAR struct can_conn_s *conn)
/* Remove the connection from the active list */
dq_rem(&conn->node, &g_active_can_connections);
dq_rem(&conn->sconn.node, &g_active_can_connections);
/* Reset structure */
@ -209,7 +209,7 @@ void can_free(FAR struct can_conn_s *conn)
/* Free the connection */
dq_addlast(&conn->node, &g_free_can_connections);
dq_addlast(&conn->sconn.node, &g_free_can_connections);
_can_semgive(&g_free_sem);
}
@ -232,7 +232,7 @@ FAR struct can_conn_s *can_nextconn(FAR struct can_conn_s *conn)
}
else
{
return (FAR struct can_conn_s *)conn->node.flink;
return (FAR struct can_conn_s *)conn->sconn.node.flink;
}
}