diff --git a/core/include/thread.h b/core/include/thread.h index c8a5161a2b6049890be3a046c5183e085b3b41e6..5d5ebaa558c3b730089b9fe2326695aa1ec390e6 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -528,6 +528,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 diff --git a/core/msg.c b/core/msg.c index 2afc1def316e96b5c606973e07e711eb35e21f9d..2cef88571adb2fe0b634a14b1af0f5b6696eeeb7 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)); } diff --git a/sys/net/gnrc/netreg/gnrc_netreg.c b/sys/net/gnrc/netreg/gnrc_netreg.c index df0450468b096d069119086254c99efe322acd34..540a321ac35784ec787e336cd3241c50c6834b03 100644 --- a/sys/net/gnrc/netreg/gnrc_netreg.c +++ b/sys/net/gnrc/netreg/gnrc_netreg.c @@ -39,13 +39,13 @@ 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 + thread_has_msg_queue(sched_threads[entry->target.pid]); +# else + 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 */ if (!has_msg_q) { @@ -53,7 +53,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; diff --git a/tests/gnrc_netif/main.c b/tests/gnrc_netif/main.c index 4a0d3b0d3fb493da58970aefc9f32f46385f6261..25fbb82944c16b41af407049144c6943223a18f3 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)));