diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2014-11-06 10:25:23 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2014-11-06 10:25:23 -0500 |
| commit | 7bb639911b04addddfda86ca7f61398f779b0d7f (patch) | |
| tree | 82fde5fed02355a0b39a9f0e31c538b75f7a3059 /src/global.c | |
| parent | f890a84fe00091ac4b9430c131e25d5bf6d3eafe (diff) | |
| parent | 15bea02c04ebf3172d495f14219b30eba262eb6a (diff) | |
| download | libgit2-7bb639911b04addddfda86ca7f61398f779b0d7f.tar.gz | |
Merge pull request #2676 from libgit2/cmn/threading
Threading and crypto libraries
Diffstat (limited to 'src/global.c')
| -rw-r--r-- | src/global.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/global.c b/src/global.c index 55b31196e..3c91860cd 100644 --- a/src/global.c +++ b/src/global.c @@ -64,8 +64,9 @@ void openssl_locking_function(int mode, int n, const char *file, int line) } } -static void shutdown_ssl(void) +static void shutdown_ssl_locking(void) { + CRYPTO_set_locking_callback(NULL); git__free(openssl_locks); } #endif @@ -96,30 +97,35 @@ static void init_ssl(void) SSL_CTX_free(git__ssl_ctx); git__ssl_ctx = NULL; } +#endif +} +int git_openssl_set_locking(void) +{ +#ifdef GIT_SSL # ifdef GIT_THREADS - { - int num_locks, i; - - num_locks = CRYPTO_num_locks(); - openssl_locks = git__calloc(num_locks, sizeof(git_mutex)); - if (openssl_locks == NULL) { - SSL_CTX_free(git__ssl_ctx); - git__ssl_ctx = NULL; - } + int num_locks, i; - for (i = 0; i < num_locks; i++) { - if (git_mutex_init(&openssl_locks[i]) != 0) { - SSL_CTX_free(git__ssl_ctx); - git__ssl_ctx = NULL; - } - } + num_locks = CRYPTO_num_locks(); + openssl_locks = git__calloc(num_locks, sizeof(git_mutex)); + GITERR_CHECK_ALLOC(openssl_locks); - CRYPTO_set_locking_callback(openssl_locking_function); + for (i = 0; i < num_locks; i++) { + if (git_mutex_init(&openssl_locks[i]) != 0) { + giterr_set(GITERR_SSL, "failed to initialize openssl locks"); + return -1; + } } - git__on_shutdown(shutdown_ssl); + CRYPTO_set_locking_callback(openssl_locking_function); + git__on_shutdown(shutdown_ssl_locking); + return 0; +# else + giterr_set(GITERR_THREAD, "libgit2 as not built with threads"); + return -1; # endif + giterr_set(GITERR_SSL, "libgit2 was not built with OpenSSL support"); + return -1; #endif } |
