提交环形缓冲区相关修改

This commit is contained in:
guo_peixu
2022-06-10 16:13:11 +08:00
parent 08fd550822
commit 65ed1c3a92
3 changed files with 34 additions and 20 deletions

View File

@@ -1,4 +1,5 @@
#include "MESA_handle_logger.h"
#include "MESA_shm_ring_queue.h"
#include "snprintf.h"
#include <pthread.h>
#include "zlog.h"
@@ -30,6 +31,7 @@ struct MESA_pthread_private{
char *cache_buf;
int fmt_buf_len;
int cache_buf_len;
struct MESA_shm_queue_head *ring_queue_head;
};
struct MESA_fmt_obj{
char sign;
@@ -216,6 +218,12 @@ struct MESA_pthread_private *MESA_create_pthread_private(void *handle)
if(pri->cache_buf == NULL){
goto error;
}
pri->ring_queue_head = MESA_shm_get_ring_queue();
/*
if(pri->queue_head == NULL){
goto error;
}
*/
return pri;
error:
@@ -237,6 +245,9 @@ void MESA_free_pthread_private(void *arg)
if(pri == NULL){
return ;
}
if(pri->ring_queue_head){
MESA_shm_recycle_ring_queue(pri->ring_queue_head);
}
if(pri->fmt_buf){
free(pri->fmt_buf);
}
@@ -252,6 +263,8 @@ void MESA_free_pthread_private(void *arg)
void MESA_alloc_pthread_key()
{
pthread_key_create(&MESA_pthread_key, MESA_free_pthread_private);
MESA_shm_init_overview();
MESA_shm_init_mutex();
return ;
}
@@ -334,9 +347,10 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
pri->cache_buf_len = n + 1;
pri->cache_buf = p;
va_copy(ap_bk, ap);
portable_vsnprintf(handle, pri->cache_buf, pri->cache_buf_len, fmt, ap_bk);
n = portable_vsnprintf(handle, pri->cache_buf, pri->cache_buf_len, fmt, ap_bk);
}
}
MESA_shm_copy_buf_to_ring_queue(pri->cache_buf, n, pri->ring_queue_head);
va_end(ap);
va_end(ap_bk);

View File

@@ -17,7 +17,7 @@ CFLAGS_+= -fsanitize=address -fno-omit-frame-pointer
LIB+=-lasan
endif
SRC=MESA_handle_logger.c
SRC=MESA_handle_logger.c MESA_shm_ring_queue.c
OBJS=$(SRC:.c=.o)
TARGET=libMESA_handle_logger.a libMESA_handle_logger.so
@@ -26,10 +26,10 @@ all:$(TARGET)
cp -f $(TARGET) ../lib
libMESA_handle_logger.a:$(OBJS)
ar cqs $@ $<
ar cqs $@ $^
libMESA_handle_logger.so:$(OBJS)
$(CC) $(CFLAGS) $(LIB) -shared $< -o $@
$(CC) $(CFLAGS) $(LIB) -shared $^ -o $@
.c.o:
#$(OBJS):$(SRC)