Fix codegen teardown and skip dispatch thread in tool mode

This commit is contained in:
salh
2026-05-30 11:56:35 +03:00
parent ead11217b7
commit 0d7a528395
4 changed files with 44 additions and 12 deletions
+1 -1
View File
@@ -245,7 +245,7 @@ class KernelState {
object_ref<XThread> LaunchModule(object_ref<UserModule> module);
object_ref<UserModule> GetExecutableModule();
void SetExecutableModule(object_ref<UserModule> module);
void SetExecutableModule(object_ref<UserModule> module, bool start_dispatch_thread = true);
object_ref<UserModule> LoadUserModule(const std::string_view name, bool call_entry = true);
void UnloadUserModule(const object_ref<UserModule>& module, bool call_entry = true);
+39 -8
View File
@@ -396,15 +396,46 @@ bool CodegenWriter::write(bool force) {
// Generate sources.cmake
REXCODEGEN_TRACE("Recompile: generating sources.cmake");
{
auto& recompFiles = tmplData["recomp_files"];
recompFiles = nlohmann::json::array();
for (size_t i = 0; i < cppFileIndex; ++i) {
recompFiles.push_back(fmt::format("{}_recomp.{}.cpp", projectName, i));
}
out = renderWithJson(registry, "codegen/sources_cmake", tmplData);
SaveCurrentOutData("sources.cmake");
out.clear();
println("# Auto-generated by rexglue codegen - DO NOT EDIT");
println("#");
println("# IMPORTANT: For SEH (Structured Exception Handling) support on Windows,");
println("# add /EHa to your compile options:");
println("# target_compile_options(your_target PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/EHa>)");
println("#");
println("set(GENERATED_SOURCES");
println(" ${{CMAKE_CURRENT_LIST_DIR}}/{}_config.cpp", projectName);
println(" ${{CMAKE_CURRENT_LIST_DIR}}/{}_init.cpp", projectName);
for (size_t i = 0; i < cppFileIndex; ++i) {
println(" ${{CMAKE_CURRENT_LIST_DIR}}/{}_recomp.{}.cpp", projectName, i);
}
println(")");
if (!ctx_.gameIcon().empty()) {
println("");
println("# Windows application icon resource extracted from the Xbox 360 executable.");
println("# To use your own icon, set REXGLUE_ICON_PATH before this file is included:");
println("# set(REXGLUE_ICON_PATH \"${{CMAKE_CURRENT_SOURCE_DIR}}/my_icon.ico\")");
println("#");
println("# To disable the icon entirely:");
println("# set(REXGLUE_ICON_PATH \"\")");
println("if(WIN32)");
println(" if(NOT DEFINED REXGLUE_ICON_PATH)");
println(" set(REXGLUE_ICON_PATH \"${{CMAKE_CURRENT_LIST_DIR}}/{}_icon.ico\")",
projectName);
println(" endif()");
println(" if(REXGLUE_ICON_PATH)");
println(" set(_rexglue_rc \"${{CMAKE_CURRENT_BINARY_DIR}}/{}_resources.rc\")",
projectName);
println(" file(WRITE \"${{_rexglue_rc}}\"");
println(" \"// Auto-generated - icon from: ${{REXGLUE_ICON_PATH}}\\n\"");
println(" \"#pragma code_page(65001)\\n\"");
println(" \"IDI_ICON1 ICON \\\"${{REXGLUE_ICON_PATH}}\\\"\\n\"");
println(" )");
println(" list(APPEND GENERATED_SOURCES \"${{_rexglue_rc}}\")");
println(" endif()");
println("endif()");
}
SaveCurrentOutData("sources.cmake");
// Write all buffered files to disk
FlushPendingWrites();
+3 -2
View File
@@ -499,7 +499,8 @@ object_ref<UserModule> KernelState::GetExecutableModule() {
return executable_module_;
}
void KernelState::SetExecutableModule(object_ref<UserModule> module) {
void KernelState::SetExecutableModule(object_ref<UserModule> module,
const bool start_dispatch_thread) {
if (module.get() == executable_module_.get()) {
return;
}
@@ -563,7 +564,7 @@ void KernelState::SetExecutableModule(object_ref<UserModule> module) {
// Spin up deferred dispatch worker.
// TODO(benvanik): move someplace more appropriate (out of ctor, but around
// here).
if (!dispatch_thread_running_) {
if (start_dispatch_thread && !dispatch_thread_running_) {
dispatch_thread_running_ = true;
dispatch_thread_ = object_ref<XHostThread>(new XHostThread(this, 128 * 1024, 0, [this]() {
auto global_lock = global_critical_region_.AcquireDeferred();
+1 -1
View File
@@ -296,7 +296,7 @@ X_STATUS Runtime::LoadXexImage(const std::string_view module_path) {
return status;
}
kernel_state_->SetExecutableModule(module);
kernel_state_->SetExecutableModule(module, !tool_mode_);
REXSYS_DEBUG(" XEX image loaded successfully");
return X_STATUS_SUCCESS;
}