Fix pthread related build busters in glog code. #866
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.
Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. Additionally, make sure you've done all of these things:
PR Description
What type of PR is this? (Check one of the boxes below)
What does this pull request do?
Fixes port.h to more closely match upstream glog code which also fixes build issues related to pthreads on MSYS2 builds.
The build issues are ultimately caused by different headers in the glog code including different config.h files. Some headers
like libs/glog/src/windows/port.h include the config.h that are in the same directory, but files like libs/glog/src/base/mutex.h
do not have a config.h in the same directory. This causes the compiler to fallback to searching the include paths. When this
happens, the gflags directories are scanned before the glog directories because glog depends on gflags. This results in the
gflags config.h being used sometimes. The gflag config.h defines HAVE_PTHREADS which in turn causes glogs' mutex.h to include pthread.h. The inclusion of pthread.h then causes issues with the thread related function declarations in port.h.
Without this change the build fails because we get "multiple definition" errors for the thread related definitions in port.h. This
change fixes this issue by allowing the code to just use the pthread header if HAVE_PTHREADS is defined and fallback on the alternate definitions if it is not. It also causes the code to be a closer match to upstream glog which could facilitate
unforking glog if that ever becomes desirable in the future.
Have you tested your changes (if applicable)? If so, how?
Yes. The glog code builds fine on a fresh MSYS2 install with this change.