Ejemplo n.º 1
0
/*
 * The RWlock is used as expected except that we allow
 * inc() to be called while holding it.  This is because we're
 * locking changes to the tree structure, not to the references.
 * Inc() is expected to have its own locking.
 */
void*
lookupkey(Intmap *map, ulong id)
{
	Intlist *f;
	void *v;

	rlock(map);
	if(f = *llookup(map, id)){
		v = f->aux;
		map->inc(v);
	}else
		v = nil;
	runlock(map);
	return v;
}
Ejemplo n.º 2
0
/*
 * The RWlock is used as expected except that we allow
 * inc() to be called while holding it.  This is because we're
 * locking changes to the tree structure, not to the references.
 * Inc() is expected to have its own locking.
 */
void*
lookupkey(Intmap *map, uint32_t id)
{
	Intlist *f;
	void *v;

	rlock(&map->RWLock);
	if((f = *llookup(map, id)) != nil){
		v = f->aux;
		map->inc(v);
	}else
		v = nil;
	runlock(&map->RWLock);
	return v;
}
Ejemplo n.º 3
0
void*
deletekey(Intmap *map, ulong id)
{
	Intlist **lf, *f;
	void *ov;

	wlock(map);
	if(f = *(lf = llookup(map, id))){
		ov = f->aux;
		*lf = f->link;
		free(f);
	}else
		ov = nil;
	wunlock(map);
	return ov;
}
Ejemplo n.º 4
0
void*
deletekey(Intmap *map, uint32_t id)
{
	Intlist **lf, *f;
	void *ov;

	wlock(&map->RWLock);
	if((f = *(lf = llookup(map, id))) != nil){
		ov = f->aux;
		*lf = f->link;
		free(f);
	}else
		ov = nil;
	wunlock(&map->RWLock);
	return ov;
}
Ejemplo n.º 5
0
Archivo: bflz.c Proyecto: aahud/harvey
void
insertnode(uint32_t key, uint32_t offset)
{
	int i;
	Node *n, **l;

	l = llookup(key);
	if(*l == nil){
		if(l==&hash[key&(nhash-1)])
			nnew++;
		*l = allocnode();
		(*l)->key = key;
	}
	n = *l;

	/* add or replace last */
	for(i=0; i<NOFF-1 && n->offset[i]!=-1; i++)
		;
	n->offset[i] = offset;
}
Ejemplo n.º 6
0
int
caninsertkey(Intmap *map, ulong id, void *v)
{
	Intlist *f;
	int rv;
	ulong h;

	wlock(map);
	if(*llookup(map, id))
		rv = 0;
	else{
		f = emalloc9p(sizeof *f);
		f->id = id;
		f->aux = v;
		h = hashid(id);
		f->link = map->hash[h];
		map->hash[h] = f;
		rv = 1;
	}
	wunlock(map);
	return rv;	
}
Ejemplo n.º 7
0
void*
insertkey(Intmap *map, ulong id, void *v)
{
	Intlist *f;
	void *ov;
	ulong h;

	wlock(map);
	if(f = *llookup(map, id)){
		/* no decrement for ov because we're returning it */
		ov = f->aux;
		f->aux = v;
	}else{
		f = emalloc9p(sizeof(*f));
		f->id = id;
		f->aux = v;
		h = hashid(id);
		f->link = map->hash[h];
		map->hash[h] = f;
		ov = nil;
	}
	wunlock(map);
	return ov;	
}
Ejemplo n.º 8
0
Archivo: bflz.c Proyecto: aahud/harvey
Node*
lookup(uint32_t key)
{
	return *llookup(key);
}