Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Thread namespacing #3830

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

Merged
merged 9 commits into from
Jun 21, 2016
Merged

Thread namespacing #3830

merged 9 commits into from
Jun 21, 2016

Conversation

pks-t
Copy link
Member

@pks-t pks-t commented Jun 20, 2016

This PR aims to fix the namespacing-issue in issue #3825. The Windows-specific pthreads.c source file tries to re-implement the API exposed by pthreads by implementing many of the pthread-symbols with Windows-specific threading code. This unfortunately results in runtime errors when a user links his application to both libgit2 and winpthreads, causing one of both libraries to override symbols of the other library, causing inconsistencies.

Fix the issue by introducing proper namespacing to our threading API. Instead of trying to re-implement all functions, implement functions inside the git_ namespace and adjust the #defines in Unix-specific code.

This solves the part where linking against both libraries causes runtime errors. What is still missing is to allow Windows-users to link libgit2 not against the internal thread API but against winpthread provided by MinGW/MSYS2. This will follow later either by updating this PR or creating a new one if this one got merged already.

@pks-t pks-t force-pushed the pks/thread-namespacing branch from a94fc26 to 5c6c053 Compare June 20, 2016 16:50
} native;
} git_rwlock;

#define PTHREAD_MUTEX_INITIALIZER {(void*)-1}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to suggest we rename this, but I think it's wholly unused so perhaps we should just remove it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, will remove.

@ethomson
Copy link
Member

Thanks for taking care of this. I made a couple of quite trivial comments, but this is great. 😀

pks-t added 9 commits June 20, 2016 19:32
The function pthread_num_processors_np is currently unused and superseded by the
function `git_online_cpus`. Remove the function.
The old pthread-file did re-implement the pthreads API with exact symbol
matching. As the thread-abstraction has now been split up between Unix- and
Windows-specific files within the `git_` namespace to avoid symbol-clashes
between libgit2 and pthreads, the rewritten wrappers have nothing to do with
pthreads anymore.

Rename the Windows-specific pthread-files to honor this change.
@pks-t pks-t force-pushed the pks/thread-namespacing branch from 5c6c053 to aab266c Compare June 20, 2016 18:11
@pks-t
Copy link
Member Author

pks-t commented Jun 20, 2016

New version fixes comments by @ethomson. Thanks for your reviews

@ethomson
Copy link
Member

Thanks again, this is great.

@ethomson ethomson merged commit bb0edf8 into libgit2:master Jun 21, 2016
@pks-t pks-t deleted the pks/thread-namespacing branch June 21, 2016 05:43
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.

2 participants