bugfix: harbor service should not release before others

This commit is contained in:
Cloud Wu
2014-10-10 20:13:53 +08:00
parent 2f6bfe9104
commit 4a8bf4f39a
5 changed files with 23 additions and 0 deletions

View File

@@ -31,5 +31,17 @@ skynet_harbor_init(int harbor) {
void
skynet_harbor_start(void *ctx) {
// the HARBOR must be reserved to ensure the pointer is valid.
// It will be released at last by calling skynet_harbor_exit
skynet_context_reserve(ctx);
REMOTE = ctx;
}
void
skynet_harbor_exit() {
struct skynet_context * ctx = REMOTE;
REMOTE= NULL;
if (ctx) {
skynet_context_release(ctx);
}
}

View File

@@ -26,5 +26,6 @@ void skynet_harbor_send(struct remote_message *rmsg, uint32_t source, int sessio
int skynet_harbor_message_isremote(uint32_t handle);
void skynet_harbor_init(int harbor);
void skynet_harbor_start(void * ctx);
void skynet_harbor_exit();
#endif

View File

@@ -178,6 +178,14 @@ skynet_context_grab(struct skynet_context *ctx) {
__sync_add_and_fetch(&ctx->ref,1);
}
void
skynet_context_reserve(struct skynet_context *ctx) {
skynet_context_grab(ctx);
// don't count the context reserved, because skynet abort (the worker threads terminate) only when the total context is 0 .
// the reserved context will be release at last.
context_dec();
}
static void
delete_context(struct skynet_context *ctx) {
if (ctx->logfile) {

View File

@@ -10,6 +10,7 @@ struct skynet_monitor;
struct skynet_context * skynet_context_new(const char * name, const char * parm);
void skynet_context_grab(struct skynet_context *);
void skynet_context_reserve(struct skynet_context *ctx);
struct skynet_context * skynet_context_release(struct skynet_context *);
uint32_t skynet_context_handle(struct skynet_context *);
int skynet_context_push(uint32_t handle, struct skynet_message *message);

View File

@@ -236,4 +236,5 @@ skynet_start(struct skynet_config * config) {
if (config->daemon) {
daemon_exit(config->daemon);
}
skynet_harbor_exit();
}