[3ae31e9] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | mtzap.c -- Multi-Tasker -- free a TCB
|
---|
| 4 | Version 3 -- 1988-04-14 -- D.N. Lynx Crowe
|
---|
| 5 | (c) Copyright 1988 -- D.N. Lynx Crowe
|
---|
| 6 | =============================================================================
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | #include "stddefs.h"
|
---|
| 10 | #include "biosdefs.h"
|
---|
| 11 | #include "mtdefs.h"
|
---|
| 12 | #include "debug.h"
|
---|
| 13 |
|
---|
| 14 | extern short setipl(); /* set processor IPL function */
|
---|
| 15 |
|
---|
| 16 | extern struct _mtdef *_MT_; /* Multi-Tasker structure pointer */
|
---|
| 17 |
|
---|
| 18 | /* |
---|
| 19 |
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | /*
|
---|
| 23 | =============================================================================
|
---|
| 24 | MTZap() -- delete a task (free its TCB)
|
---|
| 25 |
|
---|
| 26 | -1 not deleted (was active or waiting)
|
---|
| 27 | 0 deleted
|
---|
| 28 | 1 not found
|
---|
| 29 | =============================================================================
|
---|
| 30 | */
|
---|
| 31 |
|
---|
| 32 | short
|
---|
| 33 | MTZap(tid)
|
---|
| 34 | unsigned tid;
|
---|
| 35 | {
|
---|
| 36 | register short oldipl, rv;
|
---|
| 37 | register TCB *tcp;
|
---|
| 38 |
|
---|
| 39 | if ((struct _mt_def *)NIL EQ _MT_)
|
---|
| 40 | _MT_ = (struct _mt_def *)XBIOS(X_MTDEFS);
|
---|
| 41 |
|
---|
| 42 | tcp = _MT_->mtp->TCBs; /* point at start of TCB table */
|
---|
| 43 | rv = 1; /* preset return code */
|
---|
| 44 |
|
---|
| 45 | oldipl = setipl(7); /* DISABLE INTERRUPTS */
|
---|
| 46 |
|
---|
| 47 | while (tcp) { /* check each TCB */
|
---|
| 48 |
|
---|
| 49 | if (tcp->flags & MTF_OCC) { /* occupied ? */
|
---|
| 50 |
|
---|
| 51 | if (tcp->tid NE tid) /* continue if not TCB we want */
|
---|
| 52 | goto nexttcb;
|
---|
| 53 |
|
---|
| 54 | if (tcp->flags & ~MTF_OCC) { /* stopped ? */
|
---|
| 55 |
|
---|
| 56 | rv = -1; /* not stopped */
|
---|
| 57 | break;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | tcp->flags = 0; /* free the TCB */
|
---|
| 61 | rv = 0; /* TCB deleted */
|
---|
| 62 | break;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | nexttcb:
|
---|
| 66 | tcp = tcp->fwd; /* check next TCB */
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | setipl(oldipl); /* RESTORE INTERRUPTS */
|
---|
| 70 |
|
---|
| 71 | return(rv); /* return deletion status */
|
---|
| 72 | }
|
---|