source: buchla-68k/orig/MT/MTSTOP.C@ 99cac86

Last change on this file since 99cac86 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 2.8 KB
Line 
1/*
2 =============================================================================
3 mtstop.c -- Multi-Tasker -- stop task
4 Version 3 -- 1988-04-11 -- 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
13extern short setipl(); /* set processor IPL function */
14
15extern struct _mt_def *_MT_;
16
17/*
18
19*/
20
21/*
22 =============================================================================
23 MTStop() -- stop a task
24
25 -3 - task not stopped (was the current task)
26 -2 - task not stopped (can't find it on ready queue)
27 -1 - task not stopped (can't find it at all)
28
29 0 - task stopped (was ready to run)
30
31 1 - task stopped (was waiting)
32 2 - task already stopped (wasn't waiting or on ready queue)
33 3 - task will be stopped (has MTF_STP set)
34 =============================================================================
35*/
36
37short
38MTStop(tid)
39unsigned tid;
40{
41 register short oldipl;
42 register TCB *tcbcur, *tcbprv;
43
44/*
45
46*/
47 if ((struct _mt_def *)NIL EQ _MT_)
48 _MT_ = (struct _mt_def *)XBIOS(X_MTDEFS);
49
50 tcbcur = _MT_->mtp->TCBs; /* point at TCB table */
51
52 oldipl = setipl(7); /* DISABLE INTERRUPTS */
53
54 while (tcbcur) { /* check each TCB */
55
56 if (tcbcur->flags & MTF_OCC) { /* TCB in use ? */
57
58 if (tcbcur->tid EQ tid) { /* task we want ? */
59
60 if (tcbcur->flags & MTF_STP) { /* stopped ? */
61
62 setipl(oldipl); /* RESTORE INTERRUPTS */
63 return(3); /* task in stop state */
64 }
65
66 if (tcbcur->flags & MTF_RUN) {
67
68 setipl(oldipl); /* RESTORE INTERRUPTS */
69 return(-3); /* can't stop current task */
70 }
71
72 if (tcbcur->flags & MTF_SWT) { /* waiting ? */
73
74 tcbcur->flags |= MTF_STP; /* set to stop */
75
76 setipl(oldipl); /* RESTORE INTERRUPTS */
77 return(1); /* task is waiting */
78 }
79
80 if (NOT (tcbcur->flags & MTF_RDY)) { /* stopped ? */
81
82 setipl(oldipl); /* RESTORE INTERRUPTS */
83 return(2); /* task was stopped */
84 }
85/*
86
87*/
88 tcbprv = (TCB *)&_MT_->mtp->RdyQ;
89 tcbcur = tcbprv->next;
90
91 while(tcbcur) { /* locate task on ready queue */
92
93 tcbprv = tcbcur;
94 tcbcur = tcbprv->next;
95
96 if (tcbcur NE (TCB *)NIL) {
97
98 if (tcbcur->tid EQ tid) {
99
100 tcbprv->next = tcbcur->next;
101 tcbcur->flags &= ~MTF_RDY;
102
103 setipl(oldipl); /* RESTORE INTERRUPTS */
104 return(0); /* stopped a ready task */
105 }
106 }
107 }
108
109 setipl(oldipl); /* RESTORE INTERRUPTS */
110 return(-2); /* can't find a ready task */
111 }
112 }
113
114 tcbcur = tcbcur->fwd; /* point at next TCB */
115 }
116
117 setipl(oldipl); /* RESTORE INTERRUPTS */
118 return(-1); /* can't find the task at all */
119}
120
Note: See TracBrowser for help on using the repository browser.