提交 27e046f9 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

unsigned keys to avoid negative mod outputs

上级 f484e1cb
...@@ -102,11 +102,11 @@ void mpstartthem(void); ...@@ -102,11 +102,11 @@ void mpstartthem(void);
void nsinit(void); void nsinit(void);
struct ns* nsalloc(int allowdup); struct ns* nsalloc(int allowdup);
int ns_allockey(struct ns*); int ns_allockey(struct ns*);
int ns_insert(struct ns*, int key, void*); int ns_insert(struct ns*, uint key, void*);
void* ns_lookup(struct ns*, int); void* ns_lookup(struct ns*, uint);
int ns_remove(struct ns *ns, int key, void *val); int ns_remove(struct ns *ns, uint key, void *val);
void* ns_enumerate(struct ns *ns, void *(*f)(int, void *)); void* ns_enumerate(struct ns *ns, void *(*f)(uint, void *));
void* ns_enumerate_key(struct ns *ns, int key, void *(*f)(void *)); void* ns_enumerate_key(struct ns *ns, uint key, void *(*f)(void *));
// picirq.c // picirq.c
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#endif #endif
struct elem { struct elem {
int key; uint key;
void *val; void *val;
int next_lock; int next_lock;
struct elem * volatile next; struct elem * volatile next;
...@@ -25,7 +25,7 @@ struct bucket { ...@@ -25,7 +25,7 @@ struct bucket {
struct ns { struct ns {
int allowdup; int allowdup;
int nextkey; uint nextkey;
struct bucket table[NHASH]; struct bucket table[NHASH];
}; };
...@@ -64,12 +64,12 @@ elemalloc(void) ...@@ -64,12 +64,12 @@ elemalloc(void)
int int
ns_allockey(struct ns *ns) ns_allockey(struct ns *ns)
{ {
int n = __sync_fetch_and_add(&ns->nextkey, 1); uint n = __sync_fetch_and_add(&ns->nextkey, 1);
return n; return n;
} }
int int
ns_insert(struct ns *ns, int key, void *val) ns_insert(struct ns *ns, uint key, void *val)
{ {
struct elem *e = elemalloc(); struct elem *e = elemalloc();
if (e) { if (e) {
...@@ -102,7 +102,7 @@ ns_insert(struct ns *ns, int key, void *val) ...@@ -102,7 +102,7 @@ ns_insert(struct ns *ns, int key, void *val)
} }
void* void*
ns_lookup(struct ns *ns, int key) ns_lookup(struct ns *ns, uint key)
{ {
uint i = key % NHASH; uint i = key % NHASH;
...@@ -121,7 +121,7 @@ ns_lookup(struct ns *ns, int key) ...@@ -121,7 +121,7 @@ ns_lookup(struct ns *ns, int key)
} }
int int
ns_remove(struct ns *ns, int key, void *v) ns_remove(struct ns *ns, uint key, void *v)
{ {
uint i = key % NHASH; uint i = key % NHASH;
rcu_begin_write(0); rcu_begin_write(0);
...@@ -165,7 +165,7 @@ ns_remove(struct ns *ns, int key, void *v) ...@@ -165,7 +165,7 @@ ns_remove(struct ns *ns, int key, void *v)
} }
void * void *
ns_enumerate(struct ns *ns, void *(*f)(int, void *)) ns_enumerate(struct ns *ns, void *(*f)(uint, void *))
{ {
rcu_begin_read(); rcu_begin_read();
for (int i = 0; i < NHASH; i++) { for (int i = 0; i < NHASH; i++) {
...@@ -182,7 +182,7 @@ ns_enumerate(struct ns *ns, void *(*f)(int, void *)) ...@@ -182,7 +182,7 @@ ns_enumerate(struct ns *ns, void *(*f)(int, void *))
} }
void * void *
ns_enumerate_key(struct ns *ns, int key, void *(*f)(void *)) ns_enumerate_key(struct ns *ns, uint key, void *(*f)(void *))
{ {
uint i = key % NHASH; uint i = key % NHASH;
rcu_begin_read(); rcu_begin_read();
......
...@@ -445,7 +445,7 @@ migrate(struct proc *p) ...@@ -445,7 +445,7 @@ migrate(struct proc *p)
} }
static void * static void *
steal_cb(int k, void *v) steal_cb(uint k, void *v)
{ {
struct proc *p = v; struct proc *p = v;
...@@ -643,7 +643,7 @@ kill(int pid) ...@@ -643,7 +643,7 @@ kill(int pid)
return 0; return 0;
} }
void *procdump(int k, void *v) void *procdump(uint k, void *v)
{ {
struct proc *p = (struct proc *) v; struct proc *p = (struct proc *) v;
......
...@@ -35,7 +35,7 @@ rcu_alloc() ...@@ -35,7 +35,7 @@ rcu_alloc()
} }
void * void *
rcu_min(int key, void *v){ rcu_min(uint key, void *v){
struct proc *p = (struct proc *) v; struct proc *p = (struct proc *) v;
if (min_epoch[cpu->id].x > p->epoch) { if (min_epoch[cpu->id].x > p->epoch) {
min_epoch[cpu->id].x = p->epoch; min_epoch[cpu->id].x = p->epoch;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论