1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00
falk-werner_webfuse-provider/lib/wsfs/adapter/time/timeout_manager.c

85 lines
1.6 KiB
C
Raw Normal View History

#include "wsfs/adapter/time/timeout_manager_intern.h"
2019-02-09 18:02:53 +00:00
#include <stddef.h>
#include "wsfs/adapter/time/timer_intern.h"
#include "wsfs/adapter/time/timepoint.h"
2019-02-09 18:02:53 +00:00
void wsfs_timeout_manager_init(
struct wsfs_timeout_manager * manager)
{
manager->timers = NULL;
}
void wsfs_timeout_manager_cleanup(
struct wsfs_timeout_manager * manager)
{
struct wsfs_timer * timer = manager->timers;
while (NULL != timer)
{
struct wsfs_timer * next = timer->next;
wsfs_timer_trigger(timer);
timer = next;
}
manager->timers = NULL;
}
void wsfs_timeout_manager_check(
struct wsfs_timeout_manager * manager)
{
struct wsfs_timer * timer = manager->timers;
while (NULL != timer)
{
struct wsfs_timer * next = timer->next;
if (wsfs_timer_is_timeout(timer))
{
wsfs_timeout_manager_removetimer(manager, timer);
wsfs_timer_trigger(timer);
}
timer = next;
}
}
void wsfs_timeout_manager_addtimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer)
{
if (NULL != manager->timers)
{
manager->timers->prev = timer;
}
timer->next = manager->timers;
timer->prev = NULL;
manager->timers = timer;
}
void wsfs_timeout_manager_removetimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer)
{
struct wsfs_timer * prev = timer->prev;
struct wsfs_timer * next = timer->next;
if (NULL != prev)
{
prev->next = next;
}
if (NULL != next)
{
next->prev = prev;
}
if (manager->timers == timer)
{
manager->timers = next;
}
}