|
|
1.1 root 1: #include "task.h"
2:
3: /* construct qtail <--> oqueue */
4: qtail.qtail(int mode, int max) : (QTAIL)
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 qtail.put(object* p)
27: {
28: register oqueue* q = qt_queue;
29: ll:
30: if (p->o_next) task_error(E_PUTOBJ,this);
31:
32: if (q->q_count < q->q_max) {
33: if (q->q_count++) {
34: register object* oo = q->q_ptr;
35: p->o_next = oo->o_next;
36: q->q_ptr = oo->o_next = p;
37: }
38: else {
39: qhead* h = q->q_head;
40: q->q_ptr = p->o_next = p;
41: if (h) h->alert();
42: }
43: return 1;
44: }
45:
46: switch (qt_mode) {
47: case WMODE:
48: remember(thistask);
49: thistask->sleep();
50: forget(thistask);
51: goto ll;
52: case EMODE:
53: task_error(E_PUTFULL,this);
54: goto ll;
55: case ZMODE:
56: return 0;
57: }
58: }
59:
60:
61: /* create head for this q */
62: qhead* 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* qtail.cut()
79: {
80: oqueue* oldq = qt_queue;
81: qtail* t = new qtail(qt_mode,oldq->q_max);
82: oqueue* newq = t->qt_queue;
83:
84: t->qt_queue = oldq;
85: oldq->q_tail = t;
86:
87: newq->q_tail = this;
88: qt_queue = newq;
89:
90: return t;
91: }
92:
93:
94: /* this qtail is supposed to be downstream from the qhead h */
95: void qtail.splice(qhead* h)
96: {
97: h->splice(this);
98: }
99:
100:
101: void qtail.print(int n)
102: {
103: int m = qt_queue->q_max;
104: int c = qt_queue->q_count;
105: class qhead * h = qt_queue->q_head;
106:
107: printf("qtail (%d): mode=%d, max=%d, space=%d, head=%d\n",
108: this,qt_mode,m,m-c,h);
109:
110: if (n&VERBOSE) {
111: int m = n & ~(CHAIN|VERBOSE);
112: if (h) {
113: printf("head of queue:\n");
114: h->print(m);
115: }
116:
117: qt_queue->print(m);
118: }
119: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.