Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 263b1d6

Browse files
committed
Make the OpenSSL locking function warnings more severe
Our git_openssl_set_locking() would ideally not exist. Make it clearer that we provide it as a last resort and you should prefer anything else.
1 parent 4eb97ef commit 263b1d6

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

THREADING.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,26 @@ it should use. This means that libgit2 cannot know what to set as the
5454
user of libgit2 may use OpenSSL independently and the locking settings
5555
must survive libgit2 shutting down.
5656

57-
libgit2 does provide a convenience function
58-
`git_openssl_set_locking()` to use the platform-native mutex
59-
mechanisms to perform the locking, which you may rely on if you do not
60-
want to use OpenSSL outside of libgit2, or you know that libgit2 will
61-
outlive the rest of the operations. It is not safe to use OpenSSL
62-
multi-threaded after libgit2's shutdown function has been called.
57+
libgit2 does provide a last-resort convenience function
58+
`git_openssl_set_locking()` (available in `sys/openssl.h`) to use the
59+
platform-native mutex mechanisms to perform the locking, which you may
60+
rely on if you do not want to use OpenSSL outside of libgit2, or you
61+
know that libgit2 will outlive the rest of the operations. It is not
62+
safe to use OpenSSL multi-threaded after libgit2's shutdown function
63+
has been called.
64+
65+
If your programming language offers a package/bindings for OpenSSL,
66+
you should very strongly prefer to use that in order to set up
67+
locking, as they provide a level of coördination which is impossible
68+
when using this function.
6369

6470
See the
6571
[OpenSSL documentation](https://www.openssl.org/docs/crypto/threads.html)
6672
on threading for more details.
6773

74+
Be also aware that libgit2 may not always link against OpenSSL in the
75+
future if there are alternatives provided by the system.
76+
6877
libssh2 may be linked against OpenSSL or libgcrypt. If it uses
6978
OpenSSL, you only need to set up threading for OpenSSL once and the
7079
above paragraphs are enough. If it uses libgcrypt, then you need to

include/git2.h

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#include "git2/status.h"
5858
#include "git2/submodule.h"
5959
#include "git2/tag.h"
60-
#include "git2/threads.h"
6160
#include "git2/transport.h"
6261
#include "git2/tree.h"
6362
#include "git2/types.h"

include/git2/threads.h renamed to include/git2/sys/openssl.h

+9-11
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,35 @@
44
* This file is part of libgit2, distributed under the GNU GPL v2 with
55
* a Linking Exception. For full terms see the included COPYING file.
66
*/
7-
#ifndef INCLUDE_git_threads_h__
8-
#define INCLUDE_git_threads_h__
7+
#ifndef INCLUDE_git_openssl_h__
8+
#define INCLUDE_git_openssl_h__
99

1010
#include "common.h"
1111

12-
/**
13-
* @file git2/threads.h
14-
* @brief Library level thread functions
15-
* @defgroup git_thread Threading functions
16-
* @ingroup Git
17-
* @{
18-
*/
1912
GIT_BEGIN_DECL
2013

2114
/**
2215
* Initialize the OpenSSL locks
2316
*
2417
* OpenSSL requires the application to determine how it performs
25-
* locking. This is a convenience function which libgit2 provides for
18+
* locking.
19+
*
20+
* This is a last-resort convenience function which libgit2 provides for
2621
* allocating and initializing the locks as well as setting the
2722
* locking function to use the system's native locking functions.
2823
*
2924
* The locking function will be cleared and the memory will be freed
3025
* when you call git_threads_sutdown().
3126
*
27+
* If your programming language has an OpenSSL package/bindings, it
28+
* likely sets up locking. You should very strongly prefer that over
29+
* this function.
30+
*
3231
* @return 0 on success, -1 if there are errors or if libgit2 was not
3332
* built with OpenSSL and threading support.
3433
*/
3534
GIT_EXTERN(int) git_openssl_set_locking(void);
3635

37-
/** @} */
3836
GIT_END_DECL
3937
#endif
4038

src/global.c

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "global.h"
99
#include "hash.h"
1010
#include "sysdir.h"
11-
#include "git2/threads.h"
1211
#include "git2/global.h"
1312
#include "thread-utils.h"
1413

0 commit comments

Comments
 (0)