Skip to content

runtime/shims: remove thread_local and function-local static guards in d3d12_xs, file_system and xgameruntime - #7957

Open
DevilNine wants to merge 1 commit into
ItsNotRexed:mainfrom
DevilNine:fix/shims-remove-tls-static-guards
Open

DevilNine wants to merge 1 commit into
ItsNotRexed:mainfrom
DevilNine:fix/shims-remove-tls-static-guards

Conversation

@DevilNine

Copy link
Copy Markdown

Summary

Follow-up in the RT-488 class (companion to #7074, #7175, #7198, #7359, and #7824, with zero file overlap) removing remaining static module TLS (thread_local -> _tls_index) and MSVC thread-safe function-local static initialization guards (_Init_thread_header -> _Init_thread_epoch in module TLS) across four untouched shims.

Claimed in #7804 (comment).

Changes

  • runtime/shims/d3d12_xs.cpp:
    • Replace all 6 function-local dynamic statics (d3d12.dll handle, 1.2 serializer support probe, and 4 host(...) exports) with namespace-scope INIT_ONCE + InitOnceExecuteOnce (passing object-pointer context structs; no function-pointer-to-void* cast).
  • runtime/shims/file_system.cpp:
    • Replace host_copy_file2()'s function-local static with INIT_ONCE and replace copy-up's std::mutex with SRWLOCK_INIT.
  • runtime/shims/xgameruntime.cpp & runtime/shims/xgameruntime_gamesave.cpp:
    • Replace thread_local bool t_time_sensitive and thread_local uint32_t t_read_count with Win32 TlsAlloc slots initialized via INIT_ONCE, preserving Win32 GetLastError() across TlsGetValue/TlsSetValue.
  • runtime/test/xgameruntime_test.cpp:
    • Add per-thread isolation + GetLastError() preservation regression checks for XThreadingImpl slots 27 and 30 (XThreadSetTimeSensitive / XThreadIsTimeSensitive).

Symbol verification (dumpbin /SYMBOLS, MSVC 19.44.35229.0 RelWithDebInfo on main dde82f2)

Object Before (main) After (this PR)
d3d12_xs.cpp.obj _Init_thread_header=1, _tls_index=1 0, 0
xgameruntime.cpp.obj _Init_thread_header=0, _tls_index=1 0, 0
xgameruntime_gamesave.cpp.obj _Init_thread_header=0, _tls_index=1 0, 0
file_system.cpp.obj local `` guard in host_copy_file2 + `startup_trace.h` 0 local `` guards in file_system.cpp (only inline `startup_trace::detail::mutex()` remains until #7824 lands)

Overlap check

Zero files in common with #7074 (library_loader.cpp), #7175 (registry.cpp), #7198 (winhttp_offline.cpp), #7359 (gameinput.cpp, dxgi_com.cpp, xmem.cpp), #7824 / #7723 (startup_trace.h, xgameruntime_offline.cpp), or active d3d12_xs_device.cpp PRs. No game files or game data are included.

Testing

  • Environment: Windows 11, Intel Core i5-12400F, NVIDIA GeForce RTX 3060 12 GB (driver 32.0.16.2124), MSVC 19.44.35229.0, Windows SDK 10.0.26100.0, CMake + Ninja RelWithDebInfo on main (dde82f2).
  • CTest (6/6 passed, 0 failed): device_proxy, device_proxy_trace, root_sig, file_system, xgameruntime, xgameruntime_gamesave.
  • Hygiene: python -I scripts/check_no_game_data.py exited 0 on all 5 changed files.

AI-assisted (Gemini / Antigravity).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant