Skip to content

Commit 58a12e5

Browse files
committed
core: make messaging optional
1 parent 5f81284 commit 58a12e5

10 files changed

+55
-52
lines changed

Makefile.defaultmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
DEFAULT_MODULE += board cpu core sys
1+
DEFAULT_MODULE += board cpu core core_msg sys
22

33
DEFAULT_MODULE += auto_init

Makefile.pseudomodules

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ PSEUDOMODULES += conn
22
PSEUDOMODULES += conn_ip
33
PSEUDOMODULES += conn_tcp
44
PSEUDOMODULES += conn_udp
5+
PSEUDOMODULES += core_msg
56
PSEUDOMODULES += core_thread_flags
67
PSEUDOMODULES += gnrc_netdev_default
78
PSEUDOMODULES += gnrc_ipv6_default

core/include/msg.h

+5
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ int msg_avail(void);
375375
*/
376376
int msg_init_queue(msg_t *array, int num);
377377

378+
/**
379+
* @brief Prints the message queue of the current thread.
380+
*/
381+
void msg_queue_print(void);
382+
378383
#ifdef __cplusplus
379384
}
380385
#endif

core/include/thread.h

+5-7
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,14 @@ struct _thread {
8585

8686
clist_node_t rq_entry; /**< run queue entry */
8787

88-
void *wait_data; /**< holding messages */
88+
#if defined(MODULE_CORE_MSG) || defined(MODULE_CORE_THREAD_FLAGS)
89+
void *wait_data; /**< used by msg and thread flags */
90+
#endif
91+
#if defined(MODULE_CORE_MSG)
8992
priority_queue_t msg_waiters; /**< threads waiting on message */
90-
9193
cib_t msg_queue; /**< message queue */
9294
msg_t *msg_array; /**< memory holding messages */
95+
#endif
9396

9497
#if defined DEVELHELP || defined(SCHED_TEST_STACK)
9598
char *stack_start; /**< thread's stack start address */
@@ -321,11 +324,6 @@ static inline kernel_pid_t thread_getpid(void)
321324
*/
322325
char *thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_start, int stack_size);
323326

324-
/**
325-
* @brief Prints the message queue of the current thread.
326-
*/
327-
void thread_print_msg_queue(void);
328-
329327
/**
330328
* @brief Add thread to list, sorted by priority (internal)
331329
*

core/msg.c

+28
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include "debug.h"
3535
#include "thread.h"
3636

37+
#ifdef MODULE_CORE_MSG
38+
3739
static int _msg_receive(msg_t *m, int block);
3840
static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned state);
3941

@@ -389,3 +391,29 @@ int msg_init_queue(msg_t *array, int num)
389391

390392
return -1;
391393
}
394+
395+
void msg_queue_print(void)
396+
{
397+
unsigned state = irq_disable();
398+
399+
thread_t *thread =(thread_t *)sched_active_thread;
400+
cib_t *msg_queue = &thread->msg_queue;
401+
msg_t *msg_array = thread->msg_array;
402+
unsigned int i = msg_queue->read_count & msg_queue->mask;
403+
404+
printf("Message queue of thread %" PRIkernel_pid "\n", thread->pid);
405+
printf(" size: %u (avail: %d)\n", msg_queue->mask + 1,
406+
cib_avail((cib_t *)msg_queue));
407+
408+
for (; i != (msg_queue->write_count & msg_queue->mask);
409+
i = (i + 1) & msg_queue->mask) {
410+
msg_t *m = &msg_array[i];
411+
printf(" * %u: sender: %" PRIkernel_pid ", type: 0x%04" PRIu16
412+
", content: %" PRIu32 " (%p)\n", i, m->sender_pid, m->type,
413+
m->content.value, (void *)m->content.ptr);
414+
}
415+
416+
irq_restore(state);
417+
}
418+
419+
#endif /* MODULE_CORE_MSG */

core/thread.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
225225

226226
cb->rq_entry.next = NULL;
227227

228+
#ifdef MODULE_CORE_MSG
228229
cb->wait_data = NULL;
229-
230230
cb->msg_waiters.first = NULL;
231-
232231
cib_init(&(cb->msg_queue), 0);
233232
cb->msg_array = NULL;
233+
#endif
234234

235235
sched_num_threads++;
236236

core/thread_print_msg_queue.c

-41
This file was deleted.

dist/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ QUIET ?= 1
3636
#USEMODULE += posix
3737
#USEMODULE += xtimer
3838

39+
# If your application is very simple and doesn't use modules that use
40+
# messaging, it can be disabled to save some memory:
41+
42+
#DISABLE_MODULE += core_msg
43+
3944
#export INCLUDES += -Iapplication_include
4045

4146
# Specify custom dependencies for your application here ...

tests/sizeof_tcb/Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
APPLICATION = sizeof_tcb
22
include ../Makefile.tests_common
33

4-
# optional thread_t modifying modules:
4+
# othread_t modifying modules:
5+
#
6+
# disabled by default:
57
# USEMODULE += core_thread_flags
8+
#
9+
# enabled by defaule:
10+
# DISABLE_MODULE += core_msg
611

712
include $(RIOTBASE)/Makefile.include

tests/sizeof_tcb/main.c

+2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ int main(void)
3939
P(flags);
4040
#endif
4141
P(rq_entry);
42+
#ifdef MODULE_CORE_MSG
4243
P(wait_data);
4344
P(msg_waiters);
4445
P(msg_queue);
4546
P(msg_array);
47+
#endif
4648
#ifdef DEVELHELP
4749
P(name);
4850
#endif

0 commit comments

Comments
 (0)