set main thread in main()

This commit is contained in:
Subhraman Sarkar 2024-09-14 08:31:54 +05:30 committed by Sergey Popov
parent 6d35d37c3e
commit f87a136929
6 changed files with 19 additions and 3 deletions

View file

@ -7,7 +7,8 @@ plugins {
task buildCppDepends {
doLast {
exec {
commandLine './build-android-dependencies/build-android-deps.sh'
workingDir './build-android-dependencies'
commandLine './build-android-deps.sh'
}
}
}

Binary file not shown.

View file

@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View file

@ -465,8 +465,12 @@ static void raise_window_event(const SDL_Event& event)
}
}
// TODO: I'm uncertain if this is always safe to call at static init; maybe set in main() instead?
static const std::thread::id main_thread = std::this_thread::get_id();
static std::thread::id main_thread;
void set_main_thread()
{
main_thread = std::this_thread::get_id();
}
// this should probably be elsewhere, but as the main thread is already
// being tracked here, this went here.

View file

@ -120,6 +120,8 @@ void focus_handler(const sdl_handler* ptr);
bool has_focus(const sdl_handler* ptr, const SDL_Event* event);
void set_main_thread();
// whether the currently executing thread is the main thread.
bool is_in_main_thread();

View file

@ -19,6 +19,7 @@
#include "commandline_options.hpp" // for commandline_options, etc
#include "config.hpp" // for config, config::error, etc
#include "cursor.hpp" // for set, CURSOR_TYPE::NORMAL, etc
#include "events.hpp"
#include "filesystem.hpp" // for filesystem::file_exists, filesystem::io_exception, etc
#include "floating_label.hpp"
#include "font/error.hpp" // for error
@ -1042,6 +1043,7 @@ int wesnoth_main(int argc, char** argv)
int main(int argc, char** argv)
#endif
{
events::set_main_thread();
#ifdef __ANDROID__
__android_log_write(ANDROID_LOG_INFO, "wesnoth", "Wesnoth started");