diff --git a/README.markdown b/README.markdown index 8b12369a..f6426303 100644 --- a/README.markdown +++ b/README.markdown @@ -77,6 +77,9 @@ Before doing anything else with the library, call: sodium_init(); +This function is not thread-safe. No other Sodium functions should be +called until it successfully returns. + And if you need to release memory and other resources possibly allocated by the library, call: diff --git a/src/libsodium/sodium/core.c b/src/libsodium/sodium/core.c index f354f1fa..84fad58e 100644 --- a/src/libsodium/sodium/core.c +++ b/src/libsodium/sodium/core.c @@ -2,14 +2,15 @@ #include "core.h" #include "crypto_onetimeauth.h" -static char initialized; +static _Bool initialized; int sodium_init(void) { - if (__sync_lock_test_and_set(&initialized, 1) != 0) { + if (initialized != 0) { return 1; } + initialized = 1; if (crypto_onetimeauth_pick_best_implementation() == NULL) { return -1; }