no hdef(register no pred, register no fun, register no val, byte stamp) { register no i=HKEY(pred,fun),last; HLIMIT(last); while(HNOTFULL() && HUSED() && !(HFOUND())) HASH_NEXT(); if(!HUSED() || (HDELETED() && HFOUND()) ) { HPUT(i,pred,fun,val,stamp); return 1; } return 0; }
bp_long hindex(register no pred, register no fun, bp_long *index) { register no last,i=HKEY(pred,fun); if(HFOUND()) {*index=i; return FOUND;} if(!HUSED()) {*index=i; return FREE;} HLIMIT(last); do { HASH_NEXT(); if(HFOUND()) {*index=i; return FOUND;} } while(HNOTFULL() && HUSED()); if(!HNOTFULL()) {hfull("culprit->hindex"); return FULL;} else {*index=i; return FREE;} }
static int handles_proc(struct proc_file *pf, void *arg) { static char *objtype[OBJECT_TYPES] = {"THREAD", "EVENT", "TIMER", "MUTEX", "SEM", "FILE", "SOCKET", "IOMUX", "FILEMAP"}; int h; int i; struct object *o; int objcount[OBJECT_TYPES]; for (i = 0; i < OBJECT_TYPES; i++) objcount[i] = 0; pprintf(pf, "handle addr s p type count locks\n"); pprintf(pf, "------ -------- - - ------- ----- -----\n"); for (h = 0; h < htabsize; h++) { if (!HUSED(htab[h])) continue; o = HOBJ(htab[h]); pprintf(pf, "%6d %8X %d %d %-7s %5d %5d\n", h, o, o->signaled, HPROT(htab[h]), objtype[o->type], o->handle_count, o->lock_count); if (o->handle_count != 0) objcount[o->type] += FRAQ / o->handle_count; } pprintf(pf, "\n"); for (i = 0; i < OBJECT_TYPES; i++) { if (objcount[i] > 0) { pprintf(pf, "%s:%d ", objtype[i], objcount[i] / FRAQ); } } pprintf(pf, "\n"); return 0; }
int hassign(struct object *o, handle_t h) { int rc; if (h > HTABSIZE / sizeof(handle_t)) return -EBADF; while (htabsize <= h) { rc = expand_htab(); if (rc < 0) return rc; } if (!HUSED(htab[h])) { // Not allocated, remove from freelist rc = remove_from_freelist(h); if (rc < 0) return rc; } else { // Handle already allocated, free handle struct object *oo = HOBJ(htab[h]); if (HPROT(htab[h])) return -EACCES; if (--oo->handle_count == 0) { rc = close_object(oo); if (oo->lock_count == 0) destroy_object(oo); if (rc < 0) return rc; } } // Assign handle to object htab[h] = (handle_t) o; o->handle_count++; return 0; }
no hget(register no pred, register no fun) { register no last,i=HKEY(pred,fun); if(HFOUND()) return htable[i].val; HLIMIT(last); do { HASH_NEXT(); if(HFOUND()) return htable[i].val; } while(HNOTFULL() && HUSED()); return (no)NULL; }
no hset(register no pred, register no fun, register no val) { register no i=HKEY(pred,fun),last; HLIMIT(last); while(HNOTFULL() && HUSED() && !(HFOUND())) HASH_NEXT(); if(HFOUND()) { htable[i].val=val; return 1; } warnmes("hdef/3 required before using hset/3"); #if 0 fprintf(STD_err,"%s/%ld+...->%s/%ld\n", NAME(pred),GETARITY(pred), NAME(val),GETARITY(val) ); #endif return 0; }
static int files_proc(struct proc_file *pf, void *arg) { int h; struct object *o; struct file *filp; char perm[11]; pprintf(pf, "handle flags mode uid gid type path\n"); pprintf(pf, "------ -------- ---------- --- --- -------- ----------------------------------\n"); for (h = 0; h < htabsize; h++) { if (!HUSED(htab[h])) continue; o = HOBJ(htab[h]); if (o->type != OBJECT_FILE) continue; filp = (struct file *) o; strcpy(perm, " ---------"); switch (filp->mode & S_IFMT) { case S_IFREG: perm[0] = '-'; break; case S_IFLNK: perm[0] = 'l'; break; case S_IFDIR: perm[0] = 'd'; break; case S_IFBLK: perm[0] = 'b'; break; case S_IFCHR: perm[0] = 'c'; break; case S_IFPKT: perm[0] = 'p'; break; } if (filp->mode & 0400) perm[1] = 'r'; if (filp->mode & 0200) perm[2] = 'w'; if (filp->mode & 0100) perm[3] = 'x'; if (filp->mode & 0040) perm[4] = 'r'; if (filp->mode & 0020) perm[5] = 'w'; if (filp->mode & 0010) perm[6] = 'x'; if (filp->mode & 0004) perm[7] = 'r'; if (filp->mode & 0002) perm[8] = 'w'; if (filp->mode & 0001) perm[9] = 'x'; pprintf(pf, "%6d %08X %s %3d %3d %-8s %s\n", h, filp->flags, perm, filp->owner, filp->group, filp->fs->fsys->name, filp->path ? filp->path : "<no name>"); } return 0; }
term hlist(register term H, register term regs, stack wam) { no i; cell xval; bp_long ival; byte stamp; #if TRACE>0 fprintf(STD_err,"entering hlist, wam=%d, bboard=%d H=%d\n", wam,g.shared[BBoardStk].base,H); bbcheck(wam); #endif if(!INTEGER(X(1))) return NULL; /* first arg: stamp */ stamp=(byte)(OUTPUT_INT(X(1))); xval=X(2); /* second arg: starting arity of listed terms */ if(!INTEGER(xval)) return NULL; ival=OUTPUT_INT(xval); for(i=0; i<HMAX; i++) if(hstamp[i]>=stamp && HUSED()) { term xref=C2T(g.predmark); if(hstamp[i]<=RUNTIME) { /* gets preds of arity < ival `represented' as g.predmark*/ if(g.predmark!=htable[i].pred || GETARITY(htable[i].fun)<(no)ival) continue; xval=g.predmark; } else { /* gets RUNTIME data of arity > ival */ cell v=htable[i].val; if(NULL==(term)v) continue; if(VAR(v) && !( ONSTACK(g.shared[BBoardStk],v) || ONSTACK(g.shared[InstrStk],v) /*|| ON(HeapStk,v) */ )) { #if TRACE>0 fprintf(STD_err, "unexpected data in htable[%d]=>\n<%s,%s>->%s\n",i, smartref(htable[i].pred,wam), smartref(htable[i].fun,wam), smartref(v,wam)); #endif /* continue; */ } FDEREF(v); if((INTEGER(xval) && ival>0) || VAR(xval) || (GETARITY(xval) < (no)ival) || xval==g.empty ) continue; if(COMPOUND(xval)) xval=T2C(xref); } IF_OVER("COPY_KEYS",(term *)H,HeapStk,bp_halt(9)); SAVE_FUN(htable[i].pred); SAVE_FUN(htable[i].fun); #if 0 ASSERT2(( ATOMIC(xval) || ONSTACK(g.shared[BBoardStk],xval) || ON(HeapStk,xval)), /* will fail with multiple engines */ xval); #endif PUSH_LIST(xval); } PUSH_NIL(); return H; }
struct object *hlookup(handle_t h) { if (h < 0 || h >= htabsize) return NULL; if (!HUSED(htab[h])) return NULL; return HOBJ(htab[h]); }