void ScopedPriorityChange::SetToNormalOrBetter() { staticbool enabled = com::android::libcore::niceness_apis(); if (!enabled) { return;
}
DCHECK(!priority_changed_); int cached_niceness = self_->GetCachedNiceness(); if (cached_niceness > 0/* excludes no Java peer case */) { int old_niceness = getpriority(PRIO_PROCESS, 0); if (old_niceness == cached_niceness) { // Reduce nicenesss to zero, increasing our priority. // Should succeed on Android; will probably fail elsewhere. int ret = setpriority(PRIO_PROCESS, 0, 0); if (ret == 0) { // Maintain old niceness in thread structure, so we can determine "real" niceness without // acquiring the mutator lock.
self_->SetNicenessBeforeBoost(old_niceness);
priority_changed_ = true;
}
} elseif (old_niceness > 0) { // Priority increase is warranted, but cache is out of sync.
LOG(WARNING) << "Cached niceness = " << cached_niceness
<< "; actual niceness = " << old_niceness;
}
}
}
void ScopedPriorityChange::ResetInternal() {
DCHECK(priority_changed_);
DCHECK_GT(self_->GetNicenessBeforeBoost(), 0);
DCHECK(com::android::libcore::niceness_apis());
Locks::mutator_lock_->AssertSharedHeld(self_);
self_->SetNicenessBeforeBoost(Thread::kNotBoosted); // Do this even if getpriority() test // fails. if (getpriority(PRIO_PROCESS, 0) == 0) { // We changed priority and nobody visibly altered it in the interim; change it to the current // cached value. int cached_niceness = self_->GetCachedNiceness(); int old_cached_niceness; // We cannot acquire the Java monitor that normally protects the niceness field here, since that // would sometimes require us to suspend. We instead rely on the fact that any updates to the // niceness fields while the thread is running are followed by a setpriority() call with the // same niceness value. do { int ret = setpriority(PRIO_PROCESS, 0, cached_niceness); // Increasing our niceness should always work, especially since decreasing it did.
CHECK_EQ(ret, 0) << strerror(errno);
old_cached_niceness = cached_niceness;
cached_niceness = self_->GetCachedNiceness(); // If it changed in the interim, we may have restored an obsolete niceness value, and we // need to fix that. Otherwise any later updates will come with following setpriority() // calls, which will overwrite ours.
} while (cached_niceness != old_cached_niceness);
} else {
LOG(WARNING) << "Priority change inside ScopedPriorityChange"; // Do not restore priority, since somebody else changed it in the interim.
}
}
} // namespace art
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.