ladybird/Userland/Libraries
kleines Filmröllchen 125122a9ab LibAudio: Prevent racy eternal deadlock of the audio enqueue thread
The audio enqueuer thread goes to sleep when there is no more audio data
present, and through normal Core::EventLoop events it can be woken up.
However, that waking up only happens when the thread is not currently
running, so that the wake-up events don't queue up and cause weirdness.
The atomic variable responsible for keeping track of whether the thread
is active can lead to a racy deadlock however, where the audio enqueuer
thread will never wake up again despite there being audio data to
enqueue. Consider this scenario:

- Main thread calls into async_enqueue. It detects that according to the
  atomic variable, the other thread is still running, skipping the event
  queue wake.
- Enqueuer thread has just finished playing the last chunk of audio and
  detects that there is no audio left. It enters the if block with the
  dbgln "Reached end of provided audio data..."
- Main thread enqueues audio, making the user sample queue non-empty.
- Enqueuer thread does not check this condition again, instead setting
  the atomic variable to indicate that it is not running. It exits into
  an event loop sleep.
- Main thread exits async_enqueue. The calling audio enqueuing system
  (see e.g. Piano, but all of them function similarly) will wait until
  the enqueuer thread has played enough samples before async_enqueue is
  called again. However, since the enqueuer thread will never play any
  audio, this condition is never fulfilled and audio playback deadlocks

This commit fixes that by allowing the event loop to not enqueue an
event that already exists, therefore overloading the audio enqueuer
event loop by at maximum one message in weird situations. We entirely
get rid of the atomic variable and the race condition is prevented.
2022-07-22 19:35:41 +01:00
..
LibArchive Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibAudio LibAudio: Prevent racy eternal deadlock of the audio enqueue thread 2022-07-22 19:35:41 +01:00
LibC LibC: Mark a bunch of functions as cancellation points 2022-07-22 10:07:15 -07:00
LibCards Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibChess Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibCodeComprehension Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibCompress LibCompress: Write Deflate window size in the Zlib header 2022-07-10 13:52:18 +03:00
LibConfig LibConfig+ConfigServer: Write config values synchronously 2022-04-26 22:51:49 +02:00
LibCore LibAudio: Prevent racy eternal deadlock of the audio enqueue thread 2022-07-22 19:35:41 +01:00
LibCoredump Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibCpp Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibCrypt Everywhere: Explicitly specify the size in StringView constructors 2022-07-12 23:11:35 +02:00
LibCrypto LibCrypto: Expose UnsignedBigInteger's is_zero() in SignedBigInteger 2022-07-18 08:51:07 +01:00
LibDebug Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibDesktop LaunchServer+SystemServer: Move the portal to a user-specific directory 2022-07-19 11:15:14 +01:00
LibDeviceTree
LibDiff Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
LibDl Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
LibDNS Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibDSP LibDSP: Rename library namespace to DSP 2022-07-19 11:17:45 +01:00
LibEDID Everywhere: Split Error::from_string_literal and Error::from_string_view 2022-07-12 23:11:35 +02:00
LibELF Utilities+LibELF: Temporary promises for dynamic linker in "pledge" 2022-07-21 16:40:11 +02:00
LibFileSystemAccessClient Everywhere: Split Error::from_string_literal and Error::from_string_view 2022-07-12 23:11:35 +02:00
LibGemini Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibGfx AK+LibGfx+LibJS: Pass -1 as the file descriptor to anonymous mmap 2022-07-19 12:39:24 +02:00
LibGL Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibGPU LibGPU: Do not load LibSoftGPU via symlink inside Serenity 2022-06-13 21:45:27 +01:00
LibGUI LibGUI: Add MoveLineUpOrDownCommand 2022-07-19 10:49:38 +01:00
LibHTTP Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibImageDecoderClient Userland: Rename IPC::ServerConnection=>IPC::ConnectionToServer 2022-02-25 22:35:12 +01:00
LibIMAP Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibIPC LibIPC: Retry post_message write on EAGAIN and yield 2022-07-15 12:38:35 +02:00
LibJS LibJS: Add tests for %TypedArray%.prototype.with 2022-07-22 17:17:15 +01:00
LibKeyboard Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibLine LibLine: Ignore empty spans when stylizing 2022-07-17 00:51:31 +00:00
LibM LibM: Implement fma 2022-07-08 22:27:38 +00:00
LibMain Everywhere: Explicitly specify the size in StringView constructors 2022-07-12 23:11:35 +02:00
LibMarkdown Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibPartition LibPartition: Fix end block off by one error 2022-07-21 20:13:44 +01:00
LibPCIDB Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibPDF Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibProtocol LibCore+Everywhere: Make Core::Stream::read() return Bytes 2022-04-16 13:27:51 -04:00
LibRegex LibRegex: Check code unit count range when accessing by code unit count 2022-07-20 21:25:59 +01:00
LibSanitizer Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibSoftGPU Everywhere: Fix a bunch of typos 2022-05-29 15:22:00 +02:00
LibSQL Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibSymbolication Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibSyntax Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
LibSystem Meta+Userland: Add ENABLE_USERSPACE_COVERAGE_COLLECTION CMake option 2022-05-02 01:46:18 +02:00
LibTest LibCore: Replace the ArgsParser option argument setting with an enum 2022-07-14 00:24:24 +01:00
LibTextCodec Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibThreading LibThreading: Add is_started state information to Thread 2022-07-22 19:35:41 +01:00
LibTimeZone Everywhere: Explicitly specify the size in StringView constructors 2022-07-12 23:11:35 +02:00
LibTLS Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibUnicode LibUnicode: Generate per-locale data for the "noon" fixed day period 2022-07-21 20:36:03 +01:00
LibUSBDB Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibVideo Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibVT LibVT: Remove Vector<Kernel::KString> title stack 2022-07-14 13:13:48 +02:00
LibWasm Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibWeb LibWeb: Allow calc() inside CSS transform functions :^) 2022-07-21 16:36:08 +02:00
LibWebSocket Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibWebView Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LibX86 Everywhere: Replace single-char StringView op. arguments with chars 2022-07-12 23:11:35 +02:00
LibXML Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
CMakeLists.txt Kernel+LibPartition: Move DiskPartitionMetadata into LibPartition 2022-07-21 20:13:44 +01:00