Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2458)

Unified Diff: base/time/time_mac.cc

Issue 56973012: Implement Time::ThreadNow() on Mac. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: exclude OS_IOS from the IsThreadNowSupported check Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/time/time_mac.cc
===================================================================
--- base/time/time_mac.cc (revision 232726)
+++ base/time/time_mac.cc (working copy)
@@ -6,6 +6,7 @@
#include <CoreFoundation/CFDate.h>
#include <CoreFoundation/CFTimeZone.h>
+#include <mach/mach.h>
#include <mach/mach_time.h>
#include <sys/sysctl.h>
#include <sys/time.h>
@@ -15,6 +16,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/mac/scoped_cftyperef.h"
+#include "base/mac/scoped_mach_port.h"
namespace {
@@ -64,6 +66,33 @@
#endif // defined(OS_IOS)
}
+uint64_t ComputeThreadTicks() {
+#if defined(OS_IOS)
+ NOTREACHED();
+ return 0;
+#else
+ base::mac::ScopedMachPort thread(mach_thread_self());
+ mach_msg_type_number_t thread_info_count = THREAD_BASIC_INFO_COUNT;
+ thread_basic_info_data_t thread_info_data;
+
+ if (thread == MACH_PORT_NULL) {
+ DLOG(ERROR) << "Failed to get mach_thread_self()";
+ return 0;
+ }
+
+ kern_return_t kr = thread_info(
+ thread,
+ THREAD_BASIC_INFO,
+ reinterpret_cast<thread_info_t>(&thread_info_data),
+ &thread_info_count);
+ DCHECK_EQ(KERN_SUCCESS, kr);
+
+ return (thread_info_data.user_time.seconds *
+ base::Time::kMicrosecondsPerSecond) +
+ thread_info_data.user_time.microseconds;
+#endif // defined(OS_IOS)
+}
+
} // namespace
namespace base {
@@ -196,8 +225,7 @@
// static
TimeTicks TimeTicks::ThreadNow() {
- NOTREACHED();
- return TimeTicks();
+ return TimeTicks(ComputeThreadTicks());
}
// static
« no previous file with comments | « base/time/time.h ('k') | base/time/time_unittest.cc » ('j') | base/time/time_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698