1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 18:15:18 -07:00

sodium_init() is not thread-safe. Roll your own locks if you need that.

This commit is contained in:
Frank Denis 2013-04-19 14:19:23 +02:00
parent 48d4b5ab1e
commit 05f45575bb
2 changed files with 6 additions and 2 deletions

View File

@ -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:

View File

@ -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;
}