shm lock free

This commit is contained in:
luwenpeng
2023-06-26 18:05:38 +08:00
parent 74991f842a
commit bf3a1f09fb
6 changed files with 282 additions and 262 deletions

View File

@@ -10,36 +10,37 @@ extern "C"
#include <stdio.h>
#if ENABLD_LOG_FIEL
#define LOG_FILE(time, format, ...) \
{ \
FILE *fp = fopen("licenses.log", "a+"); \
if (fp == NULL) \
{ \
break; \
} \
fprintf(fp, "%s " format "\n", time, ##__VA_ARGS__); \
fflush(fp); \
fclose(fp); \
#define LOG_FILE(prefix, format, ...) \
{ \
FILE *fp = fopen("licenses.log", "a+"); \
if (fp == NULL) \
{ \
break; \
} \
fprintf(fp, "%s " format "\n", prefix, ##__VA_ARGS__); \
fflush(fp); \
fclose(fp); \
}
#else
#define LOG_FILE(time, format, ...)
#define LOG_FILE(prefix, format, ...)
#endif
#define LOG_STOUT(time, format, ...) \
{ \
fprintf(stderr, "%s " format "\n", time, ##__VA_ARGS__); \
#define LOG_STOUT(prefix, format, ...) \
{ \
fprintf(stderr, "%s " format "\n", prefix, ##__VA_ARGS__); \
}
#define LOG_INFO(format, ...) \
do \
{ \
char buffer[64] = {0}; \
local_time_string(buffer, sizeof(buffer)); \
LOG_STOUT(buffer, format, ##__VA_ARGS__); \
LOG_FILE(buffer, format, ##__VA_ARGS__); \
#define LOG_INFO(format, ...) \
do \
{ \
char buffer[128] = {0}; \
int n = local_time_string(buffer, sizeof(buffer)); \
snprintf(buffer + n, sizeof(buffer) - n, " tid: %ld", pthread_self()); \
LOG_STOUT(buffer, format, ##__VA_ARGS__); \
LOG_FILE(buffer, format, ##__VA_ARGS__); \
} while (0)
static void local_time_string(char *buff, int size)
static int local_time_string(char *buff, int size)
{
static unsigned char weekday_str[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
static unsigned char month_str[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
@@ -49,17 +50,17 @@ static void local_time_string(char *buff, int size)
time(&now);
if (NULL == (localtime_r(&now, &local_time)))
{
return;
return 0;
}
snprintf(buff, size,
"%s %s %d %02d:%02d:%02d %d",
weekday_str[local_time.tm_wday],
month_str[local_time.tm_mon],
local_time.tm_mday,
local_time.tm_hour,
local_time.tm_min,
local_time.tm_sec,
local_time.tm_year + 1900);
return snprintf(buff, size,
"%s %s %d %02d:%02d:%02d %d",
weekday_str[local_time.tm_wday],
month_str[local_time.tm_mon],
local_time.tm_mday,
local_time.tm_hour,
local_time.tm_min,
local_time.tm_sec,
local_time.tm_year + 1900);
}
#ifdef __cpluscplus