From: Rafał Długołęcki Date: Sun, 21 Jul 2013 19:30:20 +0000 (+0200) Subject: vlp-10 using coding style in rpcall.c X-Git-Tag: 3.1~28 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=7e24c73683b7ac18e78363e0b22e76d19cf860a6;p=vlp.git vlp-10 using coding style in rpcall.c --- diff --git a/src/int/rpcall.c b/src/int/rpcall.c index 2fd562c..49db727 100644 --- a/src/int/rpcall.c +++ b/src/int/rpcall.c @@ -1,14 +1,14 @@ -#include "depend.h" -#include "genint.h" -#include "int.h" -#include "process.h" -#include "intproto.h" +#include "depend.h" +#include "genint.h" +#include "int.h" +#include "process.h" +#include "intproto.h" #ifndef NO_PROTOTYPES static bool isenabled(word,word); static bool rpcready(word); -static void bitaccess(word,word,int *,char *); +static void bitaccess(word, word, int *, char *); static void dupmask(word); #else static bool isenabled(); @@ -17,249 +17,278 @@ static void bitaccess(); static void dupmask(); #endif - -void rpc1(msg) /* preprocess RPC request */ -message *msg; +/** + * preprocess RPC request + */ +void rpc1(message *msg) { - word pix, prot; - procdescr *p; - message *msg1; - - pix = msg->control.receiver.pix; - p = &process[ pix ]; - if (p->mark != msg->control.receiver.mark) - senderr(RTEREFTN, &msg->control.sender); - msg1 = (message *) ballocate(sizeof(message)); - if (msg1 == NULL) errsignal(RTEMEMOV); - moveblock((char *) msg, (char *) msg1, (word) sizeof(message)); - prot = msg->control.par; - if (isenabled(pix, prot)) - { - p->msgqueue = minsert(p->msgqueue, msg1); - if (p->status == ACCEPTING) activate(pix); - } - else p->rpcwait = minsert(p->rpcwait, msg1); + word pix, prot; + procdescr *p; + message *msg1; + + pix = msg->control.receiver.pix; + p = &process[pix]; + if (p->mark != msg->control.receiver.mark) + senderr(RTEREFTN, &msg->control.sender); + + msg1 = (message *) ballocate(sizeof(message)); + + if (msg1 == NULL) + errsignal(RTEMEMOV); + + moveblock((char *) msg, (char *) msg1, (word) sizeof(message)); + prot = msg->control.par; + if (isenabled(pix, prot)) { + p->msgqueue = minsert(p->msgqueue, msg1); + + if (p->status == ACCEPTING) + activate(pix); + } + else + p->rpcwait = minsert(p->rpcwait, msg1); } void rpc2() { - if (rpcready(thispix)) rpc3(); + if (rpcready(thispix)) + rpc3(); } - -void rpc3() /* Actual remote procedure call */ +/** + * Actual remote procedure call + */ +void rpc3() { - word prot, ah, am; - message *msg; + word prot, ah, am; + message *msg; - msg = mfront(thisp->msgqueue); /* remove first RPC message (enabled) */ + /* remove first RPC message (enabled) */ + msg = mfront(thisp->msgqueue); - /*fprintf( - stderr, "rpc(thisp=%d) from: node=%d, pix=%d, mark=%d\n", - thispix, - msg->control.sender.node, - msg->control.sender.pix, - msg->control.sender.mark - );*/ + /* + fprintf(stderr, "rpc(thisp=%d) from: node=%d, pix=%d, mark=%d\n", + thispix, + msg->control.sender.node, + msg->control.sender.pix, + msg->control.sender.mark + );*/ - thisp->msgqueue = qremove(thisp->msgqueue); - pushmask(thispix); /* disable all procedures */ - prot = msg->control.par; + thisp->msgqueue = qremove(thisp->msgqueue); + /* disable all procedures */ + pushmask(thispix); + prot = msg->control.par; - slopen(prot, &thisp->procref, &ah, &am); /* open procedure object */ + /* open procedure object */ + slopen(prot, &thisp->procref, &ah, &am); - { - virtaddr v; - mess2obj( thisp, &(msg->control.sender), &v ); - storevirt( v, am+M[ am ]+RPCDL ); /* set up remote DL */ - } + { + virtaddr v; + mess2obj(thisp, &(msg->control.sender), &v); + /* set up remote DL */ + storevirt(v, am + M[am] + RPCDL); + } - moveparams(thispix, am, msg, PARIN, SAVEPAR); + moveparams(thispix, am, msg, PARIN, SAVEPAR); - go(ah, am); /* transfer control to procedure */ - - free(msg); + /* transfer control to procedure */ + go(ah, am); + free(msg); } - -void rpcend(msg) /* After return from RPC */ -message *msg; +/* After return from RPC */ +void rpcend(message *msg) { - word pix, am; - procdescr *p; + word pix, am; + procdescr *p; - pix = msg->control.receiver.pix; + pix = msg->control.receiver.pix; - p = &process[ pix ]; - am = p->M[ temporary ]; /* template physical address */ - moveparams(pix, am, msg, PAROUT, SAVEPAR); - activate(pix); /* resume process waiting for RPC */ + p = &process[pix]; + /* template physical address */ + am = p->M[temporary]; + moveparams(pix, am, msg, PAROUT, SAVEPAR); + /* resume process waiting for RPC */ + activate(pix); } -static void bitaccess(pix, prot, bytenr, bitmask) -word pix, prot; -int *bytenr; -char *bitmask; +static void bitaccess(word pix, word prot, int *bytenr, char *bitmask) { - int bitnr; + int bitnr; - bitnr = prot-prototype[ process[ pix ].prot ]->maskbase; - *bytenr = bitnr / 8; - *bitmask = (char)(unsigned char)( 1 << (bitnr % 8) ); + bitnr = prot-prototype[process[pix].prot]->maskbase; + *bytenr = bitnr / 8; + *bitmask = (char)(unsigned char)(1 << (bitnr % 8)); } - -void enable(pix, prot) /* Enable remote procedure */ -word pix, prot; +/* Enable remote procedure */ +void enable(word pix, word prot) { - mask m; - int bytenr; - char bitmask; + mask m; + int bytenr; + char bitmask; - m = top(process[ pix ].rpcmask); - bitaccess(pix, prot, &bytenr, &bitmask); - m[ bytenr ] |= bitmask; + m = top(process[pix].rpcmask); + bitaccess(pix, prot, &bytenr, &bitmask); + m[bytenr] |= bitmask; } - -void disable(pix, prot) /* Disable remote procedure */ -word pix, prot; +/** + * Disable remote procedure + */ +void disable(word pix, word prot) { - mask m; - int bytenr; - char bitmask; + mask m; + int bytenr; + char bitmask; - m = top(process[ pix ].rpcmask); - bitaccess(pix, prot, &bytenr, &bitmask); - m[ bytenr ] &= ~ bitmask; + m = top(process[pix].rpcmask); + bitaccess(pix, prot, &bytenr, &bitmask); + m[bytenr] &= ~ bitmask; } - -static bool isenabled(pix, prot) /* Check if RPC allowed */ -word pix, prot; +/** + * Check if RPC allowed + */ +static bool isenabled(word pix, word prot) { - mask m; - int bytenr; - char bitmask; + mask m; + int bytenr; + char bitmask; - m = top(process[ pix ].rpcmask); - bitaccess(pix, prot, &bytenr, &bitmask); - return( m[ bytenr ] & bitmask ); + m = top(process[pix].rpcmask); + bitaccess(pix, prot, &bytenr, &bitmask); + return m[bytenr] & bitmask; } - -void pushmask(pix) /* Push empty RPC mask onto stack */ -word pix; +/** + * Push empty RPC mask onto stack + */ +void pushmask(word pix) { - mask m; - int i, size; - - size = prototype[ process[ pix ].prot ]->masksize; - m = (mask) ballocate(size); - if (m == NULL) errsignal(RTEMEMOV); - for (i = 0; i < size; i++ ) m[ i ] = '\0'; /* disable all */ - process[ pix ].rpcmask = push(process[ pix ].rpcmask, m); + mask m; + int i, size; + + size = prototype[process[pix].prot]->masksize; + m = (mask) ballocate(size); + if (m == NULL) + errsignal(RTEMEMOV); + for (i = 0; i < size; i++) { + /* disable all */ + m[i] = '\0'; + } + process[pix].rpcmask = push(process[pix].rpcmask, m); } - -static void dupmask(pix) /* Duplicate RPC mask from stack top */ -word pix; +/** + * Duplicate RPC mask from stack top + */ +static void dupmask(word pix) { - mask m; - int size; - - size = prototype[ process[ pix ].prot ]->masksize; - m = (mask) ballocate(size); - if (m == NULL) errsignal(RTEMEMOV); - moveblock(top(process[ pix ].rpcmask), m, (word) size); - process[ pix ].rpcmask = push(process[ pix ].rpcmask, m); + mask m; + int size; + + size = prototype[process[pix].prot]->masksize; + m = (mask) ballocate(size); + if (m == NULL) + errsignal(RTEMEMOV); + moveblock(top(process[pix].rpcmask), m, (word) size); + process[pix].rpcmask = push(process[pix].rpcmask, m); } - -void popmask(pix) /* Pop RPC mask from stack (restore) */ -word pix; +/** + * Pop RPC mask from stack (restore) + */ +void popmask(word pix) { - mask m; + mask m; - m = top(process[ pix ].rpcmask); - process[ pix ].rpcmask = pop(process[ pix ].rpcmask); - free((char *) m); + m = top(process[pix].rpcmask); + process[pix].rpcmask = pop(process[pix].rpcmask); + free((char *) m); } - -void evaluaterpc(pix) /* Check if any waiting RPC is enabled */ -word pix; +/** + * Check if any waiting RPC is enabled + */ +void evaluaterpc(word pix) { - queue q; - message *msg; - - q = process[ pix ].rpcwait; - if (!qempty(q)) - { - do - { - msg = mfront(q); - if (isenabled(pix, msg->control.par)) - { - process[ pix ].msgqueue = mpush(process[ pix ].msgqueue, msg); - process[ pix ].rpcwait = mdelete(process[ pix ].rpcwait, msg); - return; - } - q = qrotate(q); - } while (q != process[ pix ].rpcwait); - } + queue q; + message *msg; + + q = process[pix].rpcwait; + if (!qempty(q)) { + do { + msg = mfront(q); + if (isenabled(pix, msg->control.par)) { + process[pix].msgqueue = + mpush(process[pix].msgqueue, msg); + process[pix].rpcwait = + mdelete(process[pix].rpcwait, msg); + return; + } + q = qrotate(q); + } while (q != process[pix].rpcwait); + } } - -void rpc_accept(length) /* Accept remote procedure call */ -word length; +/** + * Accept remote procedure call + */ +void rpc_accept(word length) { - int i; - - dupmask(thispix); - for (i = 0; i < length; i++) - enable(thispix, virtprot(M[ ic++ ])); - evaluaterpc(thispix); - if (!rpcready(thispix)) - passivate(ACCEPTING); + int i; + + dupmask(thispix); + for (i = 0; i < length; i++) + enable(thispix, virtprot(M[ic++])); + + evaluaterpc(thispix); + + if (!rpcready(thispix)) + passivate(ACCEPTING); } -static bool rpcready(pix) -word pix; +static bool rpcready(word pix) { - procdescr *p; - message *msg; - word prot; - - p = &process[ pix ]; - while (!qempty(p->msgqueue)) - { - msg = mfront(p->msgqueue); - prot = msg->control.par; - if (isenabled(pix, prot)) return(TRUE); - p->msgqueue = qremove(p->msgqueue); - p->rpcwait = minsert(p->rpcwait, msg); - } - return(FALSE); + procdescr *p; + message *msg; + word prot; + + p = &process[pix]; + while (!qempty(p->msgqueue)) { + msg = mfront(p->msgqueue); + prot = msg->control.par; + if (isenabled(pix, prot)) + return TRUE; + p->msgqueue = qremove(p->msgqueue); + p->rpcwait = minsert(p->rpcwait, msg); + } + return FALSE; } - -word virtprot(prot) /* Get actual prototype for virtual */ -word prot; +/** + * Get actual prototype for virtual + */ +word virtprot(word prot) { - bool sign; - word virtnr; - - sign = (prot < 0); - prot = absolute(prot); - virtnr = prototype[ prot ]->virtnumber; - if (virtnr != -1) prot = M[ prototype[ thisp->prot ]->virtlist+virtnr ]; - if (sign) return(-prot); else return(prot); + bool sign; + word virtnr; + + sign = (prot < 0); + prot = absolute(prot); + virtnr = prototype[ prot ]->virtnumber; + if (virtnr != -1) + prot = M[prototype[thisp->prot]->virtlist + virtnr]; + + if (sign) + return -prot; + else + return prot; }