diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-08-12 21:57:15 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-08-12 21:57:15 +0800 |
commit | ad144ad2e4220dcbf678c515e4670c094413ea6d (patch) | |
tree | 830a273bfd288f828167c5445ba15bcd1050c98e /src | |
parent | aa867dd6770e7956ff08bff55639a4f4d1d74910 (diff) | |
download | dexon-bls-ad144ad2e4220dcbf678c515e4670c094413ea6d.tar dexon-bls-ad144ad2e4220dcbf678c515e4670c094413ea6d.tar.gz dexon-bls-ad144ad2e4220dcbf678c515e4670c094413ea6d.tar.bz2 dexon-bls-ad144ad2e4220dcbf678c515e4670c094413ea6d.tar.lz dexon-bls-ad144ad2e4220dcbf678c515e4670c094413ea6d.tar.xz dexon-bls-ad144ad2e4220dcbf678c515e4670c094413ea6d.tar.zst dexon-bls-ad144ad2e4220dcbf678c515e4670c094413ea6d.zip |
add blsInitThreadSafe
Diffstat (limited to 'src')
-rw-r--r-- | src/bls_c.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/bls_c.cpp b/src/bls_c.cpp index ccdc909..563ecc9 100644 --- a/src/bls_c.cpp +++ b/src/bls_c.cpp @@ -36,6 +36,23 @@ int blsInit(int curve, int maxUnitSize) return -1; } +#if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11 +#include <mutex> +static std::mutex g_mutex; +static int g_curve = -1; + +int blsInitThreadSafe(int curve, int maxUnitSize) +{ + int ret = 0; + std::lock_guard<std::mutex> lock(g_mutex); + if (g_curve != curve) { + ret = blsInit(curve, maxUnitSize); + g_curve = curve; + } + return ret; +} +#endif + static inline const mclBnG1 *cast(const G1* x) { return (const mclBnG1*)x; } static inline const mclBnG2 *cast(const G2* x) { return (const mclBnG2*)x; } |