diff --git a/skynet-src/skynet_handle.c b/skynet-src/skynet_handle.c index 58cabc0b..dc20dcf2 100644 --- a/skynet-src/skynet_handle.c +++ b/skynet-src/skynet_handle.c @@ -49,7 +49,6 @@ skynet_handle_register(struct skynet_context *ctx) { rwlock_wunlock(&s->lock); handle |= s->harbor; - skynet_context_init(ctx, handle); return handle; } } @@ -67,8 +66,9 @@ skynet_handle_register(struct skynet_context *ctx) { } } -void +int skynet_handle_retire(uint32_t handle) { + int ret = 0; struct handle_storage *s = H; rwlock_wlock(&s->lock); @@ -79,6 +79,7 @@ skynet_handle_retire(uint32_t handle) { if (ctx != NULL && skynet_context_handle(ctx) == handle) { skynet_context_release(ctx); s->slot[hash] = NULL; + ret = 1; int i; int j=0, n=s->name_count; for (i=0; ilock); + + return ret; } void @@ -105,10 +108,14 @@ skynet_handle_retireall() { for (i=0;islot_size;i++) { rwlock_rlock(&s->lock); struct skynet_context * ctx = s->slot[i]; + uint32_t handle = 0; + if (ctx) + handle = skynet_context_handle(ctx); rwlock_runlock(&s->lock); - if (ctx != NULL) { - ++n; - skynet_handle_retire(skynet_context_handle(ctx)); + if (handle != 0) { + if (skynet_handle_retire(handle)) { + ++n; + } } } if (n==0) diff --git a/skynet-src/skynet_handle.h b/skynet-src/skynet_handle.h index a39b47bb..e067eed0 100644 --- a/skynet-src/skynet_handle.h +++ b/skynet-src/skynet_handle.h @@ -8,7 +8,7 @@ struct skynet_context; uint32_t skynet_handle_register(struct skynet_context *); -void skynet_handle_retire(uint32_t handle); +int skynet_handle_retire(uint32_t handle); struct skynet_context * skynet_handle_grab(uint32_t handle); void skynet_handle_retireall(); diff --git a/skynet-src/skynet_server.c b/skynet-src/skynet_server.c index 3e902cc9..0e5f851f 100644 --- a/skynet-src/skynet_server.c +++ b/skynet-src/skynet_server.c @@ -132,6 +132,8 @@ skynet_context_new(const char * name, const char *param) { ctx->init = false; ctx->endless = false; + // Should set to 0 first to avoid skynet_handle_retireall get an uninitialized handle + ctx->handle = 0; ctx->handle = skynet_handle_register(ctx); struct message_queue * queue = ctx->queue = skynet_mq_create(ctx->handle); // init function maybe use ctx->handle, so it must init at last @@ -646,11 +648,6 @@ skynet_context_handle(struct skynet_context *ctx) { return ctx->handle; } -void -skynet_context_init(struct skynet_context *ctx, uint32_t handle) { - ctx->handle = handle; -} - void skynet_callback(struct skynet_context * context, void *ud, skynet_cb cb) { context->cb = cb; diff --git a/skynet-src/skynet_server.h b/skynet-src/skynet_server.h index 5d07ba70..27b6b768 100644 --- a/skynet-src/skynet_server.h +++ b/skynet-src/skynet_server.h @@ -12,7 +12,6 @@ struct skynet_context * skynet_context_new(const char * name, const char * parm) void skynet_context_grab(struct skynet_context *); struct skynet_context * skynet_context_release(struct skynet_context *); uint32_t skynet_context_handle(struct skynet_context *); -void skynet_context_init(struct skynet_context *, uint32_t handle); int skynet_context_push(uint32_t handle, struct skynet_message *message); void skynet_context_send(struct skynet_context * context, void * msg, size_t sz, uint32_t source, int type, int session); int skynet_context_newsession(struct skynet_context *);