Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ff9d1ea authored by Wei Wang's avatar Wei Wang Committed by Android (Google) Code Review
Browse files

Merge "Only set SCHED_RESET_ON_FORK flag if the thread is using the default...

Merge "Only set SCHED_RESET_ON_FORK flag if the thread is using the default scheduling policy." into main
parents f370ad3a b417208c
Loading
Loading
Loading
Loading
+32 −4
Original line number Diff line number Diff line
@@ -1059,8 +1059,22 @@ public final class HintManagerService extends SystemService {
                    throw new SecurityException(errMsg);
                }
                if (resetOnForkEnabled()){
                    try {
                        for (int tid : tids) {
                        Process.setThreadScheduler(tid, Process.SCHED_RESET_ON_FORK, 0);
                            int policy = Process.getThreadScheduler(tid);
                            // If the thread is not using the default scheduling policy (SCHED_OTHER),
                            // we don't change it.
                            if (policy != Process.SCHED_OTHER) {
                                continue;
                            }
                            // set the SCHED_RESET_ON_FORK flag.
                            int prio = Process.getThreadPriority(tid);
                            Process.setThreadScheduler(tid, Process.SCHED_OTHER | Process.SCHED_RESET_ON_FORK, 0);
                            Process.setThreadPriority(tid, prio);
                        }
                    } catch (Exception e) {
                        Slog.e(TAG, "Failed to set SCHED_RESET_ON_FORK for tids "
                                + Arrays.toString(tids), e);
                    }
                }

@@ -1454,8 +1468,22 @@ public final class HintManagerService extends SystemService {
                            throw new SecurityException(errMsg);
                        }
                        if (resetOnForkEnabled()){
                            try {
                                for (int tid : tids) {
                                Process.setThreadScheduler(tid, Process.SCHED_RESET_ON_FORK, 0);
                                    int policy = Process.getThreadScheduler(tid);
                                    // If the thread is not using the default scheduling policy (SCHED_OTHER),
                                    // we don't change it.
                                    if (policy != Process.SCHED_OTHER) {
                                        continue;
                                    }
                                    // set the SCHED_RESET_ON_FORK flag.
                                    int prio = Process.getThreadPriority(tid);
                                    Process.setThreadScheduler(tid, Process.SCHED_OTHER | Process.SCHED_RESET_ON_FORK, 0);
                                    Process.setThreadPriority(tid, prio);
                                }
                            } catch (Exception e) {
                                Slog.e(TAG, "Failed to set SCHED_RESET_ON_FORK for tids "
                                        + Arrays.toString(tids), e);
                            }
                        }
                        if (powerhintThreadCleanup()) {