Reindented server/core/housekeeper.c

This commit is contained in:
Johan Wikman
2015-11-30 13:53:06 +02:00
parent 486f724dc1
commit 3189a47fc5
2 changed files with 215 additions and 198 deletions

View File

@ -80,7 +80,8 @@ hkinit()
* @param taskfn The function to call for the task
* @param data Data to pass to the task function
* @param frequency How often to run the task, expressed in seconds
* @return Return the time in seconds when the task will be first run if the task was added, otherwise 0
* @return Return the time in seconds when the task will be first run
* if the task was added, otherwise 0
*/
int
hktask_add(char *name, void (*taskfn)(void *), void *data, int frequency)
@ -144,7 +145,8 @@ HKTASK *task, *ptr;
* @param taskfn The function to call for the task
* @param data Data to pass to the task function
* @param when How many second until the task is executed
* @return Return the time in seconds when the task will be first run if the task was added, otherwise 0
* @return Return the time in seconds when the task will be first run
* if the task was added, otherwise 0
*
*/
int
@ -181,9 +183,13 @@ HKTASK *task, *ptr;
ptr = ptr->next;
}
if (ptr)
{
ptr->next = task;
}
else
{
tasks = task;
}
spinlock_release(&tasklock);
return task->nextdue;
@ -209,9 +215,13 @@ HKTASK *ptr, *lptr = NULL;
ptr = ptr->next;
}
if (ptr && lptr)
{
lptr->next = ptr->next;
}
else if (ptr)
{
tasks = ptr->next;
}
spinlock_release(&tasklock);
if (ptr)
@ -256,7 +266,9 @@ int i;
for (i = 0; i < 10; i++)
{
if (do_shutdown)
{
return;
}
thread_millisleep(100);
hkheartbeat++;
}
@ -273,13 +285,17 @@ int i;
spinlock_release(&tasklock);
(*taskfn)(taskdata);
if (ptr->type == HK_ONESHOT)
{
hktask_remove(ptr->name);
}
spinlock_acquire(&tasklock);
ptr = tasks;
}
else
{
ptr = ptr->next;
}
}
spinlock_release(&tasklock);
}
}

View File

@ -32,7 +32,8 @@
* @endverbatim
*/
typedef enum {
typedef enum
{
HK_REPEATED = 1,
HK_ONESHOT
} HKTASK_TYPE;
@ -40,16 +41,15 @@ typedef enum {
/**
* The housekeeper task list
*/
typedef struct hktask {
typedef struct hktask
{
char *name; /*< A simple task name */
void (*task)(void *data); /*< The task to call */
void *data; /*< Data to pass the task */
int frequency; /*< How often to call the tasks (seconds) */
time_t nextdue; /*< When the task should be next run */
HKTASK_TYPE
type; /*< The task type */
struct hktask
*next; /*< Next task in the list */
HKTASK_TYPE type; /*< The task type */
struct hktask *next; /*< Next task in the list */
} HKTASK;
extern void hkinit();
@ -58,4 +58,5 @@ extern int hktask_oneshot(char *name, void (*task)(void *), void *data, int whe
extern int hktask_remove(char *name);
extern void hkshutdown();
extern void hkshow_tasks(DCB *pdcb);
#endif