hop-2012/harness.h

52 lines
1.2 KiB
C

#ifndef cmsg_harness_h
#define cmsg_harness_h
typedef void (*process_main_t)(void *);
typedef enum process_state_t_ {
PROCESS_DEAD = 0,
PROCESS_RUNNING,
PROCESS_WAITING
} process_state_t;
typedef struct Process {
process_state_t state;
int wait_flags;
void *stack_base;
ucontext_t context;
struct Process *link;
} Process;
typedef struct IOHandle {
Process *p;
int fd;
struct bufferevent *io;
short error_direction;
short error_kind;
} IOHandle;
typedef struct ProcessQueue {
int count;
Process *head;
Process *tail;
} ProcessQueue;
extern Process *current_process;
extern void yield(void);
extern void spawn(process_main_t f, void *arg);
extern void nap(long millis);
extern IOHandle *new_iohandle(int fd);
extern void delete_iohandle(IOHandle *h);
extern void iohandle_clear_error(IOHandle *h);
extern cmsg_bytes_t iohandle_readwait(IOHandle *h, size_t at_least);
extern void iohandle_drain(IOHandle *h, size_t count);
extern void iohandle_write(IOHandle *h, cmsg_bytes_t buf);
extern int iohandle_flush(IOHandle *h);
extern void iohandle_settimeout(IOHandle *h, int timeout_read, int timeout_write);
extern void boot_harness(void);
#endif