1. 将trylock替换为lock 2. 修改测试程序
This commit is contained in:
@@ -16,11 +16,12 @@ void *test_handle = NULL;
|
||||
int g_mode = 0;
|
||||
int g_log_num = 0;
|
||||
int g_thread_num = 0;
|
||||
int g_log_print_way = 0;
|
||||
const char *g_zlog_conf = NULL;
|
||||
volatile long g_start_time = 0;
|
||||
volatile long g_end_time = 0;
|
||||
|
||||
void call_logger(int log_num, int thread_num)
|
||||
void call_logger(int log_num, int thread_num, int way)
|
||||
{
|
||||
int i = 0;
|
||||
struct timespec start, end;
|
||||
@@ -40,15 +41,25 @@ void call_logger(int log_num, int thread_num)
|
||||
}
|
||||
for(i = 0; i < log_num; i++)
|
||||
{
|
||||
// MESA_handle_runtime_log(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
|
||||
//sleep(1);
|
||||
// MESA_handle_runtime_log(test_handle, RLOG_LV_INFO, "test", "test_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
|
||||
//MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_FATAL, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
//sleep(1);
|
||||
//MESA_HANDLE_RUNTIME_LOG(test_handle, RLOG_LV_FATAL, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
switch (way)
|
||||
{
|
||||
case 1:
|
||||
MESA_handle_runtime_log(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
MESA_handle_runtime_log(test_handle, RLOG_LV_INFO, "test", "test_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
|
||||
break;
|
||||
case 2:
|
||||
MESA_HANDLE_RUNTIME_LOG_RATELIMIT(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
MESA_HANDLE_RUNTIME_LOG_RATELIMIT(test_handle, RLOG_LV_INFO, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
sleep(1);
|
||||
break;
|
||||
case 3:
|
||||
MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
MESA_HANDLE_RUNTIME_LOG(test_handle, RLOG_LV_INFO, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// if (i % 10000 == 0)
|
||||
// sleep(1);
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
end_time = end.tv_sec*1000000 + end.tv_nsec/1000;
|
||||
@@ -73,7 +84,7 @@ void *thread_logger(void *arg)
|
||||
{
|
||||
int thread_num = (int)(unsigned long long)arg;
|
||||
printf("thread %d created! \n", thread_num);
|
||||
call_logger(g_log_num, thread_num);
|
||||
call_logger(g_log_num, thread_num, g_log_print_way);
|
||||
printf("thread %d finished! \n", thread_num);
|
||||
return NULL;
|
||||
}
|
||||
@@ -122,15 +133,16 @@ int main(int argc, char ** args)
|
||||
pthread_t t[MAX_THREAD_NUM];
|
||||
int i = 0;
|
||||
|
||||
if (argc != 5)
|
||||
if (argc != 6)
|
||||
{
|
||||
printf("Usage: ./($app) $mode[1 or 2] $zlog_conf_path $thread_num $log_num \n");
|
||||
printf("Usage: ./($app) $mode[1 or 2] $zlog_conf_path $thread_num $log_num $log_print_way[1 2 3]\n");
|
||||
return -1;
|
||||
}
|
||||
g_mode = atoi(args[1]);
|
||||
g_zlog_conf = args[2];
|
||||
g_thread_num = atoi(args[3]);
|
||||
g_log_num = atoi(args[4]);
|
||||
g_log_print_way = atoi(args[5]);
|
||||
|
||||
if(g_thread_num <= 0 || g_log_num <= 0)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#define MAX_HANDLE_LOG_PATH 4096
|
||||
#define DEFAULT_BURST 10
|
||||
#define DEFAULT_INTERVAL 5
|
||||
|
||||
static int g_zlog_inited = 0;
|
||||
static int g_zlog_conf_fp = -1;
|
||||
static char global_conf_filepath[MAX_HANDLE_LOG_PATH] = "";
|
||||
@@ -190,7 +191,7 @@ int MESA_runtime_log_ratelimit(void *handle, log_ratelimit_t *rs, int level, con
|
||||
struct timespec timer = {0, 0};
|
||||
log_handle_t *p_handle = (log_handle_t *)handle;
|
||||
|
||||
if (pthread_mutex_trylock(&rs->mutex) != 0)return 0;
|
||||
if (pthread_mutex_lock(&rs->mutex) != 0)return 0;
|
||||
|
||||
if (!rs->begin)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user