Skip to content

Commit

Permalink
kernel: avoided increments/decrements with side effects
Browse files Browse the repository at this point in the history
- moved ++/-- before or after the value use

Signed-off-by: frei tycho <[email protected]>
  • Loading branch information
tychofrei02 authored and aescolar committed Jun 14, 2024
1 parent a2e9740 commit d817940
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions kernel/include/priority_q.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ static ALWAYS_INLINE void z_priq_rb_add(struct _priq_rb *pq, struct k_thread *th
{
struct k_thread *t;

thread->base.order_key = pq->next_order_key++;
thread->base.order_key = pq->next_order_key;
++pq->next_order_key;

/* Renumber at wraparound. This is tiny code, and in practice
* will almost never be hit on real systems. BUT on very
Expand All @@ -89,7 +90,8 @@ static ALWAYS_INLINE void z_priq_rb_add(struct _priq_rb *pq, struct k_thread *th
*/
if (!pq->next_order_key) {
RB_FOR_EACH_CONTAINER(&pq->tree, t, base.qnode_rb) {
t->base.order_key = pq->next_order_key++;
t->base.order_key = pq->next_order_key;
++pq->next_order_key;
}
}

Expand Down
3 changes: 2 additions & 1 deletion kernel/mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ void k_free(void *ptr)

if (ptr != NULL) {
heap_ref = ptr;
ptr = --heap_ref;
--heap_ref;
ptr = heap_ref;

SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_heap_sys, k_free, *heap_ref, heap_ref);

Expand Down

0 comments on commit d817940

Please sign in to comment.