| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 typedef HANDLE FileHandle; | 9 typedef HANDLE FileHandle; |
| 10 typedef HANDLE MutexHandle; | 10 typedef HANDLE MutexHandle; |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 InitializeLogFileHandle()) { | 478 InitializeLogFileHandle()) { |
| 479 // We can have multiple threads and/or processes, so try to prevent them | 479 // We can have multiple threads and/or processes, so try to prevent them |
| 480 // from clobbering each other's writes. | 480 // from clobbering each other's writes. |
| 481 if (lock_log_file == LOCK_LOG_FILE) { | 481 if (lock_log_file == LOCK_LOG_FILE) { |
| 482 // Ensure that the mutex is initialized in case the client app did not | 482 // Ensure that the mutex is initialized in case the client app did not |
| 483 // call InitLogging. This is not thread safe. See below. | 483 // call InitLogging. This is not thread safe. See below. |
| 484 InitLogMutex(); | 484 InitLogMutex(); |
| 485 | 485 |
| 486 #if defined(OS_WIN) | 486 #if defined(OS_WIN) |
| 487 DWORD r = ::WaitForSingleObject(log_mutex, INFINITE); | 487 DWORD r = ::WaitForSingleObject(log_mutex, INFINITE); |
| 488 if (r == WAIT_ABANDONED) { | 488 // WaitForSingleObject could have returned WAIT_ABANDONED. We don't |
| 489 // Do not abort the process here. UI tests might be crashy sometimes, | 489 // abort the process here. UI tests might be crashy sometimes, |
| 490 // and aborting the test binary only makes the problem worse. | 490 // and aborting the test binary only makes the problem worse. |
| 491 // For more info see http://crbug.com/18028. | 491 // We also don't use LOG macros because that might lead to an infinite |
| 492 LOG(ERROR) << "Thread owning the log mutex has crashed."; | 492 // loop. For more info see http://crbug.com/18028. |
| 493 } | |
| 494 #elif defined(OS_POSIX) | 493 #elif defined(OS_POSIX) |
| 495 pthread_mutex_lock(&log_mutex); | 494 pthread_mutex_lock(&log_mutex); |
| 496 #endif | 495 #endif |
| 497 } else { | 496 } else { |
| 498 // use the lock | 497 // use the lock |
| 499 if (!log_lock) { | 498 if (!log_lock) { |
| 500 // The client app did not call InitLogging, and so the lock has not | 499 // The client app did not call InitLogging, and so the lock has not |
| 501 // been created. We do this on demand, but if two threads try to do | 500 // been created. We do this on demand, but if two threads try to do |
| 502 // this at the same time, there will be a race condition to create | 501 // this at the same time, there will be a race condition to create |
| 503 // the lock. This is why InitLogging should be called from the main | 502 // the lock. This is why InitLogging should be called from the main |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 | 573 |
| 575 CloseFile(log_file); | 574 CloseFile(log_file); |
| 576 log_file = NULL; | 575 log_file = NULL; |
| 577 } | 576 } |
| 578 | 577 |
| 579 } // namespace logging | 578 } // namespace logging |
| 580 | 579 |
| 581 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { | 580 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { |
| 582 return out << base::SysWideToUTF8(std::wstring(wstr)); | 581 return out << base::SysWideToUTF8(std::wstring(wstr)); |
| 583 } | 582 } |
| OLD | NEW |