From ee29a3353b83a03c3b1b1f78c4859c91595f1ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=83=E4=B9=99?= Date: Sat, 23 Dec 2017 15:55:08 +0800 Subject: [PATCH] [modify] if create thread pool error, send data directly [modify] remove atomic operation before init apr --- src/log_producer_client.c | 3 ++- src/log_producer_sender.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/log_producer_client.c b/src/log_producer_client.c index 1712ce5..980dfce 100644 --- a/src/log_producer_client.c +++ b/src/log_producer_client.c @@ -29,10 +29,11 @@ struct _log_producer { log_producer_result log_producer_env_init() { // if already init, just return s_last_result - if (apr_atomic_xchg32(&s_init_flag, 1)) + if (s_init_flag == 1) { return s_last_result; } + s_init_flag = 1; if (AOSE_OK != aos_http_io_initialize(C_PRODUCER_VERSION, 0)) { s_last_result = LOG_PRODUCER_INVALID; diff --git a/src/log_producer_sender.c b/src/log_producer_sender.c index 41c423e..3dd7628 100644 --- a/src/log_producer_sender.c +++ b/src/log_producer_sender.c @@ -221,6 +221,15 @@ int32_t log_producer_on_send_done(log_producer_send_param * send_param, aos_stat log_producer_result log_producer_send_data(log_producer_send_param * send_param) { log_producer_manager * producer_manager = (log_producer_manager *)send_param->producer_manager; + // if thread pool is null, send data directly + if (producer_manager->sender->thread_pool == NULL) + { + apr_atomic_inc32(&(producer_manager->sender->send_queue_count)); + apr_atomic_add32(&(producer_manager->sender->send_queue_size), send_param->log_buf->length); + apr_atomic_add32(&(producer_manager->totalBufferSize), send_param->log_buf->length); + log_producer_send_fun(NULL, send_param); + return LOG_PRODUCER_OK; + } apr_status_t result = apr_thread_pool_push(producer_manager->sender->thread_pool, log_producer_send_fun, send_param, @@ -285,13 +294,18 @@ log_producer_sender * create_log_producer_sender(log_producer_config * producer_ if (status != APR_SUCCESS) { aos_fatal_log("create thread pool error, config : %s, thread count : %d, error code : %d", producer_config->configName, producer_config->sendThreadCount, status); - return NULL; + // if create thread pool fail, just return producer_sender, and send data directly + return producer_sender; } return producer_sender; } void destroy_log_producer_sender(log_producer_sender * producer_sender) { + if (producer_sender->thread_pool == NULL) + { + return; + } int waitCount = 0; while (apr_thread_pool_tasks_count(producer_sender->thread_pool) != 0) {