提交 6b7ca768 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

allow duplicate keys in namespace

上级 d6952037
......@@ -104,8 +104,9 @@ struct ns* nsalloc(void);
int ns_allockey(struct ns*);
int ns_insert(struct ns*, int key, void*);
void* ns_lookup(struct ns*, int);
int ns_remove(struct ns *ns, int key);
int ns_remove(struct ns *ns, int key, void *val);
void ns_enumerate(struct ns *ns, void (*f)(int, void *));
void ns_enumerate_key(struct ns *ns, int key, void (*f)(void *));
// picirq.c
......
......@@ -111,7 +111,7 @@ ns_lookup(struct ns *ns, int key)
}
int
ns_remove(struct ns *ns, int key)
ns_remove(struct ns *ns, int key, void *v)
{
uint i = key % NHASH;
rcu_begin_write(&ns->table[i].l);
......@@ -122,7 +122,7 @@ ns_remove(struct ns *ns, int key)
if (!e)
break;
if (e->key == key) {
if (e->key == key && (e->val == v || v == 0)) {
for (;;)
if (__sync_bool_compare_and_swap(pe, e, e->next))
break;
......@@ -152,3 +152,17 @@ ns_enumerate(struct ns *ns, void (*f)(int, void *))
rcu_end_read();
}
void
ns_enumerate_key(struct ns *ns, int key, void (*f)(void *))
{
uint i = key % NHASH;
rcu_begin_read();
struct elem *e = ns->table[i].chain;
while (e) {
if (e->key == key)
(*f)(e->val);
e = e->next;
}
rcu_end_read();
}
......@@ -66,7 +66,7 @@ allocproc(void)
// Allocate kernel stack if possible.
if((p->kstack = kalloc()) == 0){
ns_remove(nspid, p->pid);
ns_remove(nspid, p->pid, p);
rcu_delayed(p, kmfree);
return 0;
}
......@@ -286,7 +286,7 @@ fork(int flags)
kfree(np->kstack);
np->kstack = 0;
np->state = UNUSED;
ns_remove(nspid, np->pid);
ns_remove(nspid, np->pid, np);
rcu_delayed(np, kmfree);
return -1;
}
......@@ -397,7 +397,7 @@ wait(void)
p->kstack = 0;
vmap_decref(p->vmap);
p->state = UNUSED;
if (ns_remove(nspid, p->pid) < 0)
if (ns_remove(nspid, p->pid, p) < 0)
panic("wait: ns_remove");
p->pid = 0;
p->parent = 0;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论