Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Unified Diff: base/logging.cc

Issue 19091004: Only use the LoggingLock when actually logging to a file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | remoting/host/logging_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/logging.cc
diff --git a/base/logging.cc b/base/logging.cc
index 16cd2f8b26d32f406e75b9c04c632674ce1ce708..e836092e76657df2e66349b624441a399cf7c0cc 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -152,14 +152,6 @@ uint64 TickCount() {
#endif
}
-void CloseFile(FileHandle log) {
-#if defined(OS_WIN)
- CloseHandle(log);
-#else
- fclose(log);
-#endif
-}
-
void DeleteFilePath(const PathString& log_name) {
#if defined(OS_WIN)
DeleteFile(log_name.c_str());
@@ -341,6 +333,22 @@ bool InitializeLogFileHandle() {
return true;
}
+void CloseFile(FileHandle log) {
+#if defined(OS_WIN)
+ CloseHandle(log);
+#else
+ fclose(log);
+#endif
+}
+
+void CloseLogFileUnlocked() {
+ if (!log_file)
+ return;
+
+ CloseFile(log_file);
+ log_file = NULL;
+}
+
} // namespace
LoggingSettings::LoggingSettings()
@@ -373,23 +381,19 @@ bool BaseInitLoggingImpl(const LoggingSettings& settings) {
&min_log_level);
}
- LoggingLock::Init(settings.lock_log, settings.log_file);
-
- LoggingLock logging_lock;
-
- if (log_file) {
- // calling InitLogging twice or after some log call has already opened the
- // default log file will re-initialize to the new options
- CloseFile(log_file);
- log_file = NULL;
- }
-
logging_destination = settings.logging_dest;
// ignore file options unless logging to file is set.
if ((logging_destination & LOG_TO_FILE) == 0)
return true;
+ LoggingLock::Init(settings.lock_log, settings.log_file);
+ LoggingLock logging_lock;
+
+ // Calling InitLogging twice or after some log call has already opened the
+ // default log file will re-initialize to the new options.
+ CloseLogFileUnlocked();
+
if (!log_file_name)
log_file_name = new PathString();
*log_file_name = settings.log_file;
@@ -608,16 +612,16 @@ LogMessage::~LogMessage() {
fflush(stderr);
}
- // We can have multiple threads and/or processes, so try to prevent them
- // from clobbering each other's writes.
- // If the client app did not call InitLogging, and the lock has not
- // been created do it now. We do this on demand, but if two threads try
- // to do this at the same time, there will be a race condition to create
- // the lock. This is why InitLogging should be called from the main
- // thread at the beginning of execution.
- LoggingLock::Init(LOCK_LOG_FILE, NULL);
// write to log file
if ((logging_destination & LOG_TO_FILE) != 0) {
+ // We can have multiple threads and/or processes, so try to prevent them
+ // from clobbering each other's writes.
+ // If the client app did not call InitLogging, and the lock has not
+ // been created do it now. We do this on demand, but if two threads try
+ // to do this at the same time, there will be a race condition to create
+ // the lock. This is why InitLogging should be called from the main
+ // thread at the beginning of execution.
+ LoggingLock::Init(LOCK_LOG_FILE, NULL);
LoggingLock logging_lock;
if (InitializeLogFileHandle()) {
#if defined(OS_WIN)
@@ -810,12 +814,7 @@ ErrnoLogMessage::~ErrnoLogMessage() {
void CloseLogFile() {
LoggingLock logging_lock;
-
- if (!log_file)
- return;
-
- CloseFile(log_file);
- log_file = NULL;
+ CloseLogFileUnlocked();
}
void RawLog(int level, const char* message) {
« no previous file with comments | « no previous file | remoting/host/logging_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698