Annotation of researchv10no/cmd/cfront/libC/task/qtail.c, revision 1.1

1.1     ! root        1: /*ident        "%W%" */
        !             2: /**************************************************************************
        !             3:                        Copyright (c) 1984 AT&T
        !             4:                          All Rights Reserved   
        !             5: 
        !             6:        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
        !             7:        
        !             8:        The copyright notice above does not evidence any        
        !             9:        actual or intended publication of such source code.
        !            10: 
        !            11: *****************************************************************************/
        !            12: #include <task.h>
        !            13: 
        !            14: /* construct qtail <--> oqueue */
        !            15: qtail::qtail(qmodetype mode, int max)
        !            16: {
        !            17:        if (0 < max) {
        !            18:                qt_queue = new class oqueue(max);
        !            19:                qt_queue->q_tail = this;
        !            20:        };
        !            21:        qt_mode = mode;
        !            22: }
        !            23: 
        !            24: /* destroy q if not also pointed to by a qhead */
        !            25: qtail::~qtail()
        !            26: {
        !            27:        oqueue* q = qt_queue;
        !            28: 
        !            29:        if (q->q_head)
        !            30:                q->q_tail = 0;
        !            31:        else
        !            32:                delete q;
        !            33: }
        !            34: 
        !            35: 
        !            36: /* insert object at rear of q (becoming new value of oqueue->q_ptr) */
        !            37: 
        !            38: // q->q_ptr points to last object.  last->o_next points to first object.
        !            39: // first->o_next points to the next object.
        !            40: int
        !            41: qtail::put(object* p)
        !            42: {
        !            43: ll:
        !            44:        register oqueue* q = qt_queue;
        !            45:        if (p->o_next) task_error(E_PUTOBJ, this);
        !            46: 
        !            47:        if (q->q_count < q->q_max) {
        !            48:                if (q->q_count++) {
        !            49:                        register object* oo = q->q_ptr;
        !            50:                        p->o_next = oo->o_next;
        !            51:                        q->q_ptr = oo->o_next = p;
        !            52:                }
        !            53:                else {  // q was empty; alert those waiting on it
        !            54:                        qhead* h = q->q_head;
        !            55:                        q->q_ptr = p->o_next = p;
        !            56:                        if (h) h->alert();
        !            57:                }
        !            58:                return 1;
        !            59:        }
        !            60: 
        !            61:        switch (qt_mode) {
        !            62:        case WMODE:
        !            63:                this_task()->sleep(this);
        !            64:                goto ll;
        !            65:        case EMODE:
        !            66:                task_error(E_PUTFULL, this);
        !            67:                goto ll;
        !            68:        case ZMODE:
        !            69:                return 0;
        !            70:        }
        !            71: }
        !            72: 
        !            73: 
        !            74: /* create head for this q */
        !            75: qhead*
        !            76: qtail::head()
        !            77: {
        !            78:        oqueue* q = qt_queue;
        !            79:        register qhead* h = q->q_head;
        !            80: 
        !            81:        if (h == 0) {
        !            82:                h = new qhead(qt_mode,0);
        !            83:                q->q_head = h;
        !            84:                h->qh_queue = q;
        !            85:        };
        !            86: 
        !            87:        return h;
        !            88: }
        !            89: 
        !            90: 
        !            91: /* result:  ?qhead<-->? oldq<-->(new)qtail  newq<-->(this)qtail */
        !            92: qtail*
        !            93: qtail::cut()
        !            94: {
        !            95:        oqueue* oldq = qt_queue;
        !            96:        qtail* t = new qtail(qt_mode,oldq->q_max);
        !            97:        oqueue* newq = t->qt_queue;
        !            98: 
        !            99:        t->qt_queue = oldq;
        !           100:        oldq->q_tail = t;
        !           101: 
        !           102:        newq->q_tail = this;
        !           103:        qt_queue = newq;
        !           104: 
        !           105:        return t;
        !           106: }
        !           107: 
        !           108: 
        !           109: /* this qtail is supposed to be downstream from the qhead h */
        !           110: void
        !           111: qtail::splice(qhead* h)
        !           112: {
        !           113:        h->splice(this);
        !           114: }
        !           115: 
        !           116: void
        !           117: qtail::print(int n, int baseClass)
        !           118: {
        !           119:        if (!baseClass)
        !           120:                printf("qtail ");
        !           121: 
        !           122:        int m = qt_queue->q_max;
        !           123:        int c = qt_queue->q_count;
        !           124:        class qhead * h = qt_queue->q_head;
        !           125: 
        !           126:        printf("mode=%d, max=%d, space=%d, head=%d\n",
        !           127:                qt_mode, m, m-c, h);
        !           128: 
        !           129:        if (n&VERBOSE) {
        !           130:                int m = n & ~(CHAIN|VERBOSE);
        !           131:                if (h) {
        !           132:                        printf("head of queue:\n");
        !           133:                        h->print(m);
        !           134:                } else printf("\tno head\n");
        !           135: 
        !           136:                qt_queue->print(m);
        !           137:        }
        !           138: 
        !           139:        object::print(n, 1);
        !           140: }

unix.superglobalmegacorp.com

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