Skip to content

Commit f863d6e

Browse files
Wenbin1002Helloworld-lblhnwyllmm
authored
add a lock to make LOG_HEAD thread-safe #{317} (oceanbase#327)
### What problem were solved in this pull request? Issue Number: close oceanbase#317 Problem: localtime is not a thread-safe function. ### What is changed and how it works? use localtime_r instead of localtime Co-authored-by: Helloworld-lbl <[email protected]> Co-authored-by: wangyunlai <[email protected]>
1 parent 80e6fd8 commit f863d6e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

deps/common/log/log.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,10 @@ extern Log *g_log;
185185
if (common::g_log) { \
186186
struct timeval tv; \
187187
gettimeofday(&tv, NULL); \
188-
struct tm *p = localtime(&tv.tv_sec); \
189-
char sz_head[LOG_HEAD_SIZE] = {0}; \
188+
struct tm curr_time; \
189+
struct tm *p = localtime_r(&tv.tv_sec, &curr_time); \
190+
\
191+
char sz_head[LOG_HEAD_SIZE] = {0}; \
190192
if (p) { \
191193
int usec = (int)tv.tv_usec; \
192194
snprintf(sz_head, \

0 commit comments

Comments
 (0)