openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

task.h (1917B)


      1 /* Copyright 1998-1999, Brian J. Swetland. All rights reserved.
      2 ** Distributed under the terms of the OpenBLT License
      3 */
      4 
      5 #ifndef _TASK_H_
      6 #define _TASK_H_
      7 
      8 #include "resource.h"
      9 #include "list.h"
     10 #include "team.h"
     11 
     12 #define tKERNEL       0
     13 #define tRUNNING      1
     14 #define tREADY        2
     15 #define tDEAD         3
     16 #define tWAITING      4
     17 #define tSLEEP_IRQ    5
     18 #define tSLEEP_TIMER  6
     19 #define tSLEEP_PAGING 7
     20 
     21 #define PARANOID 0
     22 
     23 #if PARANOID
     24 #define TMAGIC1 0x327610ae
     25 #define TMAGIC2 0x55716621
     26 #endif
     27 
     28 struct __task_t {
     29     resource_t rsrc;
     30 
     31 #if PARANOID
     32 	uint32 magic1;
     33 #endif
     34 		
     35 	/* wait_queue support */
     36 	resource_t *waiting_on;
     37 	node_t node;
     38 	int   status; /* status code for the task that has just been awakened */
     39 	uint32 wait_time; /* for timer queues */
     40 	
     41 	uint32 flags;
     42     uint32 irq;
     43 	uint32 esp; /* saved stack */
     44 	uint32 esp0; /* kernel entry stack -- to stuff in the TSS */
     45 #if PARANOID
     46 	uint32 magic2;
     47 #endif
     48 	uint32 cr3;
     49 	uint32 scount;
     50 	void *kstack, *ustack;
     51 	area_t *stack_area;
     52 	team_t *team; /* team to which this task belongs */
     53 
     54 #ifdef __SMP__
     55     int has_cpu, processor, last_processor;
     56 #endif
     57 };
     58 
     59 #if PARANOID
     60 #define TSETMAGIC(t) { t->magic1 = TMAGIC1; t->magic2 = TMAGIC2; }
     61 #define TCLRMAGIC(t) { t->magic1 = 0; t->magic2 = 0; }
     62 #define TCHKMAGIC(t) { if((t->magic1 != TMAGIC1) || (t->magic2 != TMAGIC2)) panic("bad thread magic");}
     63 #else
     64 #define TSETMAGIC(t) ((void)0)
     65 #define TCLRMAGIC(t) ((void)0)
     66 #define TCHKMAGIC(t) ((void)0)
     67 #endif
     68 
     69 task_t *task_create(team_t *team, uint32 ip, uint32 sp, int kernel);
     70 void task_destroy(task_t *task);
     71 void task_wait_on(task_t *task, resource_t *rsrc);
     72 void task_wake(task_t *task, int status);
     73 int wait_on(resource_t *rsrc);
     74 
     75 void task_call(task_t *t);
     76 
     77 int thr_kill(int task_id);
     78 int thr_wait(int task_id);
     79 int thr_spawn(uint32 ip, uint32 sp, 
     80 			  uint32 area0, uint32 vaddr0, 
     81 			  uint32 area1, uint32 vaddr1,
     82 			  const char *name);
     83 #endif
     84