| 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 <io.h> | 8 #include <io.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 typedef HANDLE FileHandle; | 10 typedef HANDLE FileHandle; |
| 11 typedef HANDLE MutexHandle; | 11 typedef HANDLE MutexHandle; |
| 12 // Windows warns on using write(). It prefers _write(). | 12 // Windows warns on using write(). It prefers _write(). |
| 13 #define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count)) | 13 #define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count)) |
| 14 // Windows doesn't define STDERR_FILENO. Define it here. | 14 // Windows doesn't define STDERR_FILENO. Define it here. |
| 15 #define STDERR_FILENO 2 | 15 #define STDERR_FILENO 2 |
| 16 #elif defined(OS_MACOSX) | 16 #elif defined(OS_MACOSX) |
| 17 #include <CoreFoundation/CoreFoundation.h> | 17 #include <CoreFoundation/CoreFoundation.h> |
| 18 #include <mach/mach.h> | 18 #include <mach/mach.h> |
| 19 #include <mach/mach_time.h> | 19 #include <mach/mach_time.h> |
| 20 #include <mach-o/dyld.h> | 20 #include <mach-o/dyld.h> |
| 21 #elif defined(OS_LINUX) | 21 #elif defined(OS_POSIX) |
| 22 #include <sys/syscall.h> | 22 #include <sys/syscall.h> |
| 23 #include <time.h> | 23 #include <time.h> |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 #if defined(OS_POSIX) | 26 #if defined(OS_POSIX) |
| 27 #include <errno.h> | 27 #include <errno.h> |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 #include <stdio.h> | 29 #include <stdio.h> |
| 30 #include <string.h> | 30 #include <string.h> |
| 31 #include <unistd.h> | 31 #include <unistd.h> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 #endif | 130 #endif |
| 131 } | 131 } |
| 132 | 132 |
| 133 int32 CurrentThreadId() { | 133 int32 CurrentThreadId() { |
| 134 #if defined(OS_WIN) | 134 #if defined(OS_WIN) |
| 135 return GetCurrentThreadId(); | 135 return GetCurrentThreadId(); |
| 136 #elif defined(OS_MACOSX) | 136 #elif defined(OS_MACOSX) |
| 137 return mach_thread_self(); | 137 return mach_thread_self(); |
| 138 #elif defined(OS_LINUX) | 138 #elif defined(OS_LINUX) |
| 139 return syscall(__NR_gettid); | 139 return syscall(__NR_gettid); |
| 140 #elif defined(OS_FREEBSD) |
| 141 // TODO(BSD): find a better thread ID |
| 142 return reinterpret_cast<int64>(pthread_self()); |
| 140 #endif | 143 #endif |
| 141 } | 144 } |
| 142 | 145 |
| 143 uint64 TickCount() { | 146 uint64 TickCount() { |
| 144 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
| 145 return GetTickCount(); | 148 return GetTickCount(); |
| 146 #elif defined(OS_MACOSX) | 149 #elif defined(OS_MACOSX) |
| 147 return mach_absolute_time(); | 150 return mach_absolute_time(); |
| 148 #elif defined(OS_LINUX) | 151 #elif defined(OS_POSIX) |
| 149 struct timespec ts; | 152 struct timespec ts; |
| 150 clock_gettime(CLOCK_MONOTONIC, &ts); | 153 clock_gettime(CLOCK_MONOTONIC, &ts); |
| 151 | 154 |
| 152 uint64 absolute_micro = | 155 uint64 absolute_micro = |
| 153 static_cast<int64>(ts.tv_sec) * 1000000 + | 156 static_cast<int64>(ts.tv_sec) * 1000000 + |
| 154 static_cast<int64>(ts.tv_nsec) / 1000; | 157 static_cast<int64>(ts.tv_nsec) / 1000; |
| 155 | 158 |
| 156 return absolute_micro; | 159 return absolute_micro; |
| 157 #endif | 160 #endif |
| 158 } | 161 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 #elif defined(OS_POSIX) | 222 #elif defined(OS_POSIX) |
| 220 log_file = fopen(log_file_name->c_str(), "a"); | 223 log_file = fopen(log_file_name->c_str(), "a"); |
| 221 if (log_file == NULL) | 224 if (log_file == NULL) |
| 222 return false; | 225 return false; |
| 223 #endif | 226 #endif |
| 224 } | 227 } |
| 225 | 228 |
| 226 return true; | 229 return true; |
| 227 } | 230 } |
| 228 | 231 |
| 229 #if defined(OS_LINUX) | 232 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 230 int GetLoggingFileDescriptor() { | 233 int GetLoggingFileDescriptor() { |
| 231 // No locking needed, since this is only called by the zygote server, | 234 // No locking needed, since this is only called by the zygote server, |
| 232 // which is single-threaded. | 235 // which is single-threaded. |
| 233 if (log_file) | 236 if (log_file) |
| 234 return fileno(log_file); | 237 return fileno(log_file); |
| 235 return -1; | 238 return -1; |
| 236 } | 239 } |
| 237 #endif | 240 #endif |
| 238 | 241 |
| 239 void InitLogMutex() { | 242 void InitLogMutex() { |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 | 722 |
| 720 if (level == LOG_FATAL) | 723 if (level == LOG_FATAL) |
| 721 DebugUtil::BreakDebugger(); | 724 DebugUtil::BreakDebugger(); |
| 722 } | 725 } |
| 723 | 726 |
| 724 } // namespace logging | 727 } // namespace logging |
| 725 | 728 |
| 726 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { | 729 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { |
| 727 return out << WideToUTF8(std::wstring(wstr)); | 730 return out << WideToUTF8(std::wstring(wstr)); |
| 728 } | 731 } |
| OLD | NEW |