Compare commits

...

2 commits

Author SHA1 Message Date
ce019229bb Use larger audio buffer on web
All checks were successful
Run tests / Run tests (push) Successful in 10m37s
2026-07-04 17:01:04 +03:00
fac3503820 Prevent registering threads twice in logger
Important for web builds where audio thread coincides with main thread
2026-07-04 17:00:39 +03:00
2 changed files with 16 additions and 0 deletions

View file

@ -139,10 +139,15 @@ namespace psemek::log
level max_; level max_;
}; };
thread_local bool this_thread_registered = false;
} }
void register_thread(std::string name) void register_thread(std::string name)
{ {
if (this_thread_registered)
return;
#ifdef _PTHREAD_H #ifdef _PTHREAD_H
#if (defined _GNU_SOURCE) #if (defined _GNU_SOURCE)
#if __APPLE__ #if __APPLE__
@ -167,6 +172,8 @@ namespace psemek::log
thread_names[id] = std::make_unique<std::string>(name); thread_names[id] = std::make_unique<std::string>(name);
} }
this_thread_registered = true;
{ {
std::size_t current_max = max_thread_name_length.load(); std::size_t current_max = max_thread_name_length.load();
while(current_max < name.size() && !max_thread_name_length.compare_exchange_weak(current_max, name.size())) while(current_max < name.size() && !max_thread_name_length.compare_exchange_weak(current_max, name.size()))
@ -178,6 +185,9 @@ namespace psemek::log
void unregister_thread(std::thread::id id) void unregister_thread(std::thread::id id)
{ {
if (!this_thread_registered)
return;
std::string name; std::string name;
{ {
std::lock_guard lock{thread_names_mutex}; std::lock_guard lock{thread_names_mutex};
@ -194,6 +204,8 @@ namespace psemek::log
thread_names.erase(it); thread_names.erase(it);
} }
this_thread_registered = false;
if (id == std::this_thread::get_id()) if (id == std::this_thread::get_id())
put_message(level::info, "Thread \"" + name + "\" unregistered", name); put_message(level::info, "Thread \"" + name + "\" unregistered", name);
else else

View file

@ -47,7 +47,11 @@ namespace psemek::sdl2
desired.freq = audio::frequency; desired.freq = audio::frequency;
desired.channels = 2; desired.channels = 2;
desired.format = AUDIO_F32SYS; desired.format = AUDIO_F32SYS;
#ifndef __EMSCRIPTEN__
desired.samples = 256; desired.samples = 256;
#else
desired.samples = 2048;
#endif
desired.callback = &callback<float>; desired.callback = &callback<float>;
desired.userdata = this; desired.userdata = this;
if (device_ = SDL_OpenAudioDevice(nullptr, 0, &desired, &obtained, 0); device_ == 0) if (device_ = SDL_OpenAudioDevice(nullptr, 0, &desired, &obtained, 0); device_ == 0)