Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
15e8f4e3
Commit
15e8f4e3
authored
9 years ago
by
DipSwitch
Browse files
Options
Downloads
Patches
Plain Diff
core: add support to see if there are messages available for the current thread
parent
d18063cb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
core/include/msg.h
+8
-0
8 additions, 0 deletions
core/include/msg.h
core/msg.c
+16
-0
16 additions, 0 deletions
core/msg.c
tests/thread_msg_avail/Makefile
+6
-0
6 additions, 0 deletions
tests/thread_msg_avail/Makefile
tests/thread_msg_avail/main.c
+61
-0
61 additions, 0 deletions
tests/thread_msg_avail/main.c
with
91 additions
and
0 deletions
core/include/msg.h
+
8
−
0
View file @
15e8f4e3
...
...
@@ -224,6 +224,14 @@ int msg_reply(msg_t *m, msg_t *reply);
*/
int
msg_reply_int
(
msg_t
*
m
,
msg_t
*
reply
);
/**
* @brief Check how many messages are available in the message queue
*
* @return Number of messages available in our queue on success
* @return -1, if no caller's message queue is initialized
*/
int
msg_avail
(
void
);
/**
* @brief Initialize the current thread's message queue.
*
...
...
This diff is collapsed.
Click to expand it.
core/msg.c
+
16
−
0
View file @
15e8f4e3
...
...
@@ -370,6 +370,22 @@ static int _msg_receive(msg_t *m, int block)
DEBUG
(
"This should have never been reached!
\n
"
);
}
int
msg_avail
(
void
)
{
DEBUG
(
"msg_available: %"
PRIkernel_pid
": msg_available.
\n
"
,
sched_active_thread
->
pid
);
tcb_t
*
me
=
(
tcb_t
*
)
sched_active_thread
;
int
queue_index
=
-
1
;
if
(
me
->
msg_array
)
{
queue_index
=
cib_avail
(
&
(
me
->
msg_queue
));
}
return
queue_index
;
}
int
msg_init_queue
(
msg_t
*
array
,
int
num
)
{
/* check if num is a power of two by comparing to its complement */
...
...
This diff is collapsed.
Click to expand it.
tests/thread_msg_avail/Makefile
0 → 100644
+
6
−
0
View file @
15e8f4e3
APPLICATION
=
thread_msg_avail
include
../Makefile.tests_common
DISABLE_MODULE
+=
auto_init
include
$(RIOTBASE)/Makefile.include
This diff is collapsed.
Click to expand it.
tests/thread_msg_avail/main.c
0 → 100644
+
61
−
0
View file @
15e8f4e3
/*
* Copyright (C) 2015 Nick van IJzendoorn <nijzendoorn@engineering-spirit.nl>
*
* 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.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief Thread test application
*
* @author Nick van IJzendoorn <nijzendoorn@engineering-spirit.nl>
*
* @}
*/
#include
<stdio.h>
#include
<inttypes.h>
#include
"thread.h"
#include
"msg.h"
#define MSG_QUEUE_LENGTH (8)
msg_t
msg_queue
[
MSG_QUEUE_LENGTH
];
int
main
(
void
)
{
msg_t
msges
[
MSG_QUEUE_LENGTH
];
msg_init_queue
(
msg_queue
,
MSG_QUEUE_LENGTH
);
for
(
int
idx
=
0
;
idx
<
MSG_QUEUE_LENGTH
;
++
idx
)
{
msges
[
idx
].
sender_pid
=
thread_getpid
();
msges
[
idx
].
type
=
idx
;
msg_send_to_self
(
msges
+
idx
);
printf
(
"Add message %d
\n
"
,
idx
);
while
(
msg_avail
()
!=
(
idx
)
+
1
)
;
/* spin forever if we don't have the result we expect */
}
for
(
int
idx
=
msg_avail
();
idx
>
0
;
--
idx
)
{
msg_t
msg
;
msg_receive
(
&
msg
);
printf
(
"Receive message: %d
\n
"
,
(
MSG_QUEUE_LENGTH
-
idx
));
while
(
msg
.
type
!=
(
MSG_QUEUE_LENGTH
-
idx
)
||
msg_avail
()
!=
idx
-
1
)
;
/* spin forever if we don't have the result we expect */
}
puts
(
"TEST PASSED
\n
"
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment