#include "mt_os.h" #include "minithread.h" #include "synch.h" #include "main.h" #include "clock.h" #include #include #include /* The first argument is the address of the function to be forked off, * and the second is the argument to the function. */ int mt_minithread_fork(unsigned fn, unsigned arg) { run_struct *rs; minithread_t mt; disable_interrupts(); rs = (run_struct *) malloc (sizeof(run_struct)); rs->paddress = fn; rs->arg = arg; mt = minithread_fork(run, (arg_t)rs); /* as you can see, this currently just casts the ptr to the minithread_t to an integer. you will be responsible for doing a safer mapping between say, integers(handles), and the actual ptrs */ return (int)mt; } int mt_minithread_self() { int tmp = (int)minithread_self(); return (tmp); } int mt_minithread_yield() { minithread_yield(); return 0; } int mt_minithread_die() { assert(0); } int mt_semaphore_create() { int tmp = (int) semaphore_create(); return (tmp); } int mt_semaphore_destroy(unsigned sem) { semaphore_destroy((semaphore_t) sem); return 0; } int mt_semaphore_initialize(unsigned sem, unsigned cnt) { semaphore_initialize((semaphore_t) sem, cnt); return 0; } int mt_semaphore_P(unsigned sem) { semaphore_P((semaphore_t)sem); return 0; } int mt_semaphore_V(unsigned sem) { semaphore_V((semaphore_t)sem); return 0; }