From 3a413408ad55529623b465b2e299c9b066e2a552 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Thu, 21 Sep 2023 09:03:45 +0800 Subject: [PATCH] add func sf_alloc_init_task_ex to specify reffer_count --- src/idempotency/client/client_channel.c | 2 +- src/sf_service.h | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/idempotency/client/client_channel.c b/src/idempotency/client/client_channel.c index ae752de..822f008 100644 --- a/src/idempotency/client/client_channel.c +++ b/src/idempotency/client/client_channel.c @@ -245,7 +245,7 @@ struct idempotency_client_channel *idempotency_client_channel_get( IdempotencyClientChannel *current; IdempotencyClientChannel *channel; - key_len = snprintf(key, sizeof(key), "%s_%u", server_ip, server_port); + key_len = snprintf(key, sizeof(key), "%s-%u", server_ip, server_port); hash_code = fc_simple_hash(key, key_len); bucket = channel_context.htable.buckets + hash_code % channel_context.htable.capacity; diff --git a/src/sf_service.h b/src/sf_service.h index de3328b..b94b88e 100644 --- a/src/sf_service.h +++ b/src/sf_service.h @@ -139,8 +139,9 @@ void sf_set_sig_quit_handler(sf_sig_quit_handler quit_handler); int sf_init_task(struct fast_task_info *task); -static inline struct fast_task_info *sf_alloc_init_task( - SFNetworkHandler *handler, const int fd) +static inline struct fast_task_info *sf_alloc_init_task_ex( + SFNetworkHandler *handler, const int fd, + const int reffer_count) { struct fast_task_info *task; @@ -153,7 +154,7 @@ static inline struct fast_task_info *sf_alloc_init_task( return NULL; } - __sync_add_and_fetch(&task->reffer_count, 1); + __sync_add_and_fetch(&task->reffer_count, reffer_count); __sync_bool_compare_and_swap(&task->canceled, 1, 0); task->handler = handler; task->event.fd = fd; @@ -161,6 +162,7 @@ static inline struct fast_task_info *sf_alloc_init_task( } #define sf_hold_task(task) __sync_add_and_fetch(&task->reffer_count, 1) +#define sf_alloc_init_task(handler, fd) sf_alloc_init_task_ex(handler, fd, 1) static inline void sf_release_task(struct fast_task_info *task) {