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
615b1e60
Commit
615b1e60
authored
7 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
core/clist: add argument to clist_foreach
parent
f142908f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/include/clist.h
+5
-2
5 additions, 2 deletions
core/include/clist.h
tests/unittests/tests-core/tests-core-clist.c
+4
-3
4 additions, 3 deletions
tests/unittests/tests-core/tests-core-clist.c
with
9 additions
and
5 deletions
core/include/clist.h
+
5
−
2
View file @
615b1e60
...
...
@@ -322,13 +322,16 @@ static inline clist_node_t *clist_remove(clist_node_t *list, clist_node_t *node)
/**
* @brief Traverse clist, call function for each member
*
* The pointer supplied by @p arg will be passed to every call to @p func.
*
* If @p func returns non-zero, traversal will be aborted like when calling
* break within a for loop.
*
* @param[in] list List to traverse.
* @param[in] func Function to call for each member.
* @param[in] arg Pointer to pass to every call to @p func
*/
static
inline
void
clist_foreach
(
clist_node_t
*
list
,
int
(
*
func
)(
clist_node_t
*
)
)
static
inline
void
clist_foreach
(
clist_node_t
*
list
,
int
(
*
func
)(
clist_node_t
*
,
void
*
),
void
*
arg
)
{
clist_node_t
*
node
=
list
->
next
;
if
(
!
node
)
{
...
...
@@ -336,7 +339,7 @@ static inline void clist_foreach(clist_node_t *list, int(*func)(clist_node_t *))
}
do
{
node
=
node
->
next
;
if
(
func
(
node
))
{
if
(
func
(
node
,
arg
))
{
return
;
}
}
while
(
node
!=
list
->
next
);
...
...
This diff is collapsed.
Click to expand it.
tests/unittests/tests-core/tests-core-clist.c
+
4
−
3
View file @
615b1e60
...
...
@@ -223,8 +223,9 @@ static void _foreach_test(clist_node_t *node)
/* embunit test macros only work within void returning functions, so this
* trampoline function is needed */
static
int
_foreach_test_trampoline
(
clist_node_t
*
node
)
static
int
_foreach_test_trampoline
(
clist_node_t
*
node
,
void
*
arg
)
{
(
void
)
arg
;
_foreach_test
(
node
);
if
(
_foreach_called
==
_foreach_abort_after
)
{
return
1
;
...
...
@@ -242,7 +243,7 @@ static void test_clist_foreach(void)
clist_rpush
(
list
,
&
tests_clist_buf
[
i
]);
}
clist_foreach
(
list
,
_foreach_test_trampoline
);
clist_foreach
(
list
,
_foreach_test_trampoline
,
NULL
);
TEST_ASSERT
(
_foreach_called
==
_foreach_abort_after
);
...
...
@@ -252,7 +253,7 @@ static void test_clist_foreach(void)
}
_foreach_abort_after
=
(
TEST_CLIST_LEN
+
1
);
clist_foreach
(
list
,
_foreach_test_trampoline
);
clist_foreach
(
list
,
_foreach_test_trampoline
,
NULL
);
TEST_ASSERT
(
_foreach_called
==
TEST_CLIST_LEN
);
}
...
...
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