use the new scheduler

This commit is contained in:
lxsang
2021-01-03 21:31:35 +01:00
parent cbbc48d216
commit 08877f84ad
4 changed files with 244 additions and 87 deletions

View File

@@ -5,17 +5,16 @@
#include <semaphore.h>
#include <stdint.h>
#define antd_create_task(h, d, c, t) (antd_mktask(h, d, c, t, HEAVY))
typedef enum
{
LIGHT,
HEAVY
} antd_task_type_t;
// define the event
#define TASK_EVT_ALWAY_ON 0x01
#define TASK_EVT_ON_READABLE 0x02
#define TASK_EVT_ON_WRITABLE 0x04
#define TASK_EVT_ON_TIMEOUT 0x08
typedef struct _antd_scheduler_t antd_scheduler_t;
typedef struct _antd_callback_t antd_callback_t;
typedef struct _antd_queue_item_t antd_scheduler_evt_t;
typedef struct _antd_queue_item_t* antd_task_evt_list_t;
typedef struct
{
/**
@@ -42,17 +41,11 @@ typedef struct
* one or more event, otherwise it will be
* rejected by the scheduler
* */
antd_scheduler_evt_t* events;
antd_task_evt_list_t events;
/**
* user data if any
*/
void *data;
/**
* type of a task
* light tasks are executed directly
* heavy tasks are delegated to workers
*/
antd_task_type_t type;
} antd_task_t;
/*
* nit the main scheduler
@@ -71,8 +64,17 @@ void antd_scheduler_destroy(antd_scheduler_t *);
* - callback
* - last data access time
*/
antd_task_t *antd_mktask(void *(*handle)(void *), void *data, void *(*callback)(void *), time_t, antd_task_type_t type);
antd_task_t *antd_create_task(void *(*handle)(void *), void *data, void *(*callback)(void *), time_t);
/**
* ALWAY_ON flag doest not need a file descriptor, it will be executed immediately by the scheduler
* ANY file descriptor should work with READABLE and WRITABLE flags, including timerfd for precision timeout
* Timeout flag (in seconds precision): val is the number of seconds
*
* File descriptor close operation is not handled by the scheduler
*
* */
void antd_task_bind_event(antd_task_t* task, int fd, int timeout, int flags);
/**
* add a task
*/
@@ -90,7 +92,7 @@ int antd_scheduler_ok(antd_scheduler_t *scheduler);
*
* wait for event
*/
void* antd_scheduler_wait(void *);
void *antd_scheduler_wait(void *);
/**
* lock the scheduler
@@ -99,7 +101,7 @@ void antd_scheduler_lock(antd_scheduler_t *);
/**
* Get next valid task id
* */
int antd_scheduler_next_id(antd_scheduler_t* sched, int input);
int antd_scheduler_next_id(antd_scheduler_t *sched, int input);
/**
* unlock the scheduler
* */