mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
refactoring: list class
This commit is contained in:
parent
25d278ca4a
commit
9919ad43c8
2 changed files with 7 additions and 5 deletions
|
@ -24,7 +24,7 @@ struct interface;
|
|||
#define LIST_INIT { \
|
||||
.head = NULL, \
|
||||
.tail = NULL, \
|
||||
.count = 0, \
|
||||
.length = 0, \
|
||||
.lock = PTHREAD_MUTEX_INITIALIZER \
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ struct interface;
|
|||
|
||||
#define list_first(list) ((list)->head)
|
||||
#define list_last(list) ((list)->head)
|
||||
#define list_length(list) ((list)->count)
|
||||
#define list_length(list) ((list)->length)
|
||||
|
||||
/** Callback to destroy list elements.
|
||||
*
|
||||
|
@ -48,7 +48,7 @@ typedef void (*dtor_cb_t)(void *data);
|
|||
|
||||
struct list {
|
||||
struct list_elm *head, *tail;
|
||||
int count;
|
||||
int length;
|
||||
|
||||
dtor_cb_t destructor;
|
||||
pthread_mutex_t lock;
|
||||
|
@ -61,6 +61,8 @@ struct list_elm {
|
|||
struct path *path;
|
||||
struct interface *interface;
|
||||
struct socket *socket;
|
||||
struct opal *opal;
|
||||
struct gtfpga *gtfpga;
|
||||
hook_cb_t hook;
|
||||
} /* anonymous */;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ void list_init(struct list *l, dtor_cb_t dtor)
|
|||
pthread_mutex_init(&l->lock, NULL);
|
||||
|
||||
l->destructor = dtor;
|
||||
l->count = 0;
|
||||
l->length = 0;
|
||||
l->head = NULL;
|
||||
l->tail = NULL;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ void list_push(struct list *l, void *p)
|
|||
|
||||
l->tail = e;
|
||||
|
||||
l->count++;
|
||||
l->length++;
|
||||
|
||||
pthread_mutex_unlock(&l->lock);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue