mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-16 21:28:33 +03:00
usb_buf: count number of elements in queue
This is in preparation for limiting the maximum queue length Change-Id: I7cb184d7a1ccb519010a2f3e3295cc3a5fbf8052 Related: OS#4251
This commit is contained in:
@@ -80,6 +80,49 @@ extern int msgb_resize_area(struct msgb *msg, uint8_t *area,
|
||||
extern struct msgb *msgb_copy(const struct msgb *msg, const char *name);
|
||||
static int msgb_test_invariant(const struct msgb *msg) __attribute__((pure));
|
||||
|
||||
/*! Free all msgbs from a queue built with msgb_enqueue().
|
||||
* \param[in] queue list head of a msgb queue.
|
||||
*/
|
||||
static inline void msgb_queue_free(struct llist_head *queue)
|
||||
{
|
||||
struct msgb *msg;
|
||||
while ((msg = msgb_dequeue(queue))) msgb_free(msg);
|
||||
}
|
||||
|
||||
/*! Enqueue message buffer to tail of a queue and increment queue size counter
|
||||
* \param[in] queue linked list header of queue
|
||||
* \param[in] msg message buffer to be added to the queue
|
||||
* \param[in] count pointer to variable holding size of the queue
|
||||
*
|
||||
* The function will append the specified message buffer \a msg to the queue
|
||||
* implemented by \ref llist_head \a queue using function \ref msgb_enqueue_count,
|
||||
* then increment \a count
|
||||
*/
|
||||
static inline void msgb_enqueue_count(struct llist_head *queue, struct msgb *msg,
|
||||
unsigned int *count)
|
||||
{
|
||||
msgb_enqueue(queue, msg);
|
||||
(*count)++;
|
||||
}
|
||||
|
||||
/*! Dequeue message buffer from head of queue and decrement queue size counter
|
||||
* \param[in] queue linked list header of queue
|
||||
* \param[in] count pointer to variable holding size of the queue
|
||||
* \returns message buffer (if any) or NULL if queue empty
|
||||
*
|
||||
* The function will remove the first message buffer from the queue
|
||||
* implemented by \ref llist_head \a queue using function \ref msgb_enqueue_count,
|
||||
* and decrement \a count, all if queue is not empty.
|
||||
*/
|
||||
static inline struct msgb *msgb_dequeue_count(struct llist_head *queue,
|
||||
unsigned int *count)
|
||||
{
|
||||
struct msgb *msg = msgb_dequeue(queue);
|
||||
if (msg)
|
||||
(*count)--;
|
||||
return msg;
|
||||
}
|
||||
|
||||
#ifdef MSGB_DEBUG
|
||||
#include <osmocom/core/panic.h>
|
||||
#define MSGB_ABORT(msg, fmt, args ...) do { \
|
||||
|
||||
Reference in New Issue
Block a user