Skip to content

Commit 16c24a4

Browse files
authored
Merge pull request #21414 from maribu/core/thread/thread_msg_has_queue
core/thread: fix thread_has_msg_queue()
2 parents 69e6943 + 87ff0d5 commit 16c24a4

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

core/include/thread.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@
118118
* @author Kaspar Schleiser <[email protected]>
119119
*/
120120

121-
#include "clist.h"
121+
#include <stdbool.h>
122+
122123
#include "cib.h"
124+
#include "clist.h"
125+
#include "compiler_hints.h"
123126
#include "msg.h"
124127
#include "sched.h"
125128
#include "thread_config.h"
@@ -281,8 +284,9 @@ kernel_pid_t thread_create(char *stack,
281284
/**
282285
* @brief Retrieve a thread control block by PID.
283286
* @pre @p pid is valid
284-
* @param[in] pid Thread to retrieve.
285-
* @return `NULL` if the PID is invalid or there is no such thread.
287+
* @param[in] pid Thread to retrieve.
288+
* @return The thread identified by @p pid
289+
* @retval `NULL` no thread at the given valid PID is active.
286290
*/
287291
static inline thread_t *thread_get_unchecked(kernel_pid_t pid)
288292
{
@@ -507,11 +511,15 @@ void thread_print_stack(void);
507511
*
508512
* @param[in] thread The thread to check for
509513
*
510-
* @return `== 0`, if @p thread has no initialized message queue
511-
* @return `!= 0`, if @p thread has its message queue initialized
514+
* @pre @p thread is not `NULL` and the thread corresponding to the thread
515+
* control block @p thread points to (still) exists
516+
*
517+
* @retval false @p thread has no initialized message queue
518+
* @retval true @p thread has its message queue initialized
512519
*/
513-
static inline int thread_has_msg_queue(const volatile struct _thread *thread)
520+
static inline bool thread_has_msg_queue(const thread_t *thread)
514521
{
522+
assume(thread != NULL);
515523
#if defined(MODULE_CORE_MSG) || defined(DOXYGEN)
516524
return (thread->msg_array != NULL);
517525
#else

tests/net/gnrc_netif/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static void test_creation(void)
148148
#ifdef DEVELHELP
149149
TEST_ASSERT_EQUAL_STRING("eth", sched_threads[ethernet_netif.pid]->name);
150150
#endif
151-
TEST_ASSERT(thread_has_msg_queue(sched_threads[ethernet_netif.pid]));
151+
TEST_ASSERT(msg_queue_capacity(ethernet_netif.pid) > 0);
152152

153153
TEST_ASSERT_EQUAL_INT((gnrc_netif_ieee802154_create(&ieee802154_netif,
154154
ieee802154_netif_stack, IEEE802154_STACKSIZE, GNRC_NETIF_PRIO,
@@ -170,7 +170,7 @@ static void test_creation(void)
170170
#ifdef DEVELHELP
171171
TEST_ASSERT_EQUAL_STRING("wpan", sched_threads[ieee802154_netif.pid]->name);
172172
#endif
173-
TEST_ASSERT(thread_has_msg_queue(sched_threads[ieee802154_netif.pid]));
173+
TEST_ASSERT(msg_queue_capacity(ieee802154_netif.pid) > 0);
174174

175175
for (unsigned i = 0; i < DEFAULT_DEVS_NUMOF; i++) {
176176
TEST_ASSERT_EQUAL_INT((gnrc_netif_create(&netifs[i],
@@ -182,7 +182,7 @@ static void test_creation(void)
182182
TEST_ASSERT_EQUAL_INT(CONFIG_GNRC_NETIF_DEFAULT_HL, netifs[i].cur_hl);
183183
TEST_ASSERT_EQUAL_INT(NETDEV_TYPE_TEST, netifs[i].device_type);
184184
TEST_ASSERT(netifs[i].pid > KERNEL_PID_UNDEF);
185-
TEST_ASSERT(thread_has_msg_queue(sched_threads[netifs[i].pid]));
185+
TEST_ASSERT(msg_queue_capacity(netifs[i].pid) > 0);
186186
TEST_ASSERT_EQUAL_INT(i + SPECIAL_DEVS + 1, gnrc_netif_numof());
187187
for (unsigned j = 0; j < (i + SPECIAL_DEVS + 1); j++) {
188188
TEST_ASSERT_NOT_NULL((ptr = gnrc_netif_iter(ptr)));

0 commit comments

Comments
 (0)