guarantee that return value of skynet_context_handle is same as previously returned by skynet_handle_register

This commit is contained in:
Kezhu Wang
2012-08-04 10:11:33 +08:00
parent b5764c5736
commit bc55b8d992

View File

@@ -37,19 +37,20 @@ skynet_handle_register(struct skynet_context *ctx) {
for (;;) {
int i;
for (i=0;i<s->slot_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;i<s->slot_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) {