Bug 1810244 - restrict use of dynamic thread names via moz_task r=application-update-reviewers,bytesized,emilio

Bug 1613440 added a checker to prevent a profusion of new threads.
Unfortunately, it operates directly on C++ source code, and there is no
equivalent for Rust code.

It _is_ possible to construct such an equivalent (see bug 1810242), but
it's nontrivial. For now, let's just prevent the use of dynamic thread
names, to minimize the profusion of uninterestingly-distinct thread
names in our `XPCOMSpinEventLoopStack` crash-report field.

Differential Revision: https://phabricator.services.mozilla.com/D166842
This commit is contained in:
Ray Kraesig 2023-01-16 16:02:13 +00:00
Родитель e2cdc7e8c3
Коммит 7f1075b129
2 изменённых файлов: 5 добавлений и 2 удалений

Просмотреть файл

@ -139,7 +139,7 @@ impl BitsRequest {
) -> Result<RefPtr<BitsRequest>, BitsTaskError> {
let _ = context;
let action: Action = action.into();
let monitor_thread = create_thread(&format!("BitsMonitor {}", id)).map_err(|rv| {
let monitor_thread = create_thread("BitsMonitor").map_err(|rv| {
BitsTaskError::from_nsresult(FailedToStartThread, action, MainThread, rv)
})?;

Просмотреть файл

@ -66,7 +66,10 @@ pub fn is_main_thread() -> bool {
unsafe { NS_IsMainThread() }
}
pub fn create_thread(name: &str) -> Result<RefPtr<nsIThread>, nsresult> {
// There's no OS requirement that thread names be static, but dynamic thread
// names tend to conceal more than they reveal when processing large numbers of
// crash reports.
pub fn create_thread(name: &'static str) -> Result<RefPtr<nsIThread>, nsresult> {
getter_addrefs(|p| unsafe {
NS_NewNamedThreadWithDefaultStackSize(&*nsCString::from(name), p, ptr::null())
})