2020-03-29 15:40:33 +00:00
|
|
|
#include "webfuse/core/timer/manager_intern.h"
|
|
|
|
#include "webfuse/core/timer/timer_intern.h"
|
|
|
|
#include "webfuse/core/timer/timepoint.h"
|
2020-02-29 20:06:40 +00:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
struct wf_timer_manager
|
|
|
|
{
|
|
|
|
struct wf_timer * timers;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct wf_timer_manager *
|
2020-03-29 15:40:33 +00:00
|
|
|
wf_timer_manager_create(void)
|
2020-02-29 20:06:40 +00:00
|
|
|
{
|
|
|
|
struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager));
|
2020-03-21 20:22:22 +00:00
|
|
|
manager->timers = NULL;
|
2020-02-29 20:06:40 +00:00
|
|
|
|
|
|
|
return manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-03-29 15:40:33 +00:00
|
|
|
wf_timer_manager_dispose(
|
2020-02-29 20:06:40 +00:00
|
|
|
struct wf_timer_manager * manager)
|
|
|
|
{
|
|
|
|
struct wf_timer * timer = manager->timers;
|
|
|
|
while (NULL != timer)
|
|
|
|
{
|
|
|
|
struct wf_timer * next = timer->next;
|
|
|
|
|
2020-03-29 15:40:33 +00:00
|
|
|
wf_timer_trigger(timer);
|
2020-02-29 20:06:40 +00:00
|
|
|
timer = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-29 15:40:33 +00:00
|
|
|
void wf_timer_manager_check(
|
2020-02-29 20:06:40 +00:00
|
|
|
struct wf_timer_manager * manager)
|
|
|
|
{
|
|
|
|
struct wf_timer * timer = manager->timers;
|
|
|
|
while (NULL != timer)
|
|
|
|
{
|
|
|
|
struct wf_timer * next = timer->next;
|
|
|
|
|
2020-03-29 15:40:33 +00:00
|
|
|
if (wf_timer_is_timeout(timer))
|
2020-02-29 20:06:40 +00:00
|
|
|
{
|
2020-03-29 15:40:33 +00:00
|
|
|
wf_timer_manager_removetimer(manager, timer);
|
|
|
|
wf_timer_trigger(timer);
|
2020-02-29 20:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
timer = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:40:33 +00:00
|
|
|
void wf_timer_manager_addtimer(
|
2020-02-29 20:06:40 +00:00
|
|
|
struct wf_timer_manager * manager,
|
|
|
|
struct wf_timer * timer)
|
|
|
|
{
|
|
|
|
if (NULL != manager->timers)
|
|
|
|
{
|
|
|
|
manager->timers->prev = timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
timer->next = manager->timers;
|
|
|
|
timer->prev = NULL;
|
|
|
|
manager->timers = timer;
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:40:33 +00:00
|
|
|
void wf_timer_manager_removetimer(
|
2020-02-29 20:06:40 +00:00
|
|
|
struct wf_timer_manager * manager,
|
|
|
|
struct wf_timer * timer)
|
|
|
|
{
|
|
|
|
struct wf_timer * prev = timer->prev;
|
|
|
|
struct wf_timer * next = timer->next;
|
|
|
|
|
|
|
|
if (NULL != prev)
|
|
|
|
{
|
|
|
|
prev->next = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != next)
|
|
|
|
{
|
|
|
|
next->prev = prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (manager->timers == timer)
|
|
|
|
{
|
|
|
|
manager->timers = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|