Chromium Code Reviews| Index: base/time/time_mac.cc |
| =================================================================== |
| --- base/time/time_mac.cc (revision 232726) |
| +++ base/time/time_mac.cc (working copy) |
| @@ -6,7 +6,11 @@ |
| #include <CoreFoundation/CFDate.h> |
| #include <CoreFoundation/CFTimeZone.h> |
| +#include <mach/mach_init.h> |
|
Robert Sesek
2013/11/05 18:32:07
Include mach/mach.h instead. It will also include
fmeawad
2013/11/05 19:34:25
Done.
|
| +#include <mach/mach_port.h> |
| #include <mach/mach_time.h> |
| +#include <mach/thread_act.h> |
| + |
|
Robert Sesek
2013/11/05 18:32:07
nit: remove this blank line
fmeawad
2013/11/05 19:34:25
Done.
|
| #include <sys/sysctl.h> |
| #include <sys/time.h> |
| #include <sys/types.h> |
| @@ -64,6 +68,36 @@ |
| #endif // defined(OS_IOS) |
| } |
| +uint64_t ComputeThreadTicks() { |
| +#if defined(OS_IOS) |
| + NOTREACHED(); |
|
Robert Sesek
2013/11/05 18:32:07
NOTREACHED() or NOTIMPLEMENTED()? Can this be impl
fmeawad
2013/11/05 19:34:25
It can be implemented, but it should not be reache
fmeawad
2013/11/05 21:59:49
Done.
|
| + return 0; |
| +#else |
| + mach_port_t thread; |
|
Robert Sesek
2013/11/05 18:32:07
Why break up declaration from initialization?
fmeawad
2013/11/05 19:34:25
Done.
|
| + mach_msg_type_number_t thread_info_count = THREAD_BASIC_INFO_COUNT; |
| + thread_basic_info_data_t thread_info_data; |
| + |
| + thread = mach_thread_self(); |
|
Robert Sesek
2013/11/05 18:32:07
This is leaked. Store this in a ScopedMachPort.
fmeawad
2013/11/05 19:34:25
Done.
|
| + if (thread == MACH_PORT_NULL) |
| + return 0; |
| + |
| + kern_return_t kr; |
|
Robert Sesek
2013/11/05 18:32:07
Same. No need to break up declaration from initial
fmeawad
2013/11/05 19:34:25
Done.
|
| + |
| + kr = thread_info(thread, |
| + THREAD_BASIC_INFO, |
| + reinterpret_cast<thread_info_t>(&thread_info_data), |
| + &thread_info_count); |
| + |
| + if (kr != KERN_SUCCESS) { |
| + return 0; |
|
Robert Sesek
2013/11/05 18:32:07
No logging or DCHECKing for failure?
fmeawad
2013/11/05 19:34:25
Done.
|
| + } |
| + |
| + return (thread_info_data.user_time.seconds * |
| + base::Time::kMicrosecondsPerSecond) + |
| + thread_info_data.user_time.microseconds; |
|
Robert Sesek
2013/11/05 18:32:07
nit: align this to underneath the (
fmeawad
2013/11/05 19:34:25
Done.
|
| +#endif // defined(OS_IOS) |
| +} |
| + |
| } // namespace |
| namespace base { |
| @@ -196,8 +230,7 @@ |
| // static |
| TimeTicks TimeTicks::ThreadNow() { |
| - NOTREACHED(); |
| - return TimeTicks(); |
| + return TimeTicks(ComputeThreadTicks()); |
| } |
| // static |