73 lines
1.5 KiB
C
73 lines
1.5 KiB
C
#if !defined(_VTASKMGR_H_)
|
|
|
|
#define _VTASKMGR_H_ 1
|
|
|
|
#include <pthread.h>
|
|
#include <stddef.h>
|
|
|
|
#include "dataq.h"
|
|
#include "mylock.h"
|
|
#include "netio.h"
|
|
#include "request.h"
|
|
|
|
typedef int (*vtask_func_t)(void*);
|
|
|
|
#define VTASK_IO 0x01
|
|
#define VTASK_GENERIC 0x02
|
|
|
|
typedef struct {
|
|
int vtype;
|
|
union {
|
|
void* generic;
|
|
io_task_data_t iodata;
|
|
} u;
|
|
} vtask_data_t;
|
|
|
|
typedef struct {
|
|
data_item_t link;
|
|
void* owner;
|
|
vtask_data_t* data;
|
|
int vcpu;
|
|
vtask_func_t entry;
|
|
} vtask_t;
|
|
|
|
#define ITPTR_TO_VTASK(p) ((vtask_t*)(((char*)p) - offsetof(vtask_t, link)))
|
|
|
|
typedef enum {
|
|
VCPU_IDLE = 0,
|
|
VCPU_BUSY,
|
|
VCPU_ERR
|
|
} vcpu_state_t;
|
|
|
|
typedef struct {
|
|
int cpuid;
|
|
vcpu_state_t state;
|
|
void* owner;
|
|
cbuf_t wbuf;
|
|
vtask_t* task;
|
|
pthread_t vcpu;
|
|
} vcpu_t;
|
|
|
|
typedef struct {
|
|
int n_vcpus;
|
|
pthread_t dispatcher;
|
|
vcpu_t* vcpus;
|
|
cbuf_t wbuf;
|
|
cbuf_t wtbuf; /* used to wake up vtaskmgr to check tasks */
|
|
dataq_t taskq;
|
|
} vtaskmgr_t;
|
|
|
|
extern vtask_t* vtask_alloc();
|
|
extern int vtask_init(vtask_t*, vtask_func_t, void*);
|
|
extern void vtask_fini(vtask_t*);
|
|
|
|
extern int vtask_enq(vtaskmgr_t*, vtask_t*);
|
|
extern int vtask_handle_msg(vtaskmgr_t*, vtask_func_t, void* arg);
|
|
|
|
extern int vtaskmgr_init(vtaskmgr_t*, int);
|
|
extern int vtaskmgr_start(vtaskmgr_t*);
|
|
extern void vtaskmgr_fini(vtaskmgr_t*);
|
|
extern void vtaskmgr_wait(vtaskmgr_t*);
|
|
extern void vtaskmgr_wakeup(vtaskmgr_t*);
|
|
|
|
#endif
|