From 565258a4479287bcf482bf18832559542de40efa Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Tue, 1 Jan 2019 13:50:17 -0600 Subject: use InterlockedExchangeAdd for add --- crypto/compat/crypto_lock_win.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'crypto') diff --git a/crypto/compat/crypto_lock_win.c b/crypto/compat/crypto_lock_win.c index 43a7f05..e995726 100644 --- a/crypto/compat/crypto_lock_win.c +++ b/crypto/compat/crypto_lock_win.c @@ -30,8 +30,7 @@ CRYPTO_lock(int mode, int type, const char *file, int line) if (locks[type] == NULL) { LPCRITICAL_SECTION lcs = malloc(sizeof(CRITICAL_SECTION)); InitializeCriticalSection(lcs); - if (InterlockedCompareExchangePointer((void **)&locks[type], (void *)lcs, NULL) != NULL) - { + if (InterlockedCompareExchangePointer((void **)&locks[type], (void *)lcs, NULL) != NULL) { DeleteCriticalSection(lcs); free(lcs); } @@ -47,10 +46,9 @@ int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file, int line) { - int ret = 0; - CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE, type, file, line); - ret = *pointer + amount; - *pointer = ret; - CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE, type, file, line); - return (ret); + /* + * Windows is LLP64. sizeof(LONG) == sizeof(int) on 32-bit and 64-bit. + */ + int ret = InterlockedExchangeAdd((LONG *)pointer, (LONG)amount); + return ret + amount; } -- cgit v1.2.3-55-g6feb