Win32: Fix object::cache::threadmania test on x64 #2409
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
object::cache::threadmania
test consistently crashes on Win32 x64. This is because the pthread API against which the test is written specifies a thread's return value as being pointer-sized. On Win32, the return value of a thread is 32 bits on all platforms, and so a pointer doesn't fit platforms with larger pointer sizes. When the return value is sized-up back to a pointer and dereferenced, the test case crashes.This change fixes the problem by turning
git_thread
into a structure on Win32 with room for the thread handle, entry procedure pointer, and avoid *
parameter / return value member. To accomodate the programming model, thegit_thread_join
macro has been modified to require the address of agit_thread
instead of passing it by value. This avoids passing a structure by value. The othergit_thread
function macros in use already accepted agit_thread *
and did not require modification.A randomly generated magic number incorporated into
win32\pthread.c
is used to check for clean thread exit. In the case of unclean exit, thevalue
member of thegit_win32_thread
structure still contains the opaque value passed into the thread entry procedure, and should not be returned to the caller ofgit_thread_join
as a proper return value. Furthermore, we should ensure that all threads started by the library terminate gracefully, so the implementation also raises an assert in the case of unclean thread termination.While here I also fixed up a couple of warnings in
global.c
that MinGW complains about, and simplified the initialization logic for the Vista+ reader-writer lock function pointers.