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

project structure changed

This commit is contained in:
Falk Werner
2019-02-10 14:19:15 +01:00
parent fa5e89c64f
commit cf1b57e86e
59 changed files with 36 additions and 31 deletions

View File

@@ -0,0 +1,84 @@
#include "wsfs/time/timeout_manager_intern.h"
#include <stddef.h>
#include "wsfs/time/timer_intern.h"
#include "wsfs/time/timepoint.h"
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;
}
}

View File

@@ -0,0 +1,29 @@
#ifndef _WSFS_TIME_TIMEOUT_MANAGER_H
#define _WSFS_TIME_TIMEOUT_MANAGER_H
struct wsfs_timer;
struct wsfs_timeout_manager
{
struct wsfs_timer * timers;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_timeout_manager_init(
struct wsfs_timeout_manager * manager);
extern void wsfs_timeout_manager_cleanup(
struct wsfs_timeout_manager * manager);
extern void wsfs_timeout_manager_check(
struct wsfs_timeout_manager * manager);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,24 @@
#ifndef _WSFS_TIME_TIMEOUT_MANAGER_INTERN_H
#define _WSFS_TIME_TIMEOUT_MANAGER_INTERN_H
#include "wsfs/time/timeout_manager.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_timeout_manager_addtimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer);
extern void wsfs_timeout_manager_removetimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

31
lib/wsfs/time/timepoint.c Normal file
View File

@@ -0,0 +1,31 @@
#include "wsfs/time/timepoint.h"
#include <time.h>
#define WSFS_MSEC_PER_SEC ((wsfs_timepoint) 1000)
#define WSFS_NSEC_PER_MSEC ((wsfs_timepoint) 1000 * 1000)
wsfs_timepoint wsfs_timepoint_now(void)
{
struct timespec timepoint;
clock_gettime(CLOCK_MONOTONIC, &timepoint);
wsfs_timepoint const now = (timepoint.tv_sec * WSFS_MSEC_PER_SEC) + (timepoint.tv_nsec / WSFS_NSEC_PER_MSEC);
return now;
}
wsfs_timepoint wsfs_timepoint_in_msec(wsfs_timediff value)
{
wsfs_timepoint const now = wsfs_timepoint_now();
wsfs_timepoint result = now + ((wsfs_timepoint) value);
return result;
}
bool wsfs_timepoint_is_elapsed(wsfs_timepoint timepoint)
{
wsfs_timepoint const now = wsfs_timepoint_now();
wsfs_timediff const diff = (wsfs_timediff) (timepoint - now);
return (0 > diff);
}

31
lib/wsfs/time/timepoint.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef _WSFS_TIME_TIMEPOINT_H
#define _WSFS_TIME_TIMEPOINT_H
#ifndef __cplusplus
#include <stdbool.h>
#include <inttypes.h>
#else
#include <cinttypes>
#endif
typedef uint64_t wsfs_timepoint;
typedef int64_t wsfs_timediff;
#ifdef __cplusplus
extern "C"
{
#endif
extern wsfs_timepoint wsfs_timepoint_now(void);
extern wsfs_timepoint wsfs_timepoint_in_msec(
wsfs_timediff value);
extern bool wsfs_timepoint_is_elapsed(
wsfs_timepoint timepoint);
#ifdef __cplusplus
}
#endif
#endif

65
lib/wsfs/time/timer.c Normal file
View File

@@ -0,0 +1,65 @@
#include "wsfs/time/timer_intern.h"
#include "wsfs/time/timeout_manager_intern.h"
#include <stddef.h>
#include <string.h>
void wsfs_timer_init(
struct wsfs_timer * timer,
struct wsfs_timeout_manager * manager)
{
timer->manager = manager;
timer->timeout = 0;
timer->timeout_handler = NULL;
timer->user_data = NULL;
timer->prev = NULL;
timer->next = NULL;
}
void wsfs_timer_cleanup(
struct wsfs_timer * timer)
{
memset(timer, 0, sizeof(struct wsfs_timer));
}
void wsfs_timer_start(
struct wsfs_timer * timer,
wsfs_timepoint absolute_timeout,
wsfs_timer_timeout_fn * handler,
void * user_data)
{
timer->timeout = absolute_timeout;
timer->timeout_handler = handler;
timer->user_data = user_data;
wsfs_timeout_manager_addtimer(timer->manager, timer);
}
void wsfs_timer_cancel(
struct wsfs_timer * timer)
{
wsfs_timeout_manager_removetimer(timer->manager, timer);
timer->timeout = 0;
timer->timeout_handler = NULL;
timer->user_data = NULL;
}
bool wsfs_timer_is_timeout(
struct wsfs_timer * timer)
{
return wsfs_timepoint_is_elapsed(timer->timeout);
}
void wsfs_timer_trigger(
struct wsfs_timer * timer)
{
if (NULL != timer->timeout_handler)
{
timer->prev = NULL;
timer->next = NULL;
timer->timeout_handler(timer);
}
}

48
lib/wsfs/time/timer.h Normal file
View File

@@ -0,0 +1,48 @@
#ifndef _WSFS_TIMER_H
#define _WSFS_TIMER_H
#include "wsfs/time/timepoint.h"
struct wsfs_timer;
struct wsfs_timeout_manager;
typedef void wsfs_timer_timeout_fn(struct wsfs_timer * timer);
struct wsfs_timer
{
struct wsfs_timeout_manager * manager;
wsfs_timepoint timeout;
wsfs_timer_timeout_fn * timeout_handler;
void * user_data;
struct wsfs_timer * next;
struct wsfs_timer * prev;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_timer_init(
struct wsfs_timer * timer,
struct wsfs_timeout_manager * manager);
extern void wsfs_timer_cleanup(
struct wsfs_timer * timer);
extern void wsfs_timer_start(
struct wsfs_timer * timer,
wsfs_timepoint absolute_timeout,
wsfs_timer_timeout_fn * handler,
void * user_data);
extern void wsfs_timer_cancel(
struct wsfs_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,25 @@
#ifndef _WSFS_TIME_TIMER_INTERN_H
#define _WSFS_TIME_TIMER_INTERN_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/time/timer.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern bool wsfs_timer_is_timeout(
struct wsfs_timer * timer);
extern void wsfs_timer_trigger(
struct wsfs_timer * timer);
#ifdef __cplusplus
}
#endif
#endif