Refactored linked list administration in rhc so that it becomes reusable
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
This commit is contained in:
parent
a41a615999
commit
219cb6cf4f
4 changed files with 182 additions and 80 deletions
|
@ -101,6 +101,10 @@ set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
|||
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
|
||||
list(APPEND headers
|
||||
"${include_path}/dds/ddsrt/avl.h"
|
||||
"${include_path}/dds/ddsrt/fibheap.h"
|
||||
"${include_path}/dds/ddsrt/hopscotch.h"
|
||||
"${include_path}/dds/ddsrt/thread_pool.h"
|
||||
"${include_path}/dds/ddsrt/log.h"
|
||||
"${include_path}/dds/ddsrt/retcode.h"
|
||||
"${include_path}/dds/ddsrt/attributes.h"
|
||||
|
@ -113,7 +117,8 @@ list(APPEND headers
|
|||
"${include_path}/dds/ddsrt/strtol.h"
|
||||
"${include_path}/dds/ddsrt/types.h"
|
||||
"${include_path}/dds/ddsrt/countargs.h"
|
||||
"${include_path}/dds/ddsrt/static_assert.h")
|
||||
"${include_path}/dds/ddsrt/static_assert.h"
|
||||
"${include_path}/dds/ddsrt/circlist.h")
|
||||
|
||||
list(APPEND sources
|
||||
"${source_path}/bswap.c"
|
||||
|
@ -121,21 +126,14 @@ list(APPEND sources
|
|||
"${source_path}/log.c"
|
||||
"${source_path}/retcode.c"
|
||||
"${source_path}/strtod.c"
|
||||
"${source_path}/strtol.c")
|
||||
|
||||
list(APPEND headers
|
||||
"${include_path}/dds/ddsrt/avl.h"
|
||||
"${include_path}/dds/ddsrt/fibheap.h"
|
||||
"${include_path}/dds/ddsrt/hopscotch.h"
|
||||
"${include_path}/dds/ddsrt/thread_pool.h")
|
||||
|
||||
list(APPEND sources
|
||||
"${source_path}/strtol.c"
|
||||
"${source_path}/avl.c"
|
||||
"${source_path}/expand_envvars.c"
|
||||
"${source_path}/fibheap.c"
|
||||
"${source_path}/hopscotch.c"
|
||||
"${source_path}/thread_pool.c"
|
||||
"${source_path}/xmlparser.c")
|
||||
"${source_path}/xmlparser.c"
|
||||
"${source_path}/circlist.c")
|
||||
|
||||
# Not every target offers the same set of features. For embedded targets the
|
||||
# set of features may even be different between builds. e.g. a FreeRTOS build
|
||||
|
|
43
src/ddsrt/include/dds/ddsrt/circlist.h
Normal file
43
src/ddsrt/include/dds/ddsrt/circlist.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2019 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef DDSRT_CIRCLIST_H
|
||||
#define DDSRT_CIRCLIST_H
|
||||
|
||||
/* Circular doubly linked list implementation */
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "dds/export.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define DDSRT_FROM_CIRCLIST(typ_, member_, cle_) ((typ_ *) ((char *) (cle_) - offsetof (typ_, member_)))
|
||||
|
||||
struct ddsrt_circlist {
|
||||
struct ddsrt_circlist_elem *latest; /* pointer to latest inserted element */
|
||||
};
|
||||
|
||||
struct ddsrt_circlist_elem {
|
||||
struct ddsrt_circlist_elem *next;
|
||||
struct ddsrt_circlist_elem *prev;
|
||||
};
|
||||
|
||||
DDS_EXPORT void ddsrt_circlist_init (struct ddsrt_circlist *list);
|
||||
DDS_EXPORT bool ddsrt_circlist_isempty (const struct ddsrt_circlist *list);
|
||||
DDS_EXPORT void ddsrt_circlist_append (struct ddsrt_circlist *list, struct ddsrt_circlist_elem *elem);
|
||||
DDS_EXPORT void ddsrt_circlist_remove (struct ddsrt_circlist *list, struct ddsrt_circlist_elem *elem);
|
||||
DDS_EXPORT struct ddsrt_circlist_elem *ddsrt_circlist_oldest (const struct ddsrt_circlist *list);
|
||||
DDS_EXPORT struct ddsrt_circlist_elem *ddsrt_circlist_latest (const struct ddsrt_circlist *list);
|
||||
|
||||
#endif /* DDSRT_CIRCLIST_H */
|
84
src/ddsrt/src/circlist.c
Normal file
84
src/ddsrt/src/circlist.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2019 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "dds/ddsrt/circlist.h"
|
||||
|
||||
void ddsrt_circlist_init (struct ddsrt_circlist *list)
|
||||
{
|
||||
list->latest = NULL;
|
||||
}
|
||||
|
||||
bool ddsrt_circlist_isempty (const struct ddsrt_circlist *list)
|
||||
{
|
||||
return list->latest == NULL;
|
||||
}
|
||||
|
||||
void ddsrt_circlist_append (struct ddsrt_circlist *list, struct ddsrt_circlist_elem *elem)
|
||||
{
|
||||
if (list->latest == NULL)
|
||||
elem->next = elem->prev = elem;
|
||||
else
|
||||
{
|
||||
struct ddsrt_circlist_elem * const hd = list->latest;
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
const struct ddsrt_circlist_elem *x = hd;
|
||||
do { assert (x != elem); x = x->next; } while (x != hd);
|
||||
}
|
||||
#endif
|
||||
elem->next = hd->next;
|
||||
elem->prev = hd;
|
||||
hd->next = elem;
|
||||
elem->next->prev = elem;
|
||||
}
|
||||
list->latest = elem;
|
||||
}
|
||||
|
||||
void ddsrt_circlist_remove (struct ddsrt_circlist *list, struct ddsrt_circlist_elem *elem)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
const struct ddsrt_circlist_elem *x = list->latest;
|
||||
assert (x);
|
||||
do { if (x == elem) break; x = x->next; } while (x != list->latest);
|
||||
assert (x == elem);
|
||||
}
|
||||
#endif
|
||||
if (elem->next == elem)
|
||||
list->latest = NULL;
|
||||
else
|
||||
{
|
||||
struct ddsrt_circlist_elem * const elem_prev = elem->prev;
|
||||
struct ddsrt_circlist_elem * const elem_next = elem->next;
|
||||
elem_prev->next = elem_next;
|
||||
elem_next->prev = elem_prev;
|
||||
if (list->latest == elem)
|
||||
list->latest = elem_prev;
|
||||
}
|
||||
}
|
||||
|
||||
struct ddsrt_circlist_elem *ddsrt_circlist_oldest (const struct ddsrt_circlist *list)
|
||||
{
|
||||
assert (!ddsrt_circlist_isempty (list));
|
||||
return list->latest->next;
|
||||
}
|
||||
|
||||
struct ddsrt_circlist_elem *ddsrt_circlist_latest (const struct ddsrt_circlist *list)
|
||||
{
|
||||
assert (!ddsrt_circlist_isempty (list));
|
||||
return list->latest;
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue