ladybird/Userland/Libraries/LibCore
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
..
Account.cpp LaunchServer+SystemServer: Move the portal to a user-specific directory 2022-07-19 11:15:14 +01:00
Account.h LibCore: Add FIXME note about converting Core::Account to use StringView 2022-07-12 23:11:35 +02:00
AnonymousBuffer.cpp LibCore: Convert AnonymousBuffer to use System::anon_create 2022-02-10 21:35:17 +01:00
AnonymousBuffer.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
ArgsParser.cpp LibCore: Add support for long integral types to ArgsParser 2022-07-21 16:37:04 +02:00
ArgsParser.h LibCore: Implement integral ArgsParser options through a template 2022-07-21 16:37:04 +02:00
CMakeLists.txt LibCore: Add support for compiling for Android with API Version >= 30 2022-07-19 10:44:02 +01:00
Command.cpp Everywhere: Split Error::from_string_literal and Error::from_string_view 2022-07-12 23:11:35 +02:00
Command.h Everywhere: Rename CommandResult stdout, stderr members to output, error 2022-03-27 16:41:39 -07:00
ConfigFile.cpp LibCore: Remove ConfigFile::write_color_entry() 2022-06-05 22:42:35 +01:00
ConfigFile.h LibCore: Remove ConfigFile::write_color_entry() 2022-06-05 22:42:35 +01:00
DateTime.cpp LibCore: Do not refer to extern int daylight in DateTime::to_string 2022-07-19 12:39:24 +02:00
DateTime.h Userland: Remove a few gratuitous IPC namespace qualifiers 2022-04-03 15:18:20 +01:00
Debounce.h LibCore: Add Core::debounce(function, timeout) 2022-07-19 11:10:02 +01:00
DeferredInvocationContext.h Libraries: Use default constructors/destructors in LibCore 2022-03-10 18:04:26 -08:00
Directory.cpp LibCore: Add an optional permissions mask to Directory::create() 2022-04-13 16:00:17 +02:00
Directory.h Meta+Userland: Simplify some formatters 2022-07-12 23:11:35 +02:00
DirIterator.cpp Userland: Fail Core::find_executable_in_path on empty inputs 2022-01-04 07:38:42 +00:00
DirIterator.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
ElapsedTimer.cpp LibCore: Add ElapsedTimer::reset() 2021-10-28 11:21:18 +02:00
ElapsedTimer.h LibCore: Add ElapsedTimer::reset() 2021-10-28 11:21:18 +02:00
Event.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Event.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
EventLoop.cpp LibAudio: Prevent racy eternal deadlock of the audio enqueue thread 2022-07-22 19:35:41 +01:00
EventLoop.h LibAudio: Prevent racy eternal deadlock of the audio enqueue thread 2022-07-22 19:35:41 +01:00
File.cpp LibCore: Add File::is_{block,char}_device() helpers 2022-07-21 20:13:44 +01:00
File.h LibCore: Add File::is_{block,char}_device() helpers 2022-07-21 20:13:44 +01:00
FilePermissionsMask.cpp Everywhere: Split Error::from_string_literal and Error::from_string_view 2022-07-12 23:11:35 +02:00
FilePermissionsMask.h LibCore: Add FilePermissionsMask 2022-01-01 17:33:43 +00:00
FileStream.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
FileWatcher.cpp Everywhere: Explicitly specify the size in StringView constructors 2022-07-12 23:11:35 +02:00
FileWatcher.h Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
Forward.h Core: Remove non-existent classes from Forward.h 2022-02-18 23:31:28 +00:00
GetPassword.cpp LibCore: Use LibCore syscall wrappers in get_password() 2021-11-30 23:34:40 +01:00
GetPassword.h LibCore: Use ErrorOr<T> for Core::get_password() 2021-11-08 00:35:27 +01:00
Group.cpp LibCore: Add support for compiling for Android with API Version >= 30 2022-07-19 10:44:02 +01:00
Group.h LibCore: Add support for compiling for Android with API Version >= 30 2022-07-19 10:44:02 +01:00
InputBitStream.h LibCore: Add LittleEndianInputBitStream 2022-05-21 22:41:40 +02:00
IODevice.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
IODevice.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
LocalServer.cpp Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
LocalServer.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
LockFile.cpp LibCore+Userland: Remove File::ensure_parent_directories 2022-04-11 00:08:48 +02:00
LockFile.h Everywhere: Use my cool new @serenityos.org email address 2021-09-01 11:37:25 +04:30
MappedFile.cpp LibCore+LibGfx: Pass file-path as StringView 2022-06-14 23:00:52 +02:00
MappedFile.h LibCore+LibGfx: Pass file-path as StringView 2022-06-14 23:00:52 +02:00
MemoryStream.h Everywhere: Split Error::from_string_literal and Error::from_string_view 2022-07-12 23:11:35 +02:00
MimeData.cpp Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
MimeData.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
NetworkJob.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
NetworkJob.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
NetworkResponse.h Libraries: Use default constructors/destructors in LibCore 2022-03-10 18:04:26 -08:00
Notifier.cpp LibCore: Remove unused header includes 2021-08-01 08:10:16 +02:00
Notifier.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Object.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Object.h Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
Process.cpp Userland: Remove erroneous String -> char* -> StringView conversions 2022-07-12 23:11:35 +02:00
Process.h LibCore: Return ErrorOr<pid_t> and support arguments in Process::spawn 2022-05-25 23:14:22 +01:00
ProcessStatisticsReader.cpp Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
ProcessStatisticsReader.h Everywhere: Make tracking cpu usage independent from system ticks 2021-07-18 22:08:26 +02:00
Promise.h Libraries: Fix visibility of Object-derivative constructors 2021-11-02 22:56:53 +01:00
Property.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Property.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Proxy.h pro: Accept an optional proxy to tunnel the download through 2022-04-09 12:21:43 +02:00
SecretString.cpp Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr 2022-01-24 22:36:09 +01:00
SecretString.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
SharedCircularQueue.h Everywhere: Split Error::from_string_literal and Error::from_string_view 2022-07-12 23:11:35 +02:00
SocketAddress.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
SOCKSProxyClient.cpp Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
SOCKSProxyClient.h LibCore+Everywhere: Make Core::Stream::read() return Bytes 2022-04-16 13:27:51 -04:00
StandardPaths.cpp Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
StandardPaths.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Stream.cpp Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
Stream.h LibCore: Avoid some successive allocations in Stream::read_all() 2022-06-27 20:22:15 +01:00
System.cpp LibCore: Add function for searching a file in $PATH 2022-07-21 16:40:11 +02:00
System.h LibCore: Add function for searching a file in $PATH 2022-07-21 16:40:11 +02:00
SystemServerTakeover.cpp Everywhere: Split Error::from_string_literal and Error::from_string_view 2022-07-12 23:11:35 +02:00
SystemServerTakeover.h LibCore+LibIPC: Move SystemServerTakeover.{h,cpp} to LibCore 2022-02-06 10:28:19 +01:00
TCPServer.cpp LibCore+Userland: Remove Core::TCPSocket :^) 2022-02-06 17:28:17 +00:00
TCPServer.h LibCore+Userland+Tests: Convert Stream APIs to construct on heap 2022-01-13 15:16:12 +03:30
TempFile.cpp Userland: Remove a bunch of unnecessary Vector imports 2022-01-28 23:40:25 +01:00
TempFile.h LibCore: Add utility class for temporary files and directories 2022-01-12 14:55:19 +01:00
Timer.cpp Libraries: Use default constructors/destructors in LibCore 2022-03-10 18:04:26 -08:00
Timer.h Libraries: Use default constructors/destructors in LibCore 2022-03-10 18:04:26 -08:00
UDPServer.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
UDPServer.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
UmaskScope.h LibCore: Add Core::UmaskScope to set and unset a temporary umask 2022-01-02 18:08:02 +01:00
Version.cpp LibCore+Everywhere: Return ErrorOr from ConfigFile factory methods 2022-02-16 19:49:41 -05:00
Version.h LibCore: Refactor a version-reading utility 2021-09-02 16:17:18 +01:00