From bc55b8d9923a710551503765f942f26fa7baaacb Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Sat, 4 Aug 2012 10:11:33 +0800 Subject: [PATCH] guarantee that return value of skynet_context_handle is same as previously returned by skynet_handle_register --- skynet_handle.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/skynet_handle.c b/skynet_handle.c index 51929a52..d64c2bea 100644 --- a/skynet_handle.c +++ b/skynet_handle.c @@ -37,19 +37,20 @@ skynet_handle_register(struct skynet_context *ctx) { for (;;) { int i; for (i=0;islot_size;i++) { - int hash = (i+s->handle_index) & (s->slot_size-1); + uint32_t handle = (i+s->handle_index) & HANDLE_MASK; + int hash = handle & (s->slot_size-1); if (s->slot[hash] == NULL) { s->slot[hash] = ctx; - uint32_t handle = s->handle_index + i ; - skynet_context_init(ctx, handle); + s->handle_index = handle + 1; rwlock_wunlock(&s->lock); - s->handle_index = handle + 1; - - return (handle & HANDLE_MASK) | s->harbor; + handle |= s->harbor; + skynet_context_init(ctx, handle); + return handle; } } + assert((s->slot_size*2 - 1) <= HANDLE_MASK); struct skynet_context ** new_slot = malloc(s->slot_size * 2 * sizeof(struct skynet_context *)); memset(new_slot, 0, s->slot_size * 2 * sizeof(struct skynet_context *)); for (i=0;islot_size;i++) { @@ -127,7 +128,6 @@ skynet_handle_findname(const char * name) { int c = strcmp(n->name, name); if (c==0) { handle = n->handle; - handle |= s->harbor; break; } if (c<0) {