Skip to content

Commit

Permalink
fixup! core/msg: re-enable IRQs before printing for highlevel_stdio
Browse files Browse the repository at this point in the history
  • Loading branch information
mguetschow committed Nov 26, 2024
1 parent cdacdab commit 8094eb7
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions core/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string.h>
#include <inttypes.h>
#include <assert.h>
#include "macros/utils.h"
#include "sched.h"
#include "msg.h"
#include "msg_bus.h"
Expand Down Expand Up @@ -491,6 +492,8 @@ void msg_init_queue(msg_t *array, int num)
cib_init(&(me->msg_queue), num);
}

#define MSG_QUEUE_PRINT_MAX 16U

void msg_queue_print(void)
{
unsigned state = irq_disable();
Expand All @@ -509,20 +512,25 @@ void msg_queue_print(void)

/* copy message queue information to stack
before re-enabling IRQs (needed for highlevel_stdio) */
int mask = msg_queue->mask;
int size = mask + 1;
unsigned int size = msg_queue->mask + 1;
unsigned int max = MIN(size, MSG_QUEUE_PRINT_MAX);
unsigned int mask = max - 1;
int first_msg = cib_peek(msg_queue);
msg_t msg_array[size];
memcpy(msg_array, thread->msg_array, size);

static msg_t msg_array[MSG_QUEUE_PRINT_MAX];
memcpy(msg_array, thread->msg_array, sizeof(msg_t)*max);
irq_restore(state);

printf("Message queue of thread %" PRIkernel_pid "\n", thread->pid);

Check warning on line 524 in core/msg.c

View workflow job for this annotation

GitHub Actions / static-tests

Uncrustify proposes the following patch: --- a/core/msg.c +++ b/core/msg.c @@ -518,7 +518,7 @@ void msg_queue_print(void) int first_msg = cib_peek(msg_queue); static msg_t msg_array[MSG_QUEUE_PRINT_MAX]; - memcpy(msg_array, thread->msg_array, sizeof(msg_t)*max); + memcpy(msg_array, thread->msg_array, sizeof(msg_t) * max); irq_restore(state); printf("Message queue of thread %" PRIkernel_pid "\n", thread->pid);
printf(" size: %u (avail: %u)\n", size, msg_counter);

for (unsigned i = 0; i < msg_counter; i++) {
for (unsigned i = 0; i < MIN(msg_counter, max); i++) {
msg_t *m = &msg_array[(first_msg + i) & mask];
printf(" * %u: sender: %" PRIkernel_pid ", type: 0x%04" PRIu16
", content: %" PRIu32 " (%p)\n", i, m->sender_pid, m->type,
m->content.value, m->content.ptr);
}
if (msg_counter > max) {
printf(" ...\n");
}
}

0 comments on commit 8094eb7

Please sign in to comment.