Skip to content

Commit

Permalink
[modify] if create thread pool error, send data directly
Browse files Browse the repository at this point in the history
[modify] remove atomic operation before init apr
  • Loading branch information
shabicheng committed Dec 23, 2017
1 parent 9d9c2d9 commit ee29a33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/log_producer_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion src/log_producer_sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit ee29a33

Please sign in to comment.