diff --git a/Makefile.defaultmodules b/Makefile.defaultmodules index abb36fa10..9d8331407 100644 --- a/Makefile.defaultmodules +++ b/Makefile.defaultmodules @@ -1,3 +1,3 @@ -DEFAULT_MODULE += board cpu core sys +DEFAULT_MODULE += board cpu core core_msg sys DEFAULT_MODULE += auto_init diff --git a/Makefile.pseudomodules b/Makefile.pseudomodules index 875c570de..89695ca56 100644 --- a/Makefile.pseudomodules +++ b/Makefile.pseudomodules @@ -2,6 +2,7 @@ PSEUDOMODULES += conn PSEUDOMODULES += conn_ip PSEUDOMODULES += conn_tcp PSEUDOMODULES += conn_udp +PSEUDOMODULES += core_msg PSEUDOMODULES += core_thread_flags PSEUDOMODULES += gnrc_netdev_default PSEUDOMODULES += gnrc_ipv6_default diff --git a/core/include/msg.h b/core/include/msg.h index 274b0f427..2dfa74970 100644 --- a/core/include/msg.h +++ b/core/include/msg.h @@ -375,6 +375,11 @@ int msg_avail(void); */ int msg_init_queue(msg_t *array, int num); +/** + * @brief Prints the message queue of the current thread. + */ +void msg_queue_print(void); + #ifdef __cplusplus } #endif diff --git a/core/include/thread.h b/core/include/thread.h index c59ea9c90..7588a2748 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -85,11 +85,14 @@ struct _thread { clist_node_t rq_entry; /**< run queue entry */ - void *wait_data; /**< holding messages */ +#if defined(MODULE_CORE_MSG) || defined(MODULE_CORE_THREAD_FLAGS) + void *wait_data; /**< used by msg and thread flags */ +#endif +#if defined(MODULE_CORE_MSG) priority_queue_t msg_waiters; /**< threads waiting on message */ - cib_t msg_queue; /**< message queue */ msg_t *msg_array; /**< memory holding messages */ +#endif #if defined DEVELHELP || defined(SCHED_TEST_STACK) char *stack_start; /**< thread's stack start address */ @@ -321,11 +324,6 @@ static inline kernel_pid_t thread_getpid(void) */ char *thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_start, int stack_size); -/** - * @brief Prints the message queue of the current thread. - */ -void thread_print_msg_queue(void); - /** * @brief Add thread to list, sorted by priority (internal) * diff --git a/core/msg.c b/core/msg.c index 5629bd441..c47c3ee5c 100644 --- a/core/msg.c +++ b/core/msg.c @@ -34,6 +34,8 @@ #include "debug.h" #include "thread.h" +#ifdef MODULE_CORE_MSG + static int _msg_receive(msg_t *m, int block); static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned state); @@ -389,3 +391,29 @@ int msg_init_queue(msg_t *array, int num) return -1; } + +void msg_queue_print(void) +{ + unsigned state = irq_disable(); + + thread_t *thread =(thread_t *)sched_active_thread; + cib_t *msg_queue = &thread->msg_queue; + msg_t *msg_array = thread->msg_array; + unsigned int i = msg_queue->read_count & msg_queue->mask; + + printf("Message queue of thread %" PRIkernel_pid "\n", thread->pid); + printf(" size: %u (avail: %d)\n", msg_queue->mask + 1, + cib_avail((cib_t *)msg_queue)); + + for (; i != (msg_queue->write_count & msg_queue->mask); + i = (i + 1) & msg_queue->mask) { + msg_t *m = &msg_array[i]; + printf(" * %u: sender: %" PRIkernel_pid ", type: 0x%04" PRIu16 + ", content: %" PRIu32 " (%p)\n", i, m->sender_pid, m->type, + m->content.value, (void *)m->content.ptr); + } + + irq_restore(state); +} + +#endif /* MODULE_CORE_MSG */ diff --git a/core/thread.c b/core/thread.c index 1cac0574b..6bcb2648c 100644 --- a/core/thread.c +++ b/core/thread.c @@ -225,12 +225,12 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags, cb->rq_entry.next = NULL; +#ifdef MODULE_CORE_MSG cb->wait_data = NULL; - cb->msg_waiters.first = NULL; - cib_init(&(cb->msg_queue), 0); cb->msg_array = NULL; +#endif sched_num_threads++; diff --git a/core/thread_print_msg_queue.c b/core/thread_print_msg_queue.c deleted file mode 100644 index 575c83ea1..000000000 --- a/core/thread_print_msg_queue.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2015 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @{ - * - * @file - * @author Martine Lenders - */ - -#include - -#include "sched.h" -#include "thread.h" - -void thread_print_msg_queue(void) -{ - volatile thread_t *thread = sched_active_thread; - volatile cib_t *msg_queue = &thread->msg_queue; - msg_t *msg_array = thread->msg_array; - unsigned int i = msg_queue->read_count & msg_queue->mask; - - printf("Message queue of thread %" PRIkernel_pid "\n", thread->pid); - printf(" size: %u (avail: %d)\n", msg_queue->mask + 1, - cib_avail((cib_t *)msg_queue)); - - for (; i != (msg_queue->write_count & msg_queue->mask); - i = (i + 1) & msg_queue->mask) { - msg_t *m = &msg_array[i]; - printf(" * %u: sender: %" PRIkernel_pid ", type: 0x%04" PRIu16 - ", content: %" PRIu32 " (%p)\n", i, m->sender_pid, m->type, - m->content.value, (void *)m->content.ptr); - } -} - -/** @} */ diff --git a/dist/Makefile b/dist/Makefile index 3c35bff32..c41b0b98d 100644 --- a/dist/Makefile +++ b/dist/Makefile @@ -36,6 +36,11 @@ QUIET ?= 1 #USEMODULE += posix #USEMODULE += xtimer +# If your application is very simple and doesn't use modules that use +# messaging, it can be disabled to save some memory: + +#DISABLE_MODULE += core_msg + #export INCLUDES += -Iapplication_include # Specify custom dependencies for your application here ... diff --git a/tests/sizeof_tcb/Makefile b/tests/sizeof_tcb/Makefile index c7ead79a8..c9a38e071 100644 --- a/tests/sizeof_tcb/Makefile +++ b/tests/sizeof_tcb/Makefile @@ -1,7 +1,12 @@ APPLICATION = sizeof_tcb include ../Makefile.tests_common -# optional thread_t modifying modules: +# othread_t modifying modules: +# +# disabled by default: # USEMODULE += core_thread_flags +# +# enabled by defaule: +# DISABLE_MODULE += core_msg include $(RIOTBASE)/Makefile.include diff --git a/tests/sizeof_tcb/main.c b/tests/sizeof_tcb/main.c index 2be898ecd..33eb85cd8 100644 --- a/tests/sizeof_tcb/main.c +++ b/tests/sizeof_tcb/main.c @@ -39,10 +39,12 @@ int main(void) P(flags); #endif P(rq_entry); +#ifdef MODULE_CORE_MSG P(wait_data); P(msg_waiters); P(msg_queue); P(msg_array); +#endif #ifdef DEVELHELP P(name); #endif