Merge "Avoid busy empty loop" am: 2724a3642a

Original change: https://android-review.googlesource.com/c/platform/external/perfetto/+/1916402

Change-Id: Ib0037793b7099c0606b82d63589e435d80fcaaab
diff --git a/Android.bp b/Android.bp
index 57ce922..42c037f 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1907,7 +1907,6 @@
         "-DGOOGLE_PROTOBUF_NO_RTTI",
         "-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
         "-DHAVE_HIDDEN",
-        "-fno-finite-loops",
     ],
     header_libs: [
         "bionic_libc_platform_headers",
diff --git a/src/profiling/memory/heapprofd_end_to_end_test.cc b/src/profiling/memory/heapprofd_end_to_end_test.cc
index 3db57ee..df08bd9 100644
--- a/src/profiling/memory/heapprofd_end_to_end_test.cc
+++ b/src/profiling/memory/heapprofd_end_to_end_test.cc
@@ -312,6 +312,9 @@
 
   // Wait around so we can verify it did't crash.
   for (;;) {
+    // Call sleep, otherwise an empty busy loop is undefined behavior:
+    // http://en.cppreference.com/w/cpp/language/memory_model#Progress_guarantee
+    sleep(1);
   }
 }
 
@@ -351,6 +354,9 @@
 
   // Wait around so we can verify it did't crash.
   for (;;) {
+    // Call sleep, otherwise an empty busy loop is undefined behavior:
+    // http://en.cppreference.com/w/cpp/language/memory_model#Progress_guarantee
+    sleep(1);
   }
 }
 
@@ -387,6 +393,9 @@
 
   // Wait around so we can verify it did't crash.
   for (;;) {
+    // Call sleep, otherwise an empty busy loop is undefined behavior:
+    // http://en.cppreference.com/w/cpp/language/memory_model#Progress_guarantee
+    sleep(1);
   }
 }
 
@@ -493,6 +502,9 @@
 
   // Wait around so we can verify it didn't crash.
   for (;;) {
+    // Call sleep, otherwise an empty busy loop is undefined behavior:
+    // http://en.cppreference.com/w/cpp/language/memory_model#Progress_guarantee
+    sleep(1);
   }
 }
 
diff --git a/tools/gen_android_bp b/tools/gen_android_bp
index af7d95d..262da04 100755
--- a/tools/gen_android_bp
+++ b/tools/gen_android_bp
@@ -204,7 +204,6 @@
         ('include_dirs', {'bionic/libc/kernel'}),
     ],
     'perfetto_integrationtests': [
-        ('cflags', {'-fno-finite-loops'}),
         ('test_suites', {'general-tests'}),
         ('test_config', 'PerfettoIntegrationTests.xml'),
     ],