Skip to content

Commit

Permalink
add a lock to make LOG_HEAD thread-safe #{317} (oceanbase#327)
Browse files Browse the repository at this point in the history
### 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]>
  • Loading branch information
3 people authored Dec 1, 2023
1 parent 80e6fd8 commit f863d6e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions deps/common/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ extern Log *g_log;
if (common::g_log) { \
struct timeval tv; \
gettimeofday(&tv, NULL); \
struct tm *p = localtime(&tv.tv_sec); \
char sz_head[LOG_HEAD_SIZE] = {0}; \
struct tm curr_time; \
struct tm *p = localtime_r(&tv.tv_sec, &curr_time); \
\
char sz_head[LOG_HEAD_SIZE] = {0}; \
if (p) { \
int usec = (int)tv.tv_usec; \
snprintf(sz_head, \
Expand Down

0 comments on commit f863d6e

Please sign in to comment.