-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Merge Windows XP support from PRs #6176 and #6177 into unified implementation #6204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Co-authored-by: Sugar-Baby <[email protected]> Co-authored-by: AtomAlpaca <[email protected]> Co-authored-by: nihui <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6204 +/- ##
==========================================
- Coverage 96.17% 95.93% -0.24%
==========================================
Files 835 832 -3
Lines 260827 264287 +3460
==========================================
+ Hits 250843 253542 +2699
- Misses 9984 10745 +761 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR consolidates Windows XP support from two separate pull requests into a unified implementation, providing comprehensive build toolchain support and runtime compatibility for legacy Windows systems. The implementation uses conditional compilation to automatically select XP-compatible APIs when targeting older Windows versions.
Key changes include:
- Implementation of Windows XP-compatible threading primitives using CRITICAL_SECTION and Event objects instead of modern SRWLock/ConditionVariable APIs
- Addition of three complete build toolchains (MinGW-w64, Clang, MSVC) with appropriate XP targeting configurations
- Comprehensive CI/CD integration with dedicated workflows for each toolchain to ensure compatibility testing
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/platform.h.in |
Adds conditional threading implementation with XP-compatible CRITICAL_SECTION and dual-event ConditionVariable |
src/cpu.cpp |
Updates environment variable setting to use XP-compatible _putenv() instead of _putenv_s() |
tests/test_cpu.cpp |
Modifies minimum Windows version check from Win7 to WinXP for test compatibility |
toolchains/windows-xp-*.toolchain.cmake |
Three new CMake toolchain files for MinGW, Clang, and MSVC with XP-specific configurations |
.github/workflows/windows-xp-*.yml |
Three CI workflows for comprehensive testing across all supported toolchains |
docs/** |
Enhanced documentation with detailed build instructions and Chinese language guide |
mutex.unlock(); | ||
HANDLE events[2] = { signal_event, broadcast_event }; | ||
WaitForMultipleObjects(2, events, FALSE, INFINITE); // Wait for either signal or broadcast | ||
mutex.lock(); | ||
} | ||
void broadcast() | ||
{ | ||
SetEvent(broadcast_event); // Wake all threads | ||
ResetEvent(broadcast_event); // Reset after waking all threads |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation has a race condition. After WaitForMultipleObjects returns, there's no way to distinguish whether it was woken by signal_event or broadcast_event, and the broadcast_event is reset immediately after SetEvent, which could cause threads to miss the broadcast if they haven't reached WaitForMultipleObjects yet.
mutex.unlock(); | |
HANDLE events[2] = { signal_event, broadcast_event }; | |
WaitForMultipleObjects(2, events, FALSE, INFINITE); // Wait for either signal or broadcast | |
mutex.lock(); | |
} | |
void broadcast() | |
{ | |
SetEvent(broadcast_event); // Wake all threads | |
ResetEvent(broadcast_event); // Reset after waking all threads | |
{ | |
// Increment wait count | |
AutoLock lock(internal_mutex); | |
++wait_count; | |
} | |
mutex.unlock(); | |
HANDLE events[2] = { signal_event, broadcast_event }; | |
WaitForMultipleObjects(2, events, FALSE, INFINITE); // Wait for either signal or broadcast | |
mutex.lock(); | |
{ | |
// Decrement wait count | |
AutoLock lock(internal_mutex); | |
--wait_count; | |
if (wait_count == 0) | |
{ | |
ResetEvent(broadcast_event); // Reset broadcast_event only when all threads are woken | |
} | |
} | |
} | |
void broadcast() | |
{ | |
AutoLock lock(internal_mutex); | |
if (wait_count > 0) | |
{ | |
SetEvent(broadcast_event); // Wake all threads | |
} |
Copilot uses AI. Check for mistakes.
void broadcast() | ||
{ | ||
SetEvent(broadcast_event); // Wake all threads | ||
ResetEvent(broadcast_event); // Reset after waking all threads |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resetting the broadcast_event immediately after SetEvent creates a race condition where threads that haven't yet reached WaitForMultipleObjects may miss the broadcast signal. The reset should happen only after ensuring all waiting threads have been woken up.
Copilot uses AI. Check for mistakes.
The binary size change of libncnn.so (bytes)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR consolidates the Windows XP support contributions from PR #6176 (by @Sugar-Baby) and PR #6177 (by @AtomAlpaca) into a single, comprehensive implementation that combines the best aspects of both approaches.
Changes Made
Core Windows XP Compatibility
src/platform.h.in
to conditionally use CRITICAL_SECTION and Event-based synchronization for Windows XP instead of SRWLock/ConditionVariablesrc/cpu.cpp
to use XP-compatible_putenv()
instead of_putenv_s()
when targeting Windows XPtests/test_cpu.cpp
to support Windows XP minimum requirementsBuild Infrastructure
Added comprehensive build support with three separate toolchains:
toolchains/windows-xp-mingw.toolchain.cmake
- 32-bit MinGW targeting i686toolchains/windows-xp-clang.toolchain.cmake
- Clang with MinGW librariestoolchains/windows-xp-msvc.toolchain.cmake
- Visual Studio v141_xp toolsetCI/CD Integration
Created three separate GitHub Actions workflows for comprehensive testing:
.github/workflows/windows-xp-mingw.yml
.github/workflows/windows-xp-clang.yml
.github/workflows/windows-xp-msvc.yml
Documentation
docs/how-to-build/how-to-build.md
with detailed Windows XP build instructions for all three toolchainsdocs/developer-guide/build-ncnn-on-windows-xp.zh.md
with comprehensive setup guideTechnical Implementation Details
The Windows XP compatibility layer uses conditional compilation based on
_WIN32_WINNT > _WIN32_WINNT_WINXP
:Key features:
Build Example
Credits
This implementation preserves and combines contributions from both original PRs:
Fixes #6203.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.