| 271 | } |
| 272 | |
| 273 | static void Init(LogLockingState lock_log, const LogChar* new_log_file) { |
| 274 | if (initialized) |
| 275 | return; |
| 276 | lock_log_file = lock_log; |
| 277 | if (lock_log_file == LOCK_LOG_FILE) { |
| 278 | #if defined(OS_WIN) |
| 279 | if (!log_mutex) { |
| 280 | std::wstring safe_name; |
| 281 | if (new_log_file) |
| 282 | safe_name = new_log_file; |
| 283 | else |
| 284 | safe_name = GetDefaultLogFile(); |
| 285 | // \ is not a legal character in mutex names so we replace \ with / |
| 286 | std::replace(safe_name.begin(), safe_name.end(), '\\', '/'); |
| 287 | std::wstring t(L"Global\\"); |
| 288 | t.append(safe_name); |
| 289 | log_mutex = ::CreateMutex(NULL, FALSE, t.c_str()); |
| 290 | |
| 291 | if (log_mutex == NULL) { |
| 292 | #if DEBUG |
| 293 | // Keep the error code for debugging |
| 294 | int error = GetLastError(); // NOLINT |
| 295 | butil::debug::BreakDebugger(); |
| 296 | #endif |
| 297 | // Return nicely without putting initialized to true. |
| 298 | return; |
| 299 | } |
| 300 | } |
| 301 | #endif |
| 302 | } else { |
| 303 | log_lock = new butil::Mutex; |
| 304 | } |
| 305 | initialized = true; |
| 306 | } |
| 307 | |
| 308 | private: |
| 309 | static void LockLogging() { |
nothing calls this directly
no test coverage detected