1- Threads in libgit2
1+ Threading in libgit2
22==================
33
4- You may safely use any libgit2 object from any thread, though there
5- may be issues depending on the cryptographic libraries libgit2 or its
4+ Unless otherwise specified, libgit2 objects cannot be safely accessed by
5+ multiple threads simultaneously.
6+
7+ There are also caveats on the cryptographic libraries libgit2 or its
68dependencies link to (more on this later). For libgit2 itself,
79provided you take the following into consideration you won't run into
810issues:
@@ -26,11 +28,11 @@ The error message is thread-local. The `git_error_last()` call must
2628happen on the same thread as the error in order to get the
2729message. Often this will be the case regardless, but if you use
2830something like the [ GCD] ( http://en.wikipedia.org/wiki/Grand_Central_Dispatch )
29- on Mac OS X (where code is executed on an arbitrary thread), the code
31+ on macOS (where code is executed on an arbitrary thread), the code
3032must make sure to retrieve the error code on the thread where the error
3133happened.
3234
33- Threads and cryptographic libraries
35+ Threading and cryptographic libraries
3436=======================================
3537
3638On Windows
@@ -44,52 +46,42 @@ steps necessary. If you are using a MinGW or similar environment where
4446libssh2 uses OpenSSL or libgcrypt, then the general case affects
4547you.
4648
47- On Mac OS X
49+ On macOS
4850-----------
4951
50- By default we use libcurl to perform the encryption. The
51- system-provided libcurl uses SecureTransport, so no special steps are
52- necessary. If you link against another libcurl (e.g. from homebrew)
53- refer to the general case.
54-
55- If the option to use libcurl was deactivated, the library makes use of
56- CommonCrypto and SecureTransport for cryptographic support. These are
57- thread-safe and you do not need to do anything special.
52+ By default we make use of CommonCrypto and SecureTransport for cryptographic
53+ support. These are thread-safe and you do not need to do anything special.
5854
5955Note that libssh2 may still use OpenSSL itself. In that case, the
6056general case still affects you if you use ssh.
6157
6258General Case
6359------------
6460
65- If it's available, by default we use libcurl to provide HTTP tunneling support,
66- which may be linked against a number of cryptographic libraries and has its
67- own
68- [ recommendations for thread safety] ( https://curl.haxx.se/libcurl/c/threadsafe.html ) .
69-
70- If there are no alternative TLS implementations (currently only
71- SecureTransport), libgit2 uses OpenSSL in order to use HTTPS as a transport.
72- OpenSSL is thread-safe starting at version 1.1.0. If your copy of libgit2 is
73- linked against that version, you do not need to take any further steps.
61+ libgit2 will default to OpenSSL for HTTPS transport (except on Windows and
62+ macOS, as mentioned above). On any system, mbedTLS _ may_ be optionally
63+ enabled as the security provider. OpenSSL is thread-safe starting at
64+ version 1.1.0. If your copy of libgit2 is linked against that version,
65+ you do not need to take any further steps.
7466
7567Older versions of OpenSSL are made to be thread-implementation agnostic, and the
7668users of the library must set which locking function it should use. libgit2
7769cannot know what to set as the user of libgit2 may also be using OpenSSL independently and
7870the locking settings must then live outside the lifetime of libgit2.
7971
8072Even if libgit2 doesn't use OpenSSL directly, OpenSSL can still be used by
81- libssh2 or libcurl depending on the configuration. If OpenSSL is used by
73+ libssh2 depending on the configuration. If OpenSSL is used by
8274more than one library, you only need to set up threading for OpenSSL once.
8375
84- If libgit2 is linked against OpenSSL, it provides a last-resort convenience function
76+ If libgit2 is linked against OpenSSL < 1.1.0 , it provides a last-resort convenience function
8577` git_openssl_set_locking() ` (available in ` sys/openssl.h ` ) to use the
8678platform-native mutex mechanisms to perform the locking, which you can use
8779if you do not want to use OpenSSL outside of libgit2, or you
8880know that libgit2 will outlive the rest of the operations. It is then not
8981safe to use OpenSSL multi-threaded after libgit2's shutdown function
9082has been called. Note ` git_openssl_set_locking() ` only works if
9183libgit2 uses OpenSSL directly - if OpenSSL is only used as a dependency
92- of libssh2 or libcurl as described above, ` git_openssl_set_locking() ` is a no-op.
84+ of libssh2 as described above, ` git_openssl_set_locking() ` is a no-op.
9385
9486If your programming language offers a package/bindings for OpenSSL,
9587you should very strongly prefer to use that in order to set up
0 commit comments