void putimage(Image *i) { Image *f, **l; Chan *c; if(i->notext) return; lock(i); if(--i->ref == 0) { l = &ihash(i->qid.path); mkqid(&i->qid, ~0, ~0, QTFILE); unlock(i); c = i->c; lock(&imagealloc); for(f = *l; f; f = f->hash) { if(f == i) { *l = i->hash; break; } l = &f->hash; } i->next = imagealloc.free; imagealloc.free = i; unlock(&imagealloc); ccloseq(c); /* does not block */ return; } unlock(i); }
static any initSym(any v, char *s) { any x, *h; h = Intern + ihash(x = mkName(s)); x = consSym(v,x); *h = cons(x,*h); return x; }
void putimage(Image *i) { Chan *c, **cp; Image *f, **l; if(i->notext) return; lock(i); if(--i->ref == 0) { l = &ihash(i->qid.path); mkqid(&i->qid, ~0, ~0, QTFILE); unlock(i); c = i->c; lock(&imagealloc); for(f = *l; f; f = f->hash) { if(f == i) { *l = i->hash; break; } l = &f->hash; } i->next = imagealloc.free; imagealloc.free = i; /* defer freeing channel till we're out of spin lock's */ if(imagealloc.nfreechan == imagealloc.szfreechan){ imagealloc.szfreechan += NFREECHAN; cp = malloc(imagealloc.szfreechan*sizeof(Chan*)); if(cp == nil) panic("putimage"); memmove(cp, imagealloc.freechan, imagealloc.nfreechan*sizeof(Chan*)); free(imagealloc.freechan); imagealloc.freechan = cp; } imagealloc.freechan[imagealloc.nfreechan++] = c; unlock(&imagealloc); return; } unlock(i); }
struct inode *nilfs_gc_iget(struct the_nilfs *nilfs, ino_t ino, __u64 cno) { struct hlist_head *head = nilfs->ns_gc_inodes_h + ihash(ino, cno); struct hlist_node *node; struct inode *inode; hlist_for_each_entry(inode, node, head, i_hash) { if (inode->i_ino == ino && NILFS_I(inode)->i_cno == cno) return inode; } inode = alloc_gcinode(nilfs, ino, cno); if (likely(inode)) { hlist_add_head(&inode->i_hash, head); list_add(&NILFS_I(inode)->i_dirty, &nilfs->ns_gc_inodes); } return inode; }
static Integer get_index_tab(CTXTdeclc FILE *fd, int clause_no) { Integer hashval, size, j; Integer count = 0; byte type ; CPtr label; Integer ival; Cell val; Integer dummy; /* used to squash warnings */ size = hsize(clause_no); indextab = (struct hrec *)mem_alloc(size*sizeof(struct hrec),COMPILED_SPACE); for (j = 0; j < size; j++) { indextab[j].l = 0; indextab[j].link = (CPtr)&(indextab[j].link); } for (j = 0; j < clause_no; j++) { dummy = get_obj_byte(&type); switch (type) { case 'i': get_obj_word_bbsig_notag(&ival); hashval = ihash((Cell) ival, size); count += 9; break; case 'f': get_obj_word_bbsig_notag(&ival); // printf("sfloat: %f, %x\n",(*(float *)(&ival)), (*(Integer *)(&ival)) ); #ifndef FAST_FLOATS val = float_val_to_hash(*(float *)(&ival)); #else val = ival; #endif hashval = ihash((Cell) val, size); count += 9; break; case 'd': { double fval; dummy = get_obj_string(&fval,8); #ifndef FAST_FLOATS val = float_val_to_hash(fval); #else { union { long intp; float fltp; } cvtr; cvtr.fltp = (float)fval; val = cvtr.intp; } #endif // printf("bld float index: %2.14f, %0x, size=%d\n",fval,val,size); hashval = ihash((Cell) val, size); count += 9; break; } case 'l': hashval = ihash((Cell)(list_pscPair), size); count += 5; break; case 'n': hashval = ihash((Cell) 0, size); count += 5; break; case 'c': get_obj_word_bb(&ival); count += 9; val = (Cell)ival ; st_pscname(&val); hashval = ihash(val, size) ; break; case 's': get_obj_word_bb(&ival); count += 9; val = (Cell)ival ; st_ptrpsc(&val); hashval = ihash(val, size) ; break; default: hashval = 0; xsb_exit( "illegal format"); } get_obj_word_bbsig_notag(&label); label = reloc_addr((Integer)label, seg_text(current_seg)); inserth(label, &indextab[hashval]); } return count; }
Image* attachimage(int type, Chan *c, ulong base, ulong len) { Image *i, **l; lock(&imagealloc); /* * Search the image cache for remains of the text from a previous * or currently running incarnation */ for(i = ihash(c->qid.path); i; i = i->hash) { if(c->qid.path == i->qid.path) { lock(i); if(eqqid(c->qid, i->qid) && eqqid(c->mqid, i->mqid) && c->mchan == i->mchan && c->type == i->type) { goto found; } unlock(i); } } /* * imagereclaim dumps pages from the free list which are cached by image * structures. This should free some image structures. */ while(!(i = imagealloc.free)) { unlock(&imagealloc); imagereclaim(); if(!imagealloc.free){ freebroken(); /* can use the memory */ resrcwait("no image after reclaim"); } lock(&imagealloc); } imagealloc.free = i->next; lock(i); incref(c); c->flag &= ~CCACHE; i->c = c; i->type = c->type; i->qid = c->qid; i->mqid = c->mqid; i->mchan = c->mchan; l = &ihash(c->qid.path); i->hash = *l; *l = i; found: unlock(&imagealloc); if(i->s == 0) { i->ref++; if(waserror()) { unlock(i); putimage(i); nexterror(); } i->s = newseg(type, base, len); i->s->image = i; poperror(); } else incref(i->s); return i; }
Image* attachimage(int type, Chan *c, int color, uintptr base, usize len) { Image *i, **l; /* reclaim any free channels from reclaimed segments */ if(imagealloc.nfreechan) imagechanreclaim(); lock(&imagealloc); /* * Search the image cache for remains of the text from a previous * or currently running incarnation */ for(i = ihash(c->qid.path); i; i = i->hash) { if(c->qid.path == i->qid.path) { lock(i); if(eqqid(c->qid, i->qid) && eqqid(c->mqid, i->mqid) && c->mchan == i->mchan && c->dev->dc == i->dc) { //subtype goto found; } unlock(i); } } /* * imagereclaim dumps pages from the free list which are cached by image * structures. This should free some image structures. */ while(!(i = lruimage())) { unlock(&imagealloc); imagereclaim(); sched(); lock(&imagealloc); } lock(i); incref(c); i->c = c; i->dc = c->dev->dc; //subtype i->qid = c->qid; i->mqid = c->mqid; i->mchan = c->mchan; i->color = color; l = &ihash(c->qid.path); i->hash = *l; *l = i; found: imageused(i); unlock(&imagealloc); if(i->s == 0) { /* Disaster after commit in exec */ if(waserror()) { unlock(i); pexit(Enovmem, 1); } i->s = newseg(type, base, len); i->s->image = i; i->s->color = color; i->ref++; poperror(); } else incref(i->s); return i; }
Image* attachimage(int type, Chan *c, ulong base, ulong len) { Image *i, **l; /* reclaim any free channels from reclaimed segments */ if(imagealloc.nfreechan) imagechanreclaim(); lock(&imagealloc.lk); /* * Search the image cache for remains of the text from a previous * or currently running incarnation */ for(i = ihash(c->qid.path); i; i = i->hash) { if(c->qid.path == i->qid.path) { lock(&i->ref.lk); if(eqqid(c->qid, i->qid) && eqqid(c->mqid, i->mqid) && c->mchan == i->mchan && c->type == i->type) { goto found; } unlock(&i->ref.lk); } } /* * imagereclaim dumps pages from the free list which are cached by image * structures. This should free some image structures. */ while(!(i = imagealloc.free)) { unlock(&imagealloc.lk); imagereclaim(); sched(); lock(&imagealloc.lk); } imagealloc.free = i->next; lock(&i->ref.lk); incref(&c->ref); i->c = c; i->type = c->type; i->qid = c->qid; i->mqid = c->mqid; i->mchan = c->mchan; l = &ihash(c->qid.path); i->hash = *l; *l = i; found: unlock(&imagealloc.lk); if(i->s == 0) { /* Disaster after commit in exec */ if(waserror()) { unlock(&i->ref.lk); pexit(Enovmem, 1); } i->s = newseg(type, base, len); i->s->image = i; i->ref.ref++; poperror(); } else incref(&i->s->ref); return i; }