gpui: Fix use of `libc::sched_param` on musl (#44846)

Lukas Wirth created

Release Notes:

- N/A *or* Added/Fixed/Improved ...

Change summary

crates/gpui/src/platform/linux/dispatcher.rs | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

Detailed changes

crates/gpui/src/platform/linux/dispatcher.rs 🔗

@@ -1,18 +1,21 @@
-use crate::{
-    GLOBAL_THREAD_TIMINGS, PlatformDispatcher, Priority, PriorityQueueReceiver,
-    PriorityQueueSender, RealtimePriority, RunnableVariant, THREAD_TIMINGS, TaskLabel, TaskTiming,
-    ThreadTaskTimings, profiler,
-};
 use calloop::{
     EventLoop, PostAction,
     channel::{self, Sender},
     timer::TimeoutAction,
 };
+use util::ResultExt;
+
 use std::{
+    mem::MaybeUninit,
     thread,
     time::{Duration, Instant},
 };
-use util::ResultExt;
+
+use crate::{
+    GLOBAL_THREAD_TIMINGS, PlatformDispatcher, Priority, PriorityQueueReceiver,
+    PriorityQueueSender, RealtimePriority, RunnableVariant, THREAD_TIMINGS, TaskLabel, TaskTiming,
+    ThreadTaskTimings, profiler,
+};
 
 struct TimerAfter {
     duration: Duration,
@@ -228,7 +231,10 @@ impl PlatformDispatcher for LinuxDispatcher {
                 RealtimePriority::Other => 45,
             };
 
-            let sched_param = libc::sched_param { sched_priority };
+            // SAFETY: all sched_param members are valid when initialized to zero.
+            let mut sched_param =
+                unsafe { MaybeUninit::<libc::sched_param>::zeroed().assume_init() };
+            sched_param.sched_priority = sched_priority;
             // SAFETY: sched_param is a valid initialized structure
             let result = unsafe { libc::pthread_setschedparam(thread_id, policy, &sched_param) };
             if result != 0 {