refactor: remove neu_list dependency

Use sys/queue.h instead of neu_list.h
This commit is contained in:
gc87
2022-04-12 16:56:14 +08:00
parent 208e3aebfe
commit d13747cfc8
4 changed files with 0 additions and 247 deletions
-1
View File
@@ -154,7 +154,6 @@ set(NEURON_BASE_SOURCES
src/utils/atomic_data.c
src/utils/idhash.c
src/utils/hash_table.c
src/utils/list.c
src/utils/panic.c
src/utils/log.c
src/utils/json.c
-72
View File
@@ -1,72 +0,0 @@
/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#ifndef __NEU_LIST_H__
#define __NEU_LIST_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
// In order to make life easy, we just define the list structures
// directly, and let consumers directly inline structures.
typedef struct neu_list_node {
struct neu_list_node *ln_next;
struct neu_list_node *ln_prev;
} neu_list_node;
typedef struct neu_list {
struct neu_list_node ll_head;
size_t ll_offset;
} neu_list;
extern void neu_list_init_offset(neu_list *list, size_t offset);
#define NEU_LIST_INIT(list, type, field) \
neu_list_init_offset(list, offsetof(type, field))
#define NEU_LIST_NODE_INIT(node) \
do { \
(node)->ln_prev = (node)->ln_next = 0; \
} while (0)
extern void *neu_list_first(const neu_list *);
extern void *neu_list_last(const neu_list *);
extern void neu_list_append(neu_list *, void *);
extern void neu_list_prepend(neu_list *, void *);
extern void neu_list_insert_before(neu_list *, void *, void *);
extern void neu_list_insert_after(neu_list *, void *, void *);
extern void *neu_list_next(const neu_list *, void *);
extern void *neu_list_prev(const neu_list *, void *);
extern void neu_list_remove(neu_list *, void *);
extern int neu_list_active(neu_list *, void *);
extern int neu_list_empty(neu_list *);
extern int neu_list_node_active(neu_list_node *);
extern void neu_list_node_remove(neu_list_node *);
#define NEU_LIST_FOREACH(l, it) \
for (it = neu_list_first(l); it != NULL; it = neu_list_next(l, it))
#ifdef __cplusplus
}
#endif
#endif // __NEU_LIST_H__
-1
View File
@@ -25,7 +25,6 @@ extern "C" {
#endif
#include "file.h"
#include "list.h"
#include "log.h"
#include "neu_vector.h"
#include "neuron/adapter.h"
-173
View File
@@ -1,173 +0,0 @@
/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#include <stdlib.h>
#include <string.h>
#include <panic.h>
#include "list.h"
// Linked list implementation. We implement a doubly linked list.
// Using pointer arithmetic, we can operate as a list of "anything".
#define NODE(list, item) \
(neu_list_node *) (void *)(((char *) item) + list->ll_offset)
#define ITEM(list, node) (void *) (((char *) node) - list->ll_offset)
void neu_list_init_offset(neu_list *list, size_t offset)
{
list->ll_offset = offset;
list->ll_head.ln_next = &list->ll_head;
list->ll_head.ln_prev = &list->ll_head;
}
void *neu_list_first(const neu_list *list)
{
neu_list_node *node = list->ll_head.ln_next;
if (node == &list->ll_head) {
return (NULL);
}
return (ITEM(list, node));
}
void *neu_list_last(const neu_list *list)
{
neu_list_node *node = list->ll_head.ln_prev;
if (node == &list->ll_head) {
return (NULL);
}
return (ITEM(list, node));
}
void neu_list_append(neu_list *list, void *item)
{
neu_list_node *node = NODE(list, item);
if ((node->ln_next != NULL) || (node->ln_prev != NULL)) {
neu_panic("appending node already on a list or not inited");
}
node->ln_prev = list->ll_head.ln_prev;
node->ln_next = &list->ll_head;
node->ln_next->ln_prev = node;
node->ln_prev->ln_next = node;
}
void neu_list_prepend(neu_list *list, void *item)
{
neu_list_node *node = NODE(list, item);
if ((node->ln_next != NULL) || (node->ln_prev != NULL)) {
neu_panic("prepending node already on a list or not inited");
}
node->ln_next = list->ll_head.ln_next;
node->ln_prev = &list->ll_head;
node->ln_next->ln_prev = node;
node->ln_prev->ln_next = node;
}
void neu_list_insert_before(neu_list *list, void *item, void *before)
{
neu_list_node *node = NODE(list, item);
neu_list_node *where = NODE(list, before);
if ((node->ln_next != NULL) || (node->ln_prev != NULL)) {
neu_panic("inserting node already on a list or not inited");
}
node->ln_next = where;
node->ln_prev = where->ln_prev;
node->ln_next->ln_prev = node;
node->ln_prev->ln_next = node;
}
void neu_list_insert_after(neu_list *list, void *item, void *after)
{
neu_list_node *node = NODE(list, item);
neu_list_node *where = NODE(list, after);
if ((node->ln_next != NULL) || (node->ln_prev != NULL)) {
abort();
}
node->ln_prev = where;
node->ln_next = where->ln_next;
node->ln_next->ln_prev = node;
node->ln_prev->ln_next = node;
}
void *neu_list_next(const neu_list *list, void *item)
{
neu_list_node *node = NODE(list, item);
if (((node = node->ln_next) == &list->ll_head) || (node == NULL)) {
return (NULL);
}
return (ITEM(list, node));
}
void *neu_list_prev(const neu_list *list, void *item)
{
neu_list_node *node = NODE(list, item);
if (((node = node->ln_prev) == &list->ll_head) || (node == NULL)) {
return (NULL);
}
return (ITEM(list, node));
}
void neu_list_remove(neu_list *list, void *item)
{
neu_list_node *node = NODE(list, item);
node->ln_prev->ln_next = node->ln_next;
node->ln_next->ln_prev = node->ln_prev;
node->ln_next = NULL;
node->ln_prev = NULL;
}
int neu_list_active(neu_list *list, void *item)
{
neu_list_node *node = NODE(list, item);
return (node->ln_next == NULL ? 0 : 1);
}
int neu_list_empty(neu_list *list)
{
// The first check ensures that we treat an uninitialized list
// as empty. This use useful for statically initialized lists.
return ((list->ll_head.ln_next == NULL) ||
(list->ll_head.ln_next == &list->ll_head));
}
int neu_list_node_active(neu_list_node *node)
{
return (node->ln_next == NULL ? 0 : 1);
}
void neu_list_node_remove(neu_list_node *node)
{
if (node->ln_next != NULL) {
node->ln_prev->ln_next = node->ln_next;
node->ln_next->ln_prev = node->ln_prev;
node->ln_next = NULL;
node->ln_prev = NULL;
}
}