C:/Users/Dennis/src/lang/russell.orig/src/stree/drefops.c

Go to the documentation of this file.
00001 /*
00002  * Full versions of chgfld, initfld, lock, and unlock
00003  */
00004 # include <stdio.h>
00005 # include "parm.h"
00006 
00007 # include "stree/ststructs.mh"
00008 
00009 # include "is_ptr.h"
00010 
00011 # define MINPTR 10     /* minimum "real" pointer value */
00012 
00013 int retaddr();
00014 
00015 # ifdef UNDEFINED
00016 NODE * lock();
00017 
00018 /*
00019  *  chgfld(pp,v)
00020  *
00021  *  *pp is a field in a node, v is the new value for that field.
00022  *  If *pp is not NIL, decrement refcount of **pp.
00023  *  Stick v into *pp, and inc refcount of *v if not NIL.
00024  *  Free the old **pp if appropriate.
00025  *  Assumes that the new and old field values are different.
00026  */
00027 chgfld(pp, v)
00028 NODE **pp;
00029 register NODE *v;
00030 {   register NODE **rpp = pp;
00031 
00032     /* Make sure that rpp is a pointer */
00033 #       ifdef DEBUG
00034             if (!is_ptr(rpp)) {
00035                 dbgmsg("chgfld: argument not a pointer: value=0x%x, retaddr=0x%x\n",
00036                         rpp, retaddr());
00037                 abort();
00038             }
00039 #       endif
00040     /* If old value for *pp is not NIL, decrement refcount and free if zero. */
00041         if ( *rpp != NIL) {
00042             unlock(*rpp);
00043             if ( ((*rpp)->refcount) <= 0 && (v != *rpp) )
00044                 vfree(*rpp);
00045         }
00046 
00047     /* Put new value into field and if v is not NIL etc., inc *v's refcount. */
00048         if ( (*rpp = v) > MINPTR ) {
00049             /* Check if *v has been freed. */
00050 #             ifdef DEBUG
00051                 if ( *v > 10000 ) {
00052                     dbgmsg("chgfld: new field value already freed: nvalue=0x%x, kind=%s, retaddr=0x%x\n",
00053                             *v, kindname(v->kind), retaddr());
00054                     abort();
00055                 }
00056 #             endif
00057             (void) lock(v);
00058         }
00059 }
00060 
00061 /*
00062  *  initfld(pp,v)
00063  *
00064  *  *pp is a field in a node, v is its new value.
00065  *  Stick v into *pp, then if v is not NIL, inc *v's refcount.
00066  */
00067 initfld(pp,v)
00068 NODE **pp;
00069 register NODE *v;
00070 {   register NODE * rpp = pp;
00071 
00072     /* Check that rpp is a pointer */
00073 #     ifdef DEBUG
00074         if (!is_ptr(rpp)) {
00075             dbgmsg("initfld: argument not a pointer: value=0x%x, retaddr=0x%x\n",
00076                    rpp, retaddr());
00077             abort();
00078         }
00079 #     endif
00080     if ( (*rpp = v) > MINPTR) {
00081         (void) lock(v);
00082     }
00083 }
00084 
00085 
00086 /*
00087  * lock(p)
00088  *
00089  * p is a node. If p is not NIL, increment its ref count.
00090  * Return p.
00091  */
00092 NODE *
00093 lock(p)
00094 NODE *p;
00095 {   register NODE *rp = p;
00096 
00097     if ( rp != NIL ) {
00098 #     ifdef DEBUG
00099         /* Make sure that rp is a pointer */
00100             if (!is_ptr(rp)) {
00101                 dbgmsg("lock: argument not a pointer: value=0x%x, retaddr=0x%x\n",
00102                         rp, retaddr());
00103                 abort();
00104             }
00105         /* Check if rp has been freed. */
00106             if ( *rp != 0 && is_ptr(*rp) ) {
00107                 dbgmsg("lock: node has been freed: node addr=0x%x, kind=%s, retaddr=0x%x\n",
00108                         rp, kindname(p->kind), retaddr());
00109                 abort();
00110             }
00111         /* Make sure the reference count is reasonable */
00112             if (((unsigned)(rp -> refcount)) > 1000) {
00113                 dbgmsg("lock: node has bad refcount: node addr=0x%x, refcount=%d, kind=%s, retaddr=0x%x\n",
00114                         rp, p -> refcount, kindname(p->kind), retaddr());
00115                 fflush(stdout); fflush(stderr); prtree(rp);
00116                 abort();
00117             }
00118 #     endif
00119       ++(rp->refcount);
00120     }
00121     return(rp);
00122 }                      
00123 
00124 /*
00125  * unlock(p)
00126  *
00127  * *p is a node. Decrement its refcount.
00128  */
00129 unlock(p)
00130 NODE *p;
00131 {   register NODE * rp = p;
00132 
00133     /* reserves space to add debugging instruction */
00134 #     ifdef DEBUG
00135         if (p == 0xffffffff) {
00136             printf("sleeping\n");
00137             sleep(3);
00138         }
00139 #     endif
00140     if ( rp != NIL ) {
00141 #     ifdef DEBUG
00142         /* Make sure that rp is a pointer */
00143             if (!is_ptr(rp)) {
00144                 dbgmsg("unlock: argument not a pointer: value=0x%x, retaddr=0x%x\n",
00145                         rp, retaddr());
00146                 abort();
00147             }
00148         /* Check if rp has been freed. */
00149             if ( *rp != 0 && is_ptr(*rp) ) {
00150                 dbgmsg("unlock: node has been freed: node addr=0x%x, kind=%s, retaddr=0x%x\n",
00151                         rp, kindname(p->kind), retaddr());
00152                 abort();
00153             }
00154         /* Make sure the reference count is reasonable */
00155             if (((unsigned)(rp -> refcount)) > 1000) {
00156                 dbgmsg("unlock: node has bad refcount: node addr=0x%x, refcount=%d, kind=%s, retaddr=0x%x\n",
00157                         rp, p -> refcount, kindname(p->kind), retaddr());
00158                 abort();
00159             }
00160 #     endif
00161       --(rp->refcount);
00162     }
00163     return(rp);
00164 }
00165 
00166 #endif
00167 /* The following are included only so main doesn't have to include */
00168 /* streedefs.h                                                     */
00169 
00170 NODE * bld_den_seq_f(b)
00171 NODE * b;
00172 {
00173     return(b -> bld_den_seq);
00174 }
00175 
00176 NODE * signature_f(x)
00177 NODE * x;
00178 {
00179     return(x -> signature);
00180 }
00181 
00182 NODE * first_elmnt(x)
00183 NODE * x;
00184 {
00185     return(first(x));
00186 }
00187 

Generated on Fri Jan 25 10:39:48 2008 for russell by  doxygen 1.5.4