|
|
|
@ -74,6 +74,8 @@ static pthread_t async_output_thread;
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize OK flag */
|
|
|
|
/* Initialize OK flag */
|
|
|
|
static bool init_ok = false;
|
|
|
|
static bool init_ok = false;
|
|
|
|
|
|
|
|
/* thread running flag */
|
|
|
|
|
|
|
|
static bool thread_running = false;
|
|
|
|
/* asynchronous output mode enabled flag */
|
|
|
|
/* asynchronous output mode enabled flag */
|
|
|
|
static bool is_enabled = false;
|
|
|
|
static bool is_enabled = false;
|
|
|
|
/* asynchronous output mode's ring buffer */
|
|
|
|
/* asynchronous output mode's ring buffer */
|
|
|
|
@ -283,7 +285,7 @@ static void *async_output(void *arg) {
|
|
|
|
size_t get_log_size = 0;
|
|
|
|
size_t get_log_size = 0;
|
|
|
|
static char poll_get_buf[ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE];
|
|
|
|
static char poll_get_buf[ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE];
|
|
|
|
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
while(thread_running) {
|
|
|
|
/* waiting log */
|
|
|
|
/* waiting log */
|
|
|
|
sem_wait(&output_notice);
|
|
|
|
sem_wait(&output_notice);
|
|
|
|
/* polling gets and outputs the log */
|
|
|
|
/* polling gets and outputs the log */
|
|
|
|
@ -334,8 +336,10 @@ ElogErrCode elog_async_init(void) {
|
|
|
|
|
|
|
|
|
|
|
|
sem_init(&output_notice, 0, 0);
|
|
|
|
sem_init(&output_notice, 0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thread_running = true;
|
|
|
|
|
|
|
|
|
|
|
|
pthread_attr_init(&thread_attr);
|
|
|
|
pthread_attr_init(&thread_attr);
|
|
|
|
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
//pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
pthread_attr_setstacksize(&thread_attr, ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE);
|
|
|
|
pthread_attr_setstacksize(&thread_attr, ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE);
|
|
|
|
pthread_attr_setschedpolicy(&thread_attr, SCHED_RR);
|
|
|
|
pthread_attr_setschedpolicy(&thread_attr, SCHED_RR);
|
|
|
|
thread_sched_param.sched_priority = ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY;
|
|
|
|
thread_sched_param.sched_priority = ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY;
|
|
|
|
@ -349,4 +353,26 @@ ElogErrCode elog_async_init(void) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* asynchronous output mode deinitialize
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void elog_async_deinit(void) {
|
|
|
|
|
|
|
|
if (!init_ok) {
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD
|
|
|
|
|
|
|
|
thread_running = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pthread_join(async_output_thread, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sem_destroy(&output_notice);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init_ok = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* ELOG_ASYNC_OUTPUT_ENABLE */
|
|
|
|
#endif /* ELOG_ASYNC_OUTPUT_ENABLE */
|
|
|
|
|