Annotation of researchv9/jtools/src/pi/waitlist.c, revision 1.1

1.1     ! root        1: #include "process.pub"
        !             2: #include "frame.pri"
        !             3: #include "symtab.pri"
        !             4: #include "symbol.h"
        !             5: #include "hostcore.h"
        !             6: #include "asm.pri"
        !             7: #include "format.pub"
        !             8: #include "bpts.pri"
        !             9: #include "master.pri"
        !            10: SRCFILE("waitlist.c")
        !            11: 
        !            12: const int STOPPED=0, RUNNING=1, EXITED=2, DIED=3;
        !            13: 
        !            14: void WaitList::add(HostCore* h)
        !            15: {
        !            16:        WaitMem *wm = new WaitMem;
        !            17:        wm->core = h;
        !            18:        wm->next = head;
        !            19:        wm->changed = 0;
        !            20:        head = wm;
        !            21: }
        !            22: 
        !            23: void WaitList::remove(HostCore* h)
        !            24: {
        !            25:        WaitMem *p = 0, *n = head;
        !            26:        while (n && (n->core != h)) {
        !            27:                p = n;
        !            28:                n = p->next;
        !            29:        }
        !            30:        if (!n)
        !            31:                return;
        !            32:        if (!p)
        !            33:                head = n->next;
        !            34:        else
        !            35:                p->next = n->next;
        !            36:        delete n;
        !            37: }
        !            38: 
        !            39: int wait3(_wait*, int, int);
        !            40: int wait(_wait*);
        !            41: 
        !            42: int WaitList::wait(HostCore* h, int flags)
        !            43: {
        !            44:        WaitMem *p = head;
        !            45:        while (p && (p->core != h))
        !            46:                p = p->next;
        !            47:        if (!p)
        !            48:                return 0;
        !            49:        // It may have already occured 
        !            50:        if (p->changed) {
        !            51:                p->changed = 0;
        !            52: out:
        !            53:                if (flags & WAIT_DISCARD)
        !            54:                        return 1;
        !            55:                h->state = STOPPED;
        !            56:                if (WIFSTOPPED(p->status)) {
        !            57:                        h->cursig = p->status.w_stopsig;
        !            58:                        if (h->cursig == SIGTRAP && (flags & WAIT_PCFIX))
        !            59:                                h->regpoke(h->REG_PC(), h->pc() - 2);
        !            60:                } else {
        !            61:                        if (WIFSIGNALED(p->status)) {
        !            62:                                h->state = DIED;
        !            63:                                h->cursig = p->status.w_termsig;
        !            64:                        } else {
        !            65:                                h->state = EXITED;
        !            66:                                h->cursig = p->status.w_retcode;
        !            67:                        }
        !            68:                }
        !            69:                return 1;
        !            70:        }
        !            71:        // Must really wait for it
        !            72:        for(;;) {
        !            73:                int pid;
        !            74:                _wait tstat;
        !            75:                if (flags & WAIT_POLL) {
        !            76:                        if ((pid = ::wait3(&tstat, WNOHANG, 0)) <= 0)
        !            77:                                return 0;
        !            78:                } else  {
        !            79:                        if ((pid = ::wait(&tstat)) == -1)
        !            80:                                return 0;
        !            81:                }
        !            82:                WaitMem *q = head;
        !            83:                for ( ; q; q = q->next)
        !            84:                        if (q->core->pid == pid) {
        !            85:                                q->status = tstat;
        !            86:                                if (q == p)
        !            87:                                        goto out;
        !            88:                                q->changed = 1;
        !            89:                                break;
        !            90:                        }
        !            91:        }
        !            92: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.