1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

improves slist implementation (#29)

This commit is contained in:
Falk Werner
2019-04-26 20:50:57 +02:00
committed by GitHub
parent fa78e23533
commit 9130f00289
6 changed files with 153 additions and 64 deletions

View File

@@ -65,7 +65,7 @@ struct wf_impl_session * wf_impl_session_create(
static void wf_impl_session_dispose_filesystems(
struct wf_slist * filesystems)
{
struct wf_slist_item * item = filesystems->first;
struct wf_slist_item * item = wf_slist_first(filesystems);
while (NULL != item)
{
struct wf_slist_item * next = item->next;
@@ -156,11 +156,11 @@ static struct wf_impl_filesystem * wf_impl_session_get_filesystem(
{
struct wf_impl_filesystem * result = NULL;
struct wf_slist_item * item = session->filesystems.first;
struct wf_slist_item * item = wf_slist_first(&session->filesystems);
while (NULL != item)
{
struct wf_slist_item * next = item->next;
struct wf_impl_filesystem * filesystem = wf_container_of(session->filesystems.first, struct wf_impl_filesystem, item);
struct wf_impl_filesystem * filesystem = wf_container_of(item, struct wf_impl_filesystem, item);
if (wsi == filesystem->wsi)
{
result = filesystem;

View File

@@ -12,7 +12,7 @@ void wf_impl_session_manager_init(
void wf_impl_session_manager_cleanup(
struct wf_impl_session_manager * manager)
{
struct wf_slist_item * item = manager->sessions.first;
struct wf_slist_item * item = wf_slist_first(&manager->sessions);
while (NULL != item)
{
struct wf_slist_item * next = item->next;
@@ -47,7 +47,7 @@ struct wf_impl_session * wf_impl_session_manager_get(
{
struct wf_impl_session * session = NULL;
struct wf_slist_item * item = manager->sessions.first;
struct wf_slist_item * item = wf_slist_first(&manager->sessions);
while (NULL != item)
{
struct wf_slist_item * next = item->next;
@@ -68,11 +68,10 @@ void wf_impl_session_manager_remove(
struct wf_impl_session_manager * manager,
struct lws * wsi)
{
struct wf_slist_item * item = manager->sessions.first;
struct wf_slist_item * prev = NULL;
while (NULL != item)
struct wf_slist_item * prev = &manager->sessions.head;
while (NULL != prev->next)
{
struct wf_slist_item * next = item->next;
struct wf_slist_item * item = prev->next;
struct wf_impl_session * session = wf_container_of(item, struct wf_impl_session, item);
if (wsi == session->wsi)
{
@@ -81,7 +80,6 @@ void wf_impl_session_manager_remove(
break;
}
prev = item;
item = next;
prev = prev->next;
}
}

View File

@@ -5,7 +5,7 @@
void wf_message_queue_cleanup(
struct wf_slist * queue)
{
struct wf_slist_item * item = queue->first;
struct wf_slist_item * item = wf_slist_first(queue);
while (NULL != item)
{
struct wf_slist_item * next = item->next;

View File

@@ -4,14 +4,20 @@
void wf_slist_init(
struct wf_slist * list)
{
list->first = NULL;
list->last = NULL;
list->head.next = NULL;
list->last = &list->head;
}
bool wf_slist_empty(
struct wf_slist * list)
{
return (NULL == list->first);
return (list->last == &list->head);
}
struct wf_slist_item * wf_slist_first(
struct wf_slist * list)
{
return list->head.next;
}
void wf_slist_append(
@@ -19,58 +25,36 @@ void wf_slist_append(
struct wf_slist_item * item)
{
item->next = NULL;
list->last->next = item;
list->last = item;
if (NULL != list->last)
if (NULL == list->head.next)
{
list->last->next = item;
list->last = item;
}
else
{
list->first = item;
list->last = item;
list->head.next = item;
}
}
struct wf_slist_item * wf_slist_remove_first(
struct wf_slist * list)
{
struct wf_slist_item * const result = list->first;
if (NULL != result)
{
list->first = list->first->next;
if (NULL == list->first)
{
list->last = NULL;
}
}
return result;
return wf_slist_remove_after(list, &list->head);
}
struct wf_slist_item * wf_slist_remove_after(
struct wf_slist * list,
struct wf_slist_item * prev)
{
struct wf_slist_item * result = NULL;
if (NULL != prev)
struct wf_slist_item * result = prev->next;
if (NULL != result)
{
result = prev->next;
if ((NULL != result) && (NULL != result->next))
{
prev->next = result->next;
}
else
prev->next = result->next;
if (list->last == result)
{
list->last = prev;
prev->next = NULL;
}
}
else
{
result = wf_slist_remove_first(list);
}
}
return result;

View File

@@ -17,7 +17,7 @@ struct wf_slist_item
struct wf_slist
{
struct wf_slist_item * first;
struct wf_slist_item head;
struct wf_slist_item * last;
};
@@ -27,6 +27,9 @@ extern void wf_slist_init(
extern bool wf_slist_empty(
struct wf_slist * list);
extern struct wf_slist_item * wf_slist_first(
struct wf_slist * list);
extern void wf_slist_append(
struct wf_slist * list,
struct wf_slist_item * item);