From: Rafał Długołęcki Date: Wed, 17 Jul 2013 07:49:50 +0000 (+0200) Subject: vlp-10 using coding style in procaddr.c X-Git-Tag: 3.1~34 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=1c8065c10f89994573ea0f3faee55575360b1cd5;p=vlp.git vlp-10 using coding style in procaddr.c --- diff --git a/src/int/procaddr.c b/src/int/procaddr.c index ab020da..4977c69 100644 --- a/src/int/procaddr.c +++ b/src/int/procaddr.c @@ -21,82 +21,70 @@ arr[1..3] : arr[1]=node, arr[2]=pix. */ -void obj2mess(M,obj,mess) - word *M; - virtaddr *obj; - procaddr *mess; +void obj2mess(word *M, virtaddr *obj, procaddr *mess) { #ifdef OBJECTADDR - word am; - if( obj->mark != M[obj->addr+1] ){ - mess->node=-1; - mess->pix =-1; - mess->mark=-1; - }else{ - am=M[obj->addr]; - mess->node=M[am+2]; - mess->pix =M[am+3]; - mess->mark=M[am+4]; - } + word am; + if(obj->mark != M[obj->addr + 1]){ + mess->node=-1; + mess->pix =-1; + mess->mark=-1; + } else { + am=M[obj->addr]; + mess->node=M[am + 2]; + mess->pix =M[am + 3]; + mess->mark=M[am + 4]; + } #else - mess->node=ldnode(obj->addr); - mess->pix =ldpix (obj->addr); - mess->mark=obj->mark; + mess->node=ldnode(obj->addr); + mess->pix =ldpix (obj->addr); + mess->mark=obj->mark; #endif } -void mess2obj(p,mess,obj) - procdescr *p; - procaddr *mess; - virtaddr *obj; +void mess2obj(procdescr *p, procaddr *mess, virtaddr *obj) { - #ifdef OBJECTADDR - - word am; - word *currM=M; - word currpix=thispix; - - extern int compactify_allowed; - compactify_allowed=0; - transfer(p-process); - hash_find(mess,obj); + word am; + word *currM = M; + word currpix = thispix; + + extern int compactify_allowed; + compactify_allowed = 0; + transfer(p - process); + hash_find(mess, obj); /* - newarry(1,4,APROCESS,obj,&am); - M[am+2]=mess->node; - M[am+3]=mess->pix; - M[am+4]=mess->mark; + newarry(1, 4, APROCESS, obj, &am); + M[am + 2]=mess->node; + M[am + 3]=mess->pix; + M[am + 4]=mess->mark; */ - transfer(currpix); - M=currM; + transfer(currpix); + M = currM; - compactify_allowed=1; + compactify_allowed = 1; #else - obj->addr=staddr(mess->node,mess->pix); - obj->mark=mess->mark; - + obj->addr=staddr(mess->node, mess->pix); + obj->mark=mess->mark; #endif - } -bool isprocess(v) virtaddr *v; { - +bool isprocess(virtaddr *v) { #ifdef OBJECTADDR - word am=M[v->addr]; - - /*assert(v->mark<=M[v->addr+1]);*/ - if( v->mark!=M[v->addr+1] ) { return 0;} - else { return ( M[am+1]==APROCESS );} - + word am = M[v->addr]; + + /*assert(v->mark<=M[v->addr+1]);*/ + if(v->mark != M[v->addr + 1] ) { + return 0; + } else { + return (M[am + 1] == APROCESS); + } #else - - return ( v->mark < 0 ); - + return (v->mark < 0); #endif - } @@ -106,107 +94,118 @@ bool isprocess(v) virtaddr *v; { /* hash entry is a word pointing to dictionary or 0 if empty */ #ifndef NO_PROTOTYPES -static int hash_check_item( word, procaddr * ); -static void hash_new_item( virtaddr *, procaddr * ); -static int hash_mess( procaddr * ); -static int hash_2( int ); +static int hash_check_item(word, procaddr *); +static void hash_new_item(virtaddr *, procaddr *); +static int hash_mess(procaddr *); +static int hash_2(int); #else static int hash_check_item(); static void hash_new_item(); #endif -void hash_create(p,size) procdescr *p; int size;{ - /* create hash table for p process */ - int i; - if( p->hash!=NULL ) free( p->hash ); - p->hash_size = size; - p->hash = mallocate(size); - if( p->hash==NULL ) errsignal(RTEMEMOV); - for( i=0; ihash_size; i++ ) p->hash[i]=0; +void hash_create(procdescr *p, int size) { + /* create hash table for p process */ + int i; + if (p->hash != NULL) + free(p->hash); + p->hash_size = size; + p->hash = mallocate(size); + if(p->hash == NULL) + errsignal(RTEMEMOV); + + for (i = 0; i < p->hash_size; i++) + p->hash[i] = 0; } -/* find pointer in hash table, add if not exists */ - -void hash_find(mess,obj) procaddr *mess; virtaddr *obj; { - int i,first,jump; - word am; - first=hash_mess( mess ); - jump=hash_2(first); - for( i=first; thisp->hash[i]!=0; ){ - if( hash_check_item(thisp->hash[i],mess) ){ - obj->addr=thisp->hash[i]; - obj->mark=M[thisp->hash[i]+1]; - return; - } - i=(i+jump)%thisp->hash_size; - if( i==first ){ - int *curhash=thisp->hash; - int cursize=thisp->hash_size; -errsignal(RTEMEMOV); /* the rest is not debugged yet */ - thisp->hash_size = cursize*3-1; - thisp->hash = mallocate(thisp->hash_size); - if( thisp->hash==NULL ) errsignal(RTEMEMOV); - for( i=0; ihash_size; i++ ) thisp->hash[i]=0; - for( i=0; iaddr ); - return; - } - } - /* not exists yet */ - hash_new_item( obj, mess ); - thisp->hash[i]=obj->addr; +/** + * find pointer in hash table, add if not exists + */ +void hash_find(procaddr *mess, virtaddr *obj) { + int i, first, jump; + word am; + first = hash_mess(mess); + jump = hash_2(first); + for (i = first; thisp->hash[i] != 0; ) { + if (hash_check_item(thisp->hash[i], mess)) { + obj->addr=thisp->hash[i]; + obj->mark=M[thisp->hash[i] + 1]; + return; + } + i = (i + jump) % thisp->hash_size; + if (i == first) { + int *curhash = thisp->hash; + int cursize = thisp->hash_size; + /* the rest is not debugged yet */ + errsignal(RTEMEMOV); + thisp->hash_size = cursize * 3 - 1; + thisp->hash = mallocate(thisp->hash_size); + if(thisp->hash == NULL) + errsignal(RTEMEMOV); + + for (i = 0; i < thisp->hash_size; i++) + thisp->hash[i] = 0; + + for (i = 0; i < cursize; i++) { + if( curhash[i]!=0 ){ + virtaddr obj; + procaddr mess; + obj.addr = curhash[i]; + obj.mark = M[curhash[i] + 1]; + obj2mess(M, &obj, &mess); + hash_set(&mess, curhash[i]); + } + } + hash_new_item(obj, mess); + hash_set(mess, obj->addr); + return; + } + } + /* not exists yet */ + hash_new_item(obj, mess); + thisp->hash[i] = obj->addr; } -void hash_set(mess,ah) procaddr *mess; word ah;{ - int i,first,jump; - word am; - first=hash_mess( mess ); - jump=hash_2(first); - for( i=first; thisp->hash[i]!=0; ){ - assert( !hash_check_item(thisp->hash[i],mess) ); - i=(i+jump)%thisp->hash_size; - if( i==first ) errsignal(RTEMEMOV); - } - /* not exists yet */ - assert( thisp->hash[i]==0 ); - thisp->hash[i]=ah; +void hash_set(procaddr *mess, word ah) { + int i, first, jump; + word am; + first = hash_mess(mess); + jump = hash_2(first); + for(i = first; thisp->hash[i] != 0; ) { + assert(!hash_check_item(thisp->hash[i], mess)); + i = (i + jump) % thisp->hash_size; + if(i == first) + errsignal(RTEMEMOV); + } + /* not exists yet */ + assert(thisp->hash[i] == 0); + thisp->hash[i] = ah; } #endif - -static int hash_check_item( ah, mess ) word ah; procaddr *mess; { - word am=M[ah]; - return ( mess->node==M[am+2] && mess->pix==M[am+3] && mess->mark==M[am+4] ); +static int hash_check_item(word ah, procaddr *mess) { + word am = M[ah]; + return (mess->node == M[am + 2] && mess->pix == M[am + 3] && + mess->mark == M[am + 4]); } -static void hash_new_item( obj, mess ) virtaddr *obj; procaddr *mess; { - word am; - newarry(1,4,APROCESS,obj,&am); - M[am+2]=mess->node; - M[am+3]=mess->pix; - M[am+4]=mess->mark; +static void hash_new_item(virtaddr *obj, procaddr *mess) { + word am; + newarry(1, 4, APROCESS, obj, &am); + M[am + 2] = mess->node; + M[am + 3] = mess->pix; + M[am + 4] = mess->mark; } -static int hash_mess( mess ) procaddr *mess;{ - word hash=mess->pix; - hash *= abs( mess->mark ); - hash += mess->node; - return hash % (thisp->hash_size); +static int hash_mess(procaddr *mess) { + word hash = mess->pix; + hash *= abs(mess->mark); + hash += mess->node; + return hash % (thisp->hash_size); } -static int hash_2( hash_1 ) int hash_1;{ - return thisp->hash_size -2 - ( hash_1 % ( thisp->hash_size -2 ) ); +static int hash_2( hash_1 ) hash_1;{ + return thisp->hash_size -2 - (hash_1 % (thisp->hash_size - 2)); }