Skip to content

Commit

Permalink
Make miniglog threadsafe on non-windows system by using localtime_r()…
Browse files Browse the repository at this point in the history
… instead of localtime() for time formatting

ceres-solver/ceres-solver@dfb2012
  • Loading branch information
sh1r0 committed Mar 6, 2016
1 parent b2ee005 commit 077fce6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions include/ceres/internal/miniglog/glog/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,21 @@ class CERES_EXPORT MessageLogger {
time_t rawtime;
time (&rawtime);

struct tm* timeinfo;
struct tm timeinfo;
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
// On Windows, use secure localtime_s not localtime.
struct tm windows_timeinfo;
timeinfo = &windows_timeinfo;
localtime_s(timeinfo, &rawtime);
localtime_s(&timeinfo, &rawtime);
#else
timeinfo = localtime(&rawtime);
// On non-Windows systems, use threadsafe localtime_r not localtime.
localtime_r(&rawtime, &timeinfo);
#endif

std::set<google::LogSink*>::iterator iter;
// Send the log message to all sinks.
for (iter = google::log_sinks_global.begin();
iter != google::log_sinks_global.end(); ++iter) {
(*iter)->send(severity, file_.c_str(), filename_only_.c_str(), line_,
timeinfo, stream_.str().c_str(), stream_.str().size());
&timeinfo, stream_.str().c_str(), stream_.str().size());
}
}

Expand Down

0 comments on commit 077fce6

Please sign in to comment.