Index: webrtc/base/platform_thread.cc |
diff --git a/webrtc/base/platform_thread.cc b/webrtc/base/platform_thread.cc |
index 52f88106b7cab16f34fc4c3e2b233ba047a1a642..5c95c5f156119a5257b9f75a778bf6ff29ed7eb2 100644 |
--- a/webrtc/base/platform_thread.cc |
+++ b/webrtc/base/platform_thread.cc |
@@ -10,8 +10,11 @@ |
#include "webrtc/base/platform_thread.h" |
+#include <inttypes.h> |
the sun
2017/03/01 23:31:36
stdint.h
tommi
2017/03/02 14:11:59
removed now
|
+ |
#include "webrtc/base/atomicops.h" |
#include "webrtc/base/checks.h" |
+#include "webrtc/base/timeutils.h" |
#if defined(WEBRTC_LINUX) |
#include <sys/prctl.h> |
@@ -220,26 +223,42 @@ void PlatformThread::Run() { |
run_function_(obj_); |
return; |
} |
-// TODO(tommi): Delete the below. |
-#if !defined(WEBRTC_MAC) && !defined(WEBRTC_WIN) |
- const struct timespec ts_null = {0}; |
+ |
+ // TODO(tommi): Delete the rest of this function when looping isn't supported. |
+#if RTC_DCHECK_IS_ON |
+ static const int kMaxLoopCount = 1000; |
+ static const int kPeriodToMeasureMs = 100; |
+ int64_t loop_stamps[kMaxLoopCount] = {}; |
+ int64_t sequence_nr = 0; |
#endif |
+ |
do { |
// The interface contract of Start/Stop is that for a successful call to |
// Start, there should be at least one call to the run function. So we |
// call the function before checking |stop_|. |
if (!run_function_deprecated_(obj_)) |
break; |
+#if RTC_DCHECK_IS_ON |
the sun
2017/03/01 23:31:36
A comment wouldn't hurt, considering the above con
tommi
2017/03/02 14:11:59
Done.
|
+ auto id = sequence_nr % kMaxLoopCount; |
+ loop_stamps[id] = rtc::TimeMillis(); |
+ if (sequence_nr > kMaxLoopCount) { |
+ auto compare_id = (id + 1) % kMaxLoopCount; |
+ auto diff = loop_stamps[id] - loop_stamps[compare_id]; |
the sun
2017/03/01 23:31:36
Why do you store the whole sequence, when you're o
tommi
2017/03/02 14:11:59
Since this is a sliding window, the last time stam
the sun
2017/03/02 14:20:09
Ah, got the indices wrong - thanks for explaining.
|
+ RTC_DCHECK_GE(diff, 0); |
+ if (diff < kPeriodToMeasureMs) { |
+ RTC_NOTREACHED() << "This thread is too busy: " << name_ << " " << diff |
+ << "ms sequence=" << sequence_nr << " " << loop_stamps[id] << " vs " |
+ << loop_stamps[compare_id] << ", " << id << " vs " << compare_id; |
+ } |
+ } |
+ ++sequence_nr; |
+#endif |
#if defined(WEBRTC_WIN) |
// Alertable sleep to permit RaiseFlag to run and update |stop_|. |
SleepEx(0, true); |
} while (!stop_); |
#else |
-#if defined(WEBRTC_MAC) |
sched_yield(); |
-#else |
- nanosleep(&ts_null, nullptr); |
-#endif |
} while (!AtomicOps::AcquireLoad(&stop_flag_)); |
#endif // defined(WEBRTC_WIN) |
} |