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
7c39134d
Commit
7c39134d
authored
10 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
core: introduce intrusive singly linked list
parent
de19411a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
core/include/list.h
+77
-0
77 additions, 0 deletions
core/include/list.h
core/include/thread.h
+16
-0
16 additions, 0 deletions
core/include/thread.h
core/thread.c
+20
-0
20 additions, 0 deletions
core/thread.c
with
113 additions
and
0 deletions
core/include/list.h
0 → 100644
+
77
−
0
View file @
7c39134d
/*
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
*
* 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.
*/
/**
* @addtogroup core_util
* @{
*
* @file
* @brief Intrusive linked list
*
* Lists are represented as element pointing to the first actual list element.
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifndef LIST_H
#define LIST_H
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* @brief List node structure
*
* Used as is as reference to a list, or as member of any data structure that
* should be member of a list.
*
* Actual list objects should have a @c list_node_t as member and then use
* the container_of() macro in list operations.
* See @ref thread_add_to_list() as example.
*/
typedef
struct
list_node
{
struct
list_node
*
next
;
/**< pointer to next list entry */
}
list_node_t
;
/**
* @brief Insert object into list
*
* If called with a list reference as node, the new node will become the new
* list head.
*
* @param[in] node list node before new entry
* @param[in] new_node list node to insert
*/
static
inline
void
list_add
(
list_node_t
*
node
,
list_node_t
*
new_node
)
{
new_node
->
next
=
node
->
next
;
node
->
next
=
new_node
;
}
/**
* @brief Removes the head of the list and returns it
*
* @param[in] list Pointer to the list itself, where list->next points
* to the root node
*
* @return removed old list head, or NULL if empty
*/
static
inline
list_node_t
*
list_remove_head
(
list_node_t
*
list
)
{
list_node_t
*
head
=
list
->
next
;
if
(
head
)
{
list
->
next
=
head
->
next
;
}
return
head
;
}
#ifdef __cplusplus
}
#endif
#endif
/* LIST_H */
/** @} */
This diff is collapsed.
Click to expand it.
core/include/thread.h
+
16
−
0
View file @
7c39134d
...
...
@@ -29,6 +29,7 @@
#include
"arch/thread_arch.h"
#include
"cpu_conf.h"
#include
"sched.h"
#include
"list.h"
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -315,6 +316,21 @@ char *thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_sta
*/
void
thread_print_msg_queue
(
void
);
/**
* @brief Add thread to list, sorted by priority (internal)
*
* This will add @p thread to @p list sorted by the thread priority.
* It reuses the thread's rq_entry field.
* Used internally by msg and mutex implementations.
*
* @note Only use for threads *not on any runqueue* and with interrupts
* disabled.
*
* @param[in] list ptr to list root node
* @param[in] thread thread to add
*/
void
thread_add_to_list
(
list_node_t
*
list
,
thread_t
*
thread
);
#ifdef DEVELHELP
/**
* @brief Returns the name of a process
...
...
This diff is collapsed.
Click to expand it.
core/thread.c
+
20
−
0
View file @
7c39134d
...
...
@@ -21,6 +21,7 @@
#include
<errno.h>
#include
<stdio.h>
#include
"assert.h"
#include
"thread.h"
#include
"irq.h"
...
...
@@ -104,6 +105,25 @@ void thread_yield(void)
thread_yield_higher
();
}
void
thread_add_to_list
(
list_node_t
*
list
,
thread_t
*
thread
)
{
assert
(
thread
->
status
<
STATUS_ON_RUNQUEUE
);
uint16_t
my_prio
=
thread
->
priority
;
list_node_t
*
new_node
=
(
list_node_t
*
)
&
thread
->
rq_entry
;
while
(
list
->
next
)
{
thread_t
*
list_entry
=
container_of
((
clist_node_t
*
)
list
->
next
,
thread_t
,
rq_entry
);
if
(
list_entry
->
priority
>
my_prio
)
{
break
;
}
list
=
list
->
next
;
}
new_node
->
next
=
list
->
next
;
list
->
next
=
new_node
;
}
#ifdef DEVELHELP
uintptr_t
thread_measure_stack_free
(
char
*
stack
)
{
...
...
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