/* * Header file for CS325 thread library * Copyright 2008 Anthony Martinez */ #ifndef __LIBTHREAD_H #define __LIBTHREAD_H #include #include #define JMPBUF jmp->__jmpbuf #define EBX 0 #define ESP 1 #define EBP 2 #define ESI 3 #define EDI 4 #define EIP 5 #ifdef DEBUG # define Dprintf(...) fprintf(stderr, __VA_ARGS__) #else # define Dprintf(...) #endif #define new_thread_state() (thread_state_t*)calloc(1, sizeof(thread_state_t)) #define THREAD_STACK_SIZE (10*1024) typedef struct thread_state { struct thread_state *prev, *next; unsigned int id; unsigned int eax, ebx, ecx, edx; unsigned int *esi, *edi, *ebp, *esp, *eip; } thread_state_t; typedef struct queue_head { thread_state_t *head; thread_state_t *tail; } queue_head_t; unsigned int thread_create(void *function); void begin_threads(void); void thread_suspend(void); void thread_switch(unsigned int id); /* uh yield? */ void thread_wakeup(unsigned int id); #ifdef DEBUG # define ensure_queue(qq); if(!qq) { fprintf(stderr, "null queue in %s", __FUNCTION__); abort(); } #else # define ensure_queue(qq); #endif void _enqueue(queue_head_t *q, thread_state_t *new); thread_state_t *_dequeue(queue_head_t *q); thread_state_t *_peek(queue_head_t *q); #endif /* __LIBTHREAD_H */