From 7835db5ec308d7471ebb95ccef7f74f196deee79 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 15 Nov 2018 13:53:27 +0100 Subject: [PATCH 1/5] core: provide function to check msg queue initialization This makes it easier to refactor that part of the `thread_t` structure later on. --- core/include/thread.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/include/thread.h b/core/include/thread.h index 3a13e379c8..02aa5405dc 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -527,6 +527,26 @@ void thread_stack_print(void); */ void thread_print_stack(void); +/** + * @brief Checks if a thread has an initialized message queue + * + * @see @ref msg_init_queue() + * + * @param[in] thread The thread to check for + * + * @return `== 0`, if @p thread has no initialized message queue + * @return `!= 0`, if @p thread has its message queue initialized + */ +static inline int thread_has_msg_queue(const volatile struct _thread *thread) +{ +#if defined(MODULE_CORE_MSG) || defined(DOXYGEN) + return (thread->msg_array != NULL); +#else + (void)thread; + return 0; +#endif +} + #ifdef __cplusplus } #endif From c8937f8d401114ac4a0ff1e8d8a64df6b661f0f7 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 15 Nov 2018 14:04:28 +0100 Subject: [PATCH 2/5] core: use thread_has_msg_queue() for message queue check --- core/msg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/msg.c b/core/msg.c index 2afc1def31..2cef88571a 100644 --- a/core/msg.c +++ b/core/msg.c @@ -296,7 +296,7 @@ static int _msg_receive(msg_t *m, int block) int queue_index = -1; - if (me->msg_array) { + if (thread_has_msg_queue(me)) { queue_index = cib_get(&(me->msg_queue)); } @@ -381,7 +381,7 @@ int msg_avail(void) int queue_index = -1; - if (me->msg_array) { + if (thread_has_msg_queue(me)) { queue_index = cib_avail(&(me->msg_queue)); } From 986b9d380bb2cf1da0004c287afea85a89b2d3ca Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 15 Nov 2018 14:06:57 +0100 Subject: [PATCH 3/5] gnrc_netreg: make message queue check more readable --- sys/net/gnrc/netreg/gnrc_netreg.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sys/net/gnrc/netreg/gnrc_netreg.c b/sys/net/gnrc/netreg/gnrc_netreg.c index df0450468b..2361d4c075 100644 --- a/sys/net/gnrc/netreg/gnrc_netreg.c +++ b/sys/net/gnrc/netreg/gnrc_netreg.c @@ -39,13 +39,14 @@ void gnrc_netreg_init(void) int gnrc_netreg_register(gnrc_nettype_t type, gnrc_netreg_entry_t *entry) { -#ifdef DEVELHELP -#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS) +#if DEVELHELP + +# if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS) bool has_msg_q = (entry->type != GNRC_NETREG_TYPE_DEFAULT) || - sched_threads[entry->target.pid]->msg_array; -#else - bool has_msg_q = sched_threads[entry->target.pid]->msg_array; -#endif + (sched_threads[entry->target.pid]->msg_array != NULL); +# else + bool has_msg_q = (sched_threads[entry->target.pid]->msg_array != NULL); +# endif /* only threads with a message queue are allowed to register at gnrc */ if (!has_msg_q) { @@ -53,7 +54,7 @@ int gnrc_netreg_register(gnrc_nettype_t type, gnrc_netreg_entry_t *entry) "using msg_init_queue() !!!!\n\n", entry->target.pid); } assert(has_msg_q); -#endif +#endif /* DEVELHELP */ if (_INVALID_TYPE(type)) { return -EINVAL; From a14e33df0136bd4352c8e63ed986c5f8de7aeb5d Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 15 Nov 2018 14:07:15 +0100 Subject: [PATCH 4/5] gnrc_netreg: use thread_has_msg_queue() for msg queue check --- sys/net/gnrc/netreg/gnrc_netreg.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sys/net/gnrc/netreg/gnrc_netreg.c b/sys/net/gnrc/netreg/gnrc_netreg.c index 2361d4c075..540a321ac3 100644 --- a/sys/net/gnrc/netreg/gnrc_netreg.c +++ b/sys/net/gnrc/netreg/gnrc_netreg.c @@ -40,12 +40,11 @@ void gnrc_netreg_init(void) int gnrc_netreg_register(gnrc_nettype_t type, gnrc_netreg_entry_t *entry) { #if DEVELHELP - # if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS) bool has_msg_q = (entry->type != GNRC_NETREG_TYPE_DEFAULT) || - (sched_threads[entry->target.pid]->msg_array != NULL); + thread_has_msg_queue(sched_threads[entry->target.pid]); # else - bool has_msg_q = (sched_threads[entry->target.pid]->msg_array != NULL); + bool has_msg_q = thread_has_msg_queue(sched_threads[entry->target.pid]); # endif /* only threads with a message queue are allowed to register at gnrc */ From 91b526b0ad62038ee26d8c82ec6724b018158e4d Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 15 Nov 2018 14:11:16 +0100 Subject: [PATCH 5/5] tests/gnrc_netif: use thread_has_msg_queue() for msg queue check --- tests/gnrc_netif/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/gnrc_netif/main.c b/tests/gnrc_netif/main.c index 4a0d3b0d3f..25fbb82944 100644 --- a/tests/gnrc_netif/main.c +++ b/tests/gnrc_netif/main.c @@ -131,7 +131,7 @@ static void test_creation(void) #ifdef DEVELHELP TEST_ASSERT_EQUAL_STRING("eth", sched_threads[ethernet_netif->pid]->name); #endif - TEST_ASSERT_NOT_NULL(sched_threads[ethernet_netif->pid]->msg_array); + TEST_ASSERT(thread_has_msg_queue(sched_threads[ethernet_netif->pid])); TEST_ASSERT_NOT_NULL((ieee802154_netif = gnrc_netif_ieee802154_create( ieee802154_netif_stack, IEEE802154_STACKSIZE, GNRC_NETIF_PRIO, @@ -153,7 +153,7 @@ static void test_creation(void) #ifdef DEVELHELP TEST_ASSERT_EQUAL_STRING("wpan", sched_threads[ieee802154_netif->pid]->name); #endif - TEST_ASSERT_NOT_NULL(sched_threads[ieee802154_netif->pid]->msg_array); + TEST_ASSERT(thread_has_msg_queue(sched_threads[ieee802154_netif->pid])); for (unsigned i = 0; i < DEFAULT_DEVS_NUMOF; i++) { TEST_ASSERT_NOT_NULL((netifs[i] = gnrc_netif_create( @@ -165,7 +165,7 @@ static void test_creation(void) TEST_ASSERT_EQUAL_INT(GNRC_NETIF_DEFAULT_HL, netifs[i]->cur_hl); TEST_ASSERT_EQUAL_INT(NETDEV_TYPE_UNKNOWN, netifs[i]->device_type); TEST_ASSERT(netifs[i]->pid > KERNEL_PID_UNDEF); - TEST_ASSERT_NOT_NULL(sched_threads[netifs[i]->pid]->msg_array); + TEST_ASSERT(thread_has_msg_queue(sched_threads[netifs[i]->pid])); TEST_ASSERT_EQUAL_INT(i + SPECIAL_DEVS + 1, gnrc_netif_numof()); for (unsigned j = 0; j < (i + SPECIAL_DEVS + 1); j++) { TEST_ASSERT_NOT_NULL((ptr = gnrc_netif_iter(ptr)));