/************************************************************************* * * (c) 1996 California Institute of Technology * Department of Computer Science * Pasadena, CA 91125. * All Rights Reserved * * $Id$ * *************************************************************************/ #ifndef __CONTEXTS_H__ #define __CONTEXTS_H__ #include #include #define DEFAULT_STACK_SIZE 0x5000 #ifdef __cplusplus extern "C" { #endif /* * A process record. The first field of a process record must be * a context. * * The user must provide: * * struct process_record { * context_t c; * ... * }; * */ typedef struct process_record process_t; /* * A context consists of the state of the process, which is the * value of all registers (including pc) and the execution stack. * * For implementation purposes, we need the start address of the process * so that we can handle termination/invocation in a clean manner. * */ typedef struct { jmp_buf buf; char *stack; void (*start) (); } context_t; /* * At any given instant, "current_process" points to the process record * for the currently executing thread of control. */ extern process_t *current_process; /* * Under the timed scheduling option, the following user-defined routine * will be called when the time slice for a particular process is over. * * This routine is called with interrupts disabled, and should enable * interrupts on exit (usually by performing a context switch) */ extern void context_timeout (void); /* * The following routine returns the next process to be executed. * The user must provide this routine. */ extern process_t *context_select (void); /* * Disable/enable timer interrupts. */ extern void context_disable (void); extern void context_enable (void); /* * Perform a context switch. This routine must be called with interrupts * disabled. It re-enables interrupts. */ extern void context_switch (process_t *); /* * Initialize the context field of the process record. */ extern void context_init (process_t *, void (*f)(), int); /* * Unfair scheduling */ extern void context_unfair (void); /* * User must provide a function that deletes the process record. */ extern void context_destroy (process_t *); #ifdef __cplusplus } #endif #endif /* __CONTEXTS_H__ */