Skip to content

Conversation

@aconverse
Copy link

1. Eliminated Main Thread Initialization Race
Original: Had a two-step initialization where InitializeOnMainThread fetched GPU factories, then posted to media thread.
Fix: Moved GPU factories fetching to a synchronous call before creating DiscordVideoDecoderMediaThread, eliminating the race between initialization and potential early deletion.

2. Introduced Proper Promise/Future Pattern
Original: Used raw pointers with WaitableEvent that could be destroyed while still being accessed.
Fix: Added WaitableSharedObject<T> using RefCountedThreadSafe to ensure the waiter object stays alive until completion. Note: Chromium does not use std::promise / std::future so these are work alikes.

3. Fixed DeleteSoon Race
Original: Checked gpu_factories_ which was set asynchronously, creating a race where deletion could occur before initialization completed.
Fix: Always has media_task_runner_ available from construction, ensuring proper thread-safe deletion.

4. Added GUARDED_BY Annotations
Original: several members were properly mutex guarded but could easily be accidentally accessed in an unguarded context.
Fix: GUARDED_BY annotations turn improper access into a compiler error.
@aconverse aconverse closed this Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants