OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_POSIX) | 21 #elif defined(OS_POSIX) |
| 22 #if defined(OS_NACL) |
| 23 #include <sys/nacl_syscalls.h> |
| 24 #include <sys/time.h> // timespec doesn't seem to be in <time.h> |
| 25 #else |
22 #include <sys/syscall.h> | 26 #include <sys/syscall.h> |
| 27 #endif |
23 #include <time.h> | 28 #include <time.h> |
24 #endif | 29 #endif |
25 | 30 |
26 #if defined(OS_POSIX) | 31 #if defined(OS_POSIX) |
27 #include <errno.h> | 32 #include <errno.h> |
28 #include <pthread.h> | 33 #include <pthread.h> |
29 #include <stdlib.h> | 34 #include <stdlib.h> |
30 #include <stdio.h> | 35 #include <stdio.h> |
31 #include <string.h> | 36 #include <string.h> |
32 #include <unistd.h> | 37 #include <unistd.h> |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 int32 CurrentThreadId() { | 126 int32 CurrentThreadId() { |
122 #if defined(OS_WIN) | 127 #if defined(OS_WIN) |
123 return GetCurrentThreadId(); | 128 return GetCurrentThreadId(); |
124 #elif defined(OS_MACOSX) | 129 #elif defined(OS_MACOSX) |
125 return mach_thread_self(); | 130 return mach_thread_self(); |
126 #elif defined(OS_LINUX) | 131 #elif defined(OS_LINUX) |
127 return syscall(__NR_gettid); | 132 return syscall(__NR_gettid); |
128 #elif defined(OS_FREEBSD) | 133 #elif defined(OS_FREEBSD) |
129 // TODO(BSD): find a better thread ID | 134 // TODO(BSD): find a better thread ID |
130 return reinterpret_cast<int64>(pthread_self()); | 135 return reinterpret_cast<int64>(pthread_self()); |
| 136 #elif defined(OS_NACL) |
| 137 return pthread_self(); |
131 #endif | 138 #endif |
132 } | 139 } |
133 | 140 |
134 uint64 TickCount() { | 141 uint64 TickCount() { |
135 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
136 return GetTickCount(); | 143 return GetTickCount(); |
137 #elif defined(OS_MACOSX) | 144 #elif defined(OS_MACOSX) |
138 return mach_absolute_time(); | 145 return mach_absolute_time(); |
| 146 #elif defined(OS_NACL) |
| 147 // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h |
| 148 // So we have to use clock() for now. |
| 149 return clock(); |
139 #elif defined(OS_POSIX) | 150 #elif defined(OS_POSIX) |
140 struct timespec ts; | 151 struct timespec ts; |
141 clock_gettime(CLOCK_MONOTONIC, &ts); | 152 clock_gettime(CLOCK_MONOTONIC, &ts); |
142 | 153 |
143 uint64 absolute_micro = | 154 uint64 absolute_micro = |
144 static_cast<int64>(ts.tv_sec) * 1000000 + | 155 static_cast<int64>(ts.tv_sec) * 1000000 + |
145 static_cast<int64>(ts.tv_nsec) / 1000; | 156 static_cast<int64>(ts.tv_nsec) / 1000; |
146 | 157 |
147 return absolute_micro; | 158 return absolute_micro; |
148 #endif | 159 #endif |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 | 821 |
811 if (level == LOG_FATAL) | 822 if (level == LOG_FATAL) |
812 base::debug::BreakDebugger(); | 823 base::debug::BreakDebugger(); |
813 } | 824 } |
814 | 825 |
815 } // namespace logging | 826 } // namespace logging |
816 | 827 |
817 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { | 828 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { |
818 return out << WideToUTF8(std::wstring(wstr)); | 829 return out << WideToUTF8(std::wstring(wstr)); |
819 } | 830 } |
OLD | NEW |