Annotation of researchv10no/cmd/cfront/libC/otask/qtail.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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