Browse Source

ring_buffer: constify some arguments

Functions that don't modify content should have pointers to it marked
const.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
pull/86911/head
Nicolas Pitre 4 months ago committed by Benjamin Cabé
parent
commit
c7467f0c65
  1. 10
      include/zephyr/sys/ring_buffer.h
  2. 6
      subsys/net/lib/lwm2m/lwm2m_registry.c

10
include/zephyr/sys/ring_buffer.h

@ -209,7 +209,7 @@ static inline void ring_buf_item_init(struct ring_buf *buf, @@ -209,7 +209,7 @@ static inline void ring_buf_item_init(struct ring_buf *buf,
*
* @return true if the ring buffer is empty, or false if not.
*/
static inline bool ring_buf_is_empty(struct ring_buf *buf)
static inline bool ring_buf_is_empty(const struct ring_buf *buf)
{
return buf->get.head == buf->put.tail;
}
@ -231,7 +231,7 @@ static inline void ring_buf_reset(struct ring_buf *buf) @@ -231,7 +231,7 @@ static inline void ring_buf_reset(struct ring_buf *buf)
*
* @return Ring buffer free space (in bytes).
*/
static inline uint32_t ring_buf_space_get(struct ring_buf *buf)
static inline uint32_t ring_buf_space_get(const struct ring_buf *buf)
{
ring_buf_idx_t allocated = buf->put.head - buf->get.tail;
@ -245,7 +245,7 @@ static inline uint32_t ring_buf_space_get(struct ring_buf *buf) @@ -245,7 +245,7 @@ static inline uint32_t ring_buf_space_get(struct ring_buf *buf)
*
* @return Ring buffer free space (in 32-bit words).
*/
static inline uint32_t ring_buf_item_space_get(struct ring_buf *buf)
static inline uint32_t ring_buf_item_space_get(const struct ring_buf *buf)
{
return ring_buf_space_get(buf) / 4;
}
@ -257,7 +257,7 @@ static inline uint32_t ring_buf_item_space_get(struct ring_buf *buf) @@ -257,7 +257,7 @@ static inline uint32_t ring_buf_item_space_get(struct ring_buf *buf)
*
* @return Ring buffer capacity (in bytes).
*/
static inline uint32_t ring_buf_capacity_get(struct ring_buf *buf)
static inline uint32_t ring_buf_capacity_get(const struct ring_buf *buf)
{
return buf->size;
}
@ -269,7 +269,7 @@ static inline uint32_t ring_buf_capacity_get(struct ring_buf *buf) @@ -269,7 +269,7 @@ static inline uint32_t ring_buf_capacity_get(struct ring_buf *buf)
*
* @return Ring buffer data size (in bytes).
*/
static inline uint32_t ring_buf_size_get(struct ring_buf *buf)
static inline uint32_t ring_buf_size_get(const struct ring_buf *buf)
{
ring_buf_idx_t available = buf->put.tail - buf->get.head;

6
subsys/net/lib/lwm2m/lwm2m_registry.c

@ -1723,13 +1723,11 @@ size_t lwm2m_cache_size(const struct lwm2m_time_series_resource *cache_entry) @@ -1723,13 +1723,11 @@ size_t lwm2m_cache_size(const struct lwm2m_time_series_resource *cache_entry)
#if defined(CONFIG_LWM2M_RESOURCE_DATA_CACHE_SUPPORT)
uint32_t bytes_available;
/* ring_buf_is_empty() takes non-const pointer but still does not modify */
if (ring_buf_is_empty((struct ring_buf *) &cache_entry->rb)) {
if (ring_buf_is_empty(&cache_entry->rb)) {
return 0;
}
/* ring_buf_size_get() takes non-const pointer but still does not modify */
bytes_available = ring_buf_size_get((struct ring_buf *) &cache_entry->rb);
bytes_available = ring_buf_size_get(&cache_entry->rb);
return (bytes_available / sizeof(struct lwm2m_time_series_elem));
#else

Loading…
Cancel
Save