Increase result dispatcher thread priority

When the system has high CPU load, result dispatcher thread is frequently
in runnable state and causes the delay to post the result to the framework.

Bug: 237909133
Test: GCA, CTS, frame rate test
Change-Id: I7be2d6d38f36439eb25b03e15aa3f76cb97c152a
diff --git a/common/hal/utils/result_dispatcher.cc b/common/hal/utils/result_dispatcher.cc
index 6aa2d12..fdf9502 100644
--- a/common/hal/utils/result_dispatcher.cc
+++ b/common/hal/utils/result_dispatcher.cc
@@ -21,6 +21,7 @@
 
 #include <inttypes.h>
 #include <log/log.h>
+#include <sys/resource.h>
 #include <utils/Trace.h>
 
 #include <string>
@@ -67,6 +68,15 @@
     } else {
       ALOGI("[%s] %s: SetRealtimeThread OK", name_.c_str(), __FUNCTION__);
     }
+  } else {
+    // Assign higher priority to reduce the preemption when CPU usage is high
+    int32_t res = setpriority(
+        PRIO_PROCESS,
+        pthread_gettid_np(notify_callback_thread_.native_handle()), -20);
+    if (res != 0) {
+      ALOGE("[%s] %s: Set thread priority fail with error: %s", name_.c_str(),
+            __FUNCTION__, strerror(errno));
+    }
   }
 }