mirror of
https://github.com/apache/nuttx.git
synced 2026-05-29 20:56:47 +08:00
PF_IEEE802154: Improve some backlog counting logic; add more assertions to catch cases where the backlog count might deviate from the actual backlog.
This commit is contained in:
@@ -69,8 +69,8 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_ASSERTIONS
|
#if defined(CONFIG_DEBUG_ASSERTIONS) && CONFIG_NET_IEEE802154_BACKLOG > 0
|
||||||
int ieee802154_count_frames(FAR struct ieee802154_conn_s *conn)
|
static int ieee802154_count_frames(FAR struct ieee802154_conn_s *conn)
|
||||||
{
|
{
|
||||||
FAR struct ieee802154_container_s *container;
|
FAR struct ieee802154_container_s *container;
|
||||||
int count;
|
int count;
|
||||||
@@ -102,9 +102,9 @@ int ieee802154_count_frames(FAR struct ieee802154_conn_s *conn)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int ieee802154_queue_frame(FAR struct ieee802154_conn_s *conn,
|
static int ieee802154_queue_frame(FAR struct ieee802154_conn_s *conn,
|
||||||
FAR struct iob_s *frame,
|
FAR struct iob_s *frame,
|
||||||
FAR struct ieee802154_data_ind_s *meta)
|
FAR struct ieee802154_data_ind_s *meta)
|
||||||
{
|
{
|
||||||
FAR struct ieee802154_container_s *container;
|
FAR struct ieee802154_container_s *container;
|
||||||
|
|
||||||
@@ -150,16 +150,14 @@ int ieee802154_queue_frame(FAR struct ieee802154_conn_s *conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_NET_IEEE802154_BACKLOG > 0
|
#if CONFIG_NET_IEEE802154_BACKLOG > 0
|
||||||
/* Increment the count of frames in the queue. If the count exceeds the
|
/* If incrementing the count would exceed the maximum backlog value, then
|
||||||
* maximum backlog value, then delete the oldest frame from the head of
|
* delete the oldest frame from the head of the RX queue.
|
||||||
* the RX queue.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
conn->backlog++;
|
if (conn->backlog >= CONFIG_NET_IEEE802154_BACKLOG)
|
||||||
DEBUGASSERT((int)conn->backlog == ieee802154_count_frames(conn));
|
|
||||||
|
|
||||||
if (conn->backlog > CONFIG_NET_IEEE802154_BACKLOG)
|
|
||||||
{
|
{
|
||||||
|
DEBUGASSERT(conn->backlog == CONFIG_NET_IEEE802154_BACKLOG);
|
||||||
|
|
||||||
/* Remove the container from the tail RX input queue. */
|
/* Remove the container from the tail RX input queue. */
|
||||||
|
|
||||||
container = conn->rxhead;
|
container = conn->rxhead;
|
||||||
@@ -181,6 +179,14 @@ int ieee802154_queue_frame(FAR struct ieee802154_conn_s *conn,
|
|||||||
iob_free(container->ic_iob);
|
iob_free(container->ic_iob);
|
||||||
ieee802154_container_free(container);
|
ieee802154_container_free(container);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Increment the count of frames in the queue. */
|
||||||
|
|
||||||
|
conn->backlog++;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUGASSERT((int)conn->backlog == ieee802154_count_frames(conn));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
|||||||
@@ -81,6 +81,36 @@ struct ieee802154_recvfrom_s
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: ieee802154_count_frames
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Return the number of frames in the RX queue.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* conn - The socket connection structure.
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* The number of frames in the queue.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_DEBUG_ASSERTIONS) && CONFIG_NET_IEEE802154_BACKLOG > 0
|
||||||
|
static int ieee802154_count_frames(FAR struct ieee802154_conn_s *conn)
|
||||||
|
{
|
||||||
|
FAR struct ieee802154_container_s *container;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
for (count = 0, container = conn->rxhead;
|
||||||
|
container != NULL;
|
||||||
|
count++, container = container->ic_flink)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ieee802154_recvfrom_sender
|
* Name: ieee802154_recvfrom_sender
|
||||||
*
|
*
|
||||||
@@ -134,6 +164,7 @@ static ssize_t ieee802154_recvfrom_rxqueue(FAR struct radio_driver_s *radio,
|
|||||||
|
|
||||||
DEBUGASSERT(conn->backlog > 0);
|
DEBUGASSERT(conn->backlog > 0);
|
||||||
conn->backlog--;
|
conn->backlog--;
|
||||||
|
DEBUGASSERT((int)conn->backlog == ieee802154_count_frames(conn));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Extract the IOB containing the frame from the container */
|
/* Extract the IOB containing the frame from the container */
|
||||||
|
|||||||
Reference in New Issue
Block a user