unsigned MTGetID () { if ((struct _mt_def *) NIL EQ _MT_) _MT_ = (struct _mt_def *) XBIOS (X_MTDEFS); return (_MT_->CurP->tid); /* return current task ID */ }
unsigned MTID () { register short inuse, oldipl; register unsigned newtid; register TCB *tcp; inuse = TRUE; /* preset inuse to get things started */ if ((struct _mt_def *) NIL == _MT_) _MT_ = (struct _mt_def *) XBIOS (X_MTDEFS); oldipl = setipl (7); /* DISABLE INTERRUPTS */ while (inuse) { newtid = _MT_->mtp->IDct++; /* pick the next ID to try */ inuse = FALSE; /* say it's not in use */ tcp = _MT_->mtp->TCBs; /* start search at beginning */ while (tcp) { /* search the TCB table */ if (tcp->flags & MTF_OCC) /* TCB occupied ? */ if (tcp->tid == newtid) { /* tid in use ? */ inuse = TRUE; /* set to search again */ break; } tcp = tcp->fwd; } } setipl (oldipl); /* RESTORE INTERRUPTS */ return (newtid); /* return the new task ID */ }