lib: os: mpsc_pbuf: null check notify_drop callback

Allow the user of a mpsc_pbuf to not use the notify_drop callback by
setting it to NULL.

signed-off-by: Matt Campbell <matt@silvertree.io>
This commit is contained in:
Matt Campbell 2022-05-03 23:36:00 -04:00 committed by Carles Cufí
commit 2d937f0683
2 changed files with 16 additions and 5 deletions

View file

@ -103,7 +103,10 @@ struct mpsc_pbuf_buffer {
/** Lock. */
struct k_spinlock lock;
/** User callback called whenever packet is dropped. */
/** User callback called whenever packet is dropped.
*
* May be NULL if unneeded.
*/
mpsc_pbuf_notify_drop notify_drop;
/** Callback for getting packet length. */

View file

@ -224,7 +224,9 @@ void mpsc_pbuf_put_word(struct mpsc_pbuf_buffer *buffer,
if (cont && valid_drop) {
/* Notify about item being dropped. */
buffer->notify_drop(buffer, dropped_item);
if (buffer->notify_drop) {
buffer->notify_drop(buffer, dropped_item);
}
}
} while (cont);
@ -286,7 +288,9 @@ union mpsc_pbuf_generic *mpsc_pbuf_alloc(struct mpsc_pbuf_buffer *buffer,
if (cont && dropped_item && valid_drop) {
/* Notify about item being dropped. */
buffer->notify_drop(buffer, dropped_item);
if (buffer->notify_drop) {
buffer->notify_drop(buffer, dropped_item);
}
dropped_item = NULL;
}
} while (cont);
@ -359,7 +363,9 @@ void mpsc_pbuf_put_word_ext(struct mpsc_pbuf_buffer *buffer,
if (cont && dropped_item && valid_drop) {
/* Notify about item being dropped. */
buffer->notify_drop(buffer, dropped_item);
if (buffer->notify_drop) {
buffer->notify_drop(buffer, dropped_item);
}
dropped_item = NULL;
}
} while (cont);
@ -403,7 +409,9 @@ void mpsc_pbuf_put_data(struct mpsc_pbuf_buffer *buffer, const uint32_t *data,
if (cont && dropped_item && valid_drop) {
/* Notify about item being dropped. */
buffer->notify_drop(buffer, dropped_item);
if (buffer->notify_drop) {
buffer->notify_drop(buffer, dropped_item);
}
dropped_item = NULL;
}
} while (cont);