mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
context calling check
This commit is contained in:
@@ -15,6 +15,9 @@
|
|||||||
#define BLACKHOLE "blackhole"
|
#define BLACKHOLE "blackhole"
|
||||||
#define DEFAULT_MESSAGE_QUEUE 16
|
#define DEFAULT_MESSAGE_QUEUE 16
|
||||||
|
|
||||||
|
#define CHECKCALLING_BEGIN(ctx) assert(__sync_lock_test_and_set(&ctx->calling,1) == 0);
|
||||||
|
#define CHECKCALLING_END(ctx) __sync_lock_release(&ctx->calling);
|
||||||
|
|
||||||
struct skynet_context {
|
struct skynet_context {
|
||||||
void * instance;
|
void * instance;
|
||||||
struct skynet_module * mod;
|
struct skynet_module * mod;
|
||||||
@@ -26,6 +29,7 @@ struct skynet_context {
|
|||||||
skynet_cb cb;
|
skynet_cb cb;
|
||||||
int session_id;
|
int session_id;
|
||||||
int init;
|
int init;
|
||||||
|
int calling;
|
||||||
uint32_t forward;
|
uint32_t forward;
|
||||||
char forward_address[GLOBALNAME_LENGTH];
|
char forward_address[GLOBALNAME_LENGTH];
|
||||||
struct message_queue *queue;
|
struct message_queue *queue;
|
||||||
@@ -62,13 +66,16 @@ skynet_context_new(const char * name, const char *param) {
|
|||||||
ctx->forward = 0;
|
ctx->forward = 0;
|
||||||
ctx->forward_address[0] = '\0';
|
ctx->forward_address[0] = '\0';
|
||||||
ctx->init = 0;
|
ctx->init = 0;
|
||||||
|
ctx->calling =0;
|
||||||
ctx->handle = skynet_handle_register(ctx);
|
ctx->handle = skynet_handle_register(ctx);
|
||||||
char * uid = ctx->handle_name;
|
char * uid = ctx->handle_name;
|
||||||
_id_to_hex(uid, ctx->handle);
|
_id_to_hex(uid, ctx->handle);
|
||||||
struct message_queue * queue = ctx->queue = skynet_mq_create(ctx->handle);
|
struct message_queue * queue = ctx->queue = skynet_mq_create(ctx->handle);
|
||||||
// init function maybe use ctx->handle, so it must init at last
|
// init function maybe use ctx->handle, so it must init at last
|
||||||
|
|
||||||
|
CHECKCALLING_BEGIN(ctx)
|
||||||
int r = skynet_module_instance_init(mod, inst, ctx, param);
|
int r = skynet_module_instance_init(mod, inst, ctx, param);
|
||||||
|
CHECKCALLING_END(ctx)
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
struct skynet_context * ret = skynet_context_release(ctx);
|
struct skynet_context * ret = skynet_context_release(ctx);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@@ -163,6 +170,7 @@ _forwarding(struct skynet_context *ctx, struct skynet_message *msg) {
|
|||||||
static void
|
static void
|
||||||
_dispatch_message(struct skynet_context *ctx, struct skynet_message *msg) {
|
_dispatch_message(struct skynet_context *ctx, struct skynet_message *msg) {
|
||||||
assert(ctx->init);
|
assert(ctx->init);
|
||||||
|
CHECKCALLING_BEGIN(ctx)
|
||||||
if (msg->source == SKYNET_SYSTEM_TIMER) {
|
if (msg->source == SKYNET_SYSTEM_TIMER) {
|
||||||
ctx->cb(ctx, ctx->cb_ud, msg->session, NULL, msg->data, msg->sz);
|
ctx->cb(ctx, ctx->cb_ud, msg->session, NULL, msg->data, msg->sz);
|
||||||
} else {
|
} else {
|
||||||
@@ -174,6 +182,7 @@ _dispatch_message(struct skynet_context *ctx, struct skynet_message *msg) {
|
|||||||
free(msg->data);
|
free(msg->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CHECKCALLING_END(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
Reference in New Issue
Block a user