// Keep-awake helper for run.py: a user-interactive thread that spins (GIL released, called through ctypes) while // requests are being served. Without it macOS lowers the CPU cluster clock while the encode thread waits on the // GPU; MLX then encodes slower, the GPU starves and also clocks down, and per-request latency drifts 5 -> 15 ms. #include #include void spin_while(volatile int *flag) { pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0); while (*flag) { __asm__ volatile("yield"); } }