bignum: allow concurrent BN_MONT_CTX_set_locked()
authorGeoff Thorpe <geoff@openssl.org>
Sun, 4 May 2014 20:19:22 +0000 (16:19 -0400)
committerGeoff Thorpe <geoff@openssl.org>
Tue, 6 May 2014 21:43:35 +0000 (17:43 -0400)
commit12e9f627f9dd9a9f75d4a7beb6baf30a3697d8e0
tree5beaf93c185443d452fc9f3f01c5c84197a07b99
parent3ba1e406c2309adb427ced9815ebf05f5b58d155
bignum: allow concurrent BN_MONT_CTX_set_locked()

The lazy-initialisation of BN_MONT_CTX was serialising all threads, as
noted by Daniel Sands and co at Sandia. This was to handle the case that
2 or more threads race to lazy-init the same context, but stunted all
scalability in the case where 2 or more threads are doing unrelated
things! We favour the latter case by punishing the former. The init work
gets done by each thread that finds the context to be uninitialised, and
we then lock the "set" logic after that work is done - the winning
thread's work gets used, the losing threads throw away what they've done.

Signed-off-by: Geoff Thorpe <geoff@openssl.org>
crypto/bn/bn_mont.c