queue: make data pointers const in queue_try_add and queue_add_blocking (#423)

The only operation done on the data pointer is to pass it into the second
argument of memcpy, which is `const void *`
This commit is contained in:
Jonathan Reichelt Gjertsen 2021-05-24 23:52:49 +02:00 committed by GitHub
parent cc8b2156fb
commit b8dc054eba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -163,7 +163,7 @@ static inline bool queue_is_full(queue_t *q) {
* If the queue is full this function will return immediately with false, otherwise * If the queue is full this function will return immediately with false, otherwise
* the data is copied into a new value added to the queue, and this function will return true. * the data is copied into a new value added to the queue, and this function will return true.
*/ */
bool queue_try_add(queue_t *q, void *data); bool queue_try_add(queue_t *q, const void *data);
/*! \brief Non-blocking removal of entry from the queue if non empty /*! \brief Non-blocking removal of entry from the queue if non empty
* \ingroup queue * \ingroup queue
@ -199,7 +199,7 @@ bool queue_try_peek(queue_t *q, void *data);
* *
* If the queue is full this function will block, until a removal happens on the queue * If the queue is full this function will block, until a removal happens on the queue
*/ */
void queue_add_blocking(queue_t *q, void *data); void queue_add_blocking(queue_t *q, const void *data);
/*! \brief Blocking remove entry from queue /*! \brief Blocking remove entry from queue
* \ingroup queue * \ingroup queue

View File

@ -41,7 +41,7 @@ static inline uint16_t inc_index(queue_t *q, uint16_t index) {
return index; return index;
} }
static bool queue_add_internal(queue_t *q, void *data, bool block) { static bool queue_add_internal(queue_t *q, const void *data, bool block) {
do { do {
uint32_t save = spin_lock_blocking(q->core.spin_lock); uint32_t save = spin_lock_blocking(q->core.spin_lock);
if (queue_get_level_unsafe(q) != q->element_count) { if (queue_get_level_unsafe(q) != q->element_count) {
@ -94,7 +94,7 @@ static bool queue_peek_internal(queue_t *q, void *data, bool block) {
} while (true); } while (true);
} }
bool queue_try_add(queue_t *q, void *data) { bool queue_try_add(queue_t *q, const void *data) {
return queue_add_internal(q, data, false); return queue_add_internal(q, data, false);
} }
@ -106,7 +106,7 @@ bool queue_try_peek(queue_t *q, void *data) {
return queue_peek_internal(q, data, false); return queue_peek_internal(q, data, false);
} }
void queue_add_blocking(queue_t *q, void *data) { void queue_add_blocking(queue_t *q, const void *data) {
queue_add_internal(q, data, true); queue_add_internal(q, data, true);
} }