54 lines
1.3 KiB
C
54 lines
1.3 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 *waiters;
|
|
int fd;
|
|
struct bufferevent *io;
|
|
unsigned short error_direction;
|
|
unsigned short error_kind;
|
|
} IOHandle;
|
|
|
|
extern IOHandle *stdin_h;
|
|
extern IOHandle *stdout_h;
|
|
extern IOHandle *stderr_h;
|
|
|
|
extern Process *current_process;
|
|
|
|
extern void yield(void);
|
|
extern Process *spawn(process_main_t f, void *arg);
|
|
extern void nap(long millis);
|
|
|
|
extern void suspend(void);
|
|
extern void resume(Process *p);
|
|
|
|
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);
|
|
extern void interrupt_harness(void);
|
|
|
|
#endif
|