Annotation of researchv10no/cmd/cfront/libC/task/obj.c, revision 1.1.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: object::~object()
                     15: {
                     16:        if (o_link) task_error(E_OLINK, this);
                     17:        if (o_next) task_error(E_ONEXT, this);
                     18: } /* delete */
                     19: 
                     20: /*     note that a task can be on a chain in several places
                     21: */
                     22: 
                     23: /* object::remember() ... */
                     24: 
                     25: void
                     26: object::forget(register task* p)
                     27: /* remove all occurrences of task* p from this object's task list */
                     28: {
                     29:        register olink* ll;
                     30:        register olink* l;
                     31: 
                     32:        if (o_link == 0) return;
                     33: 
                     34:        while (o_link->l_task == p) {
                     35:                ll = o_link;
                     36:                o_link = ll->l_next;
                     37:                delete ll;
                     38:                if (o_link == 0) return;
                     39:        };
                     40: 
                     41:        l = o_link;
                     42:        while (ll = l->l_next) {
                     43:                if (ll->l_task == p) {
                     44:                        l->l_next = ll->l_next;
                     45:                        delete ll;
                     46:                }
                     47:                else l = ll;
                     48:        };
                     49: }
                     50: 
                     51: 
                     52: /*
                     53:  * prepare IDLE tasks on this object for scheduling
                     54:  * also flush the remember chain
                     55:  */
                     56: void
                     57: object::alert()
                     58: {
                     59:        register olink* l;
                     60:        register olink* ll;
                     61: 
                     62:        for (l=o_link; ll = l; l=l->l_next, delete ll) {
                     63:                register task* p = l->l_task;
                     64:                if (p->s_state == IDLE) p->insert(0,this);
                     65:        }
                     66:        o_link = 0;
                     67: }
                     68: 
                     69: /*
                     70:  * virtual int object::pending() returns 1 if the object should be waited for.
                     71:  * By default say yes and assume that alert() will be called somehow.
                     72:  */
                     73: int
                     74: object::pending()
                     75: {
                     76:        return 1;
                     77: }
                     78: 
                     79: /*
                     80:  * object::print() is a virtual function.  In each derived class,
                     81:  * derived::print() will print the derived information,
                     82:  * then call its immediate base::print(), with second argument non-zero. 
                     83:  * The original virtual call will have the second argument 0.
                     84:  * The first arg is meant to be CHAIN, VERBOSE, or STACK, or several combined
                     85:  * with | (e.g., CHAIN|STACK)
                     86:  */
                     87: void
                     88: object::print(int n, int baseClass)
                     89: {
                     90:        if (!baseClass)
                     91:                printf("Unidentified object ");
                     92: 
                     93:        if (n&VERBOSE) {
                     94:                olink* l;
                     95:                printf("\tobject:  this=%x\n", this);
                     96:                if (!o_link)
                     97:                        printf("\tNo tasks remembered\n");
                     98:                for (l=o_link; l; l=l->l_next) {
                     99:                        printf("\tNext task on this=%x remember chain is:\n",
                    100:                                this);
                    101:                        l->l_task->print(n & ~CHAIN);
                    102:                }
                    103:        }
                    104: 
                    105:        if (n&CHAIN) {
                    106:                if (o_next) o_next->print(n);
                    107:        }
                    108:        printf("\n");
                    109: }
                    110: 
                    111: #define macro_start static char* error_name[] = {
                    112: #define macro(num,name,string) string,
                    113: #define macro_end(last_name) };
                    114: task_error_messages
                    115: #undef macro_start
                    116: #undef macro
                    117: #undef macro_end
                    118: 
                    119: static int in_error = 0;
                    120: 
                    121: void
                    122: sched::_print_error(int n)
                    123: {
                    124: 
                    125:        register i = (n<1 || MAXERR<n) ? 0 : n;
                    126: 
                    127:        printf("\n\n***** task_error(%d) %s\n",n,error_name[i]);
                    128: 
                    129:        if (object::this_task()) { 
                    130:                printf("thistask: ");
                    131:                thistask->print(VERBOSE|STACK);
                    132:        }
                    133:        if (sched::runchain) {
                    134:                printf("runchain:\n");
                    135:                sched::runchain->print(CHAIN);
                    136:        }
                    137: } /* _print_error */
                    138: 
                    139: // Obsolete version, remains for compatibility, use 2-argument static version
                    140: // instead
                    141: int
                    142: object::task_error(int n)
                    143: {
                    144:        if (in_error)
                    145:                exit(in_error);
                    146:        else
                    147:                in_error = n;
                    148: 
                    149:        if (error_fct) {
                    150:                n = (*error_fct)(n,this);
                    151:                if (n) exit(n);
                    152:        }
                    153:        else {
                    154:                sched::_print_error(n);
                    155:                exit(n);
                    156:        }
                    157:        in_error = 0;
                    158:        return 0;
                    159: }
                    160: //The second, static, version of the task_error function is usable by
                    161: //both member functions and non-member functions.
                    162: int
                    163: object::task_error(int n, object* th)
                    164: {
                    165:        if (in_error)
                    166:                exit(in_error);
                    167:        else
                    168:                in_error = n;
                    169: 
                    170:        if (error_fct) {
                    171:                n = (*error_fct)(n, th);
                    172:                                        //th is really a "this" pointer for real
                    173:                                        //objects, and is 0 for non-members
                    174:                if (n) exit(n);
                    175:        }
                    176:        else {
                    177:                sched::_print_error(n);
                    178:                exit(n);
                    179:        }
                    180:        in_error = 0;
                    181:        return 0;
                    182: }

unix.superglobalmegacorp.com

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