diff options
author | Brent Cook <busterb@gmail.com> | 2019-01-01 13:50:17 -0600 |
---|---|---|
committer | Brent Cook <busterb@gmail.com> | 2019-01-01 15:44:37 -0600 |
commit | 565258a4479287bcf482bf18832559542de40efa (patch) | |
tree | ca085c5f06c93fa1bda54dfe1504dcfebd96978f | |
parent | e50817195679a6156ca331c15ecef355b43e81dc (diff) | |
download | portable-565258a4479287bcf482bf18832559542de40efa.tar.gz portable-565258a4479287bcf482bf18832559542de40efa.tar.bz2 portable-565258a4479287bcf482bf18832559542de40efa.zip |
use InterlockedExchangeAdd for add
-rw-r--r-- | crypto/compat/crypto_lock_win.c | 14 |
1 files changed, 6 insertions, 8 deletions
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) | |||
30 | if (locks[type] == NULL) { | 30 | if (locks[type] == NULL) { |
31 | LPCRITICAL_SECTION lcs = malloc(sizeof(CRITICAL_SECTION)); | 31 | LPCRITICAL_SECTION lcs = malloc(sizeof(CRITICAL_SECTION)); |
32 | InitializeCriticalSection(lcs); | 32 | InitializeCriticalSection(lcs); |
33 | if (InterlockedCompareExchangePointer((void **)&locks[type], (void *)lcs, NULL) != NULL) | 33 | if (InterlockedCompareExchangePointer((void **)&locks[type], (void *)lcs, NULL) != NULL) { |
34 | { | ||
35 | DeleteCriticalSection(lcs); | 34 | DeleteCriticalSection(lcs); |
36 | free(lcs); | 35 | free(lcs); |
37 | } | 36 | } |
@@ -47,10 +46,9 @@ int | |||
47 | CRYPTO_add_lock(int *pointer, int amount, int type, const char *file, | 46 | CRYPTO_add_lock(int *pointer, int amount, int type, const char *file, |
48 | int line) | 47 | int line) |
49 | { | 48 | { |
50 | int ret = 0; | 49 | /* |
51 | CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE, type, file, line); | 50 | * Windows is LLP64. sizeof(LONG) == sizeof(int) on 32-bit and 64-bit. |
52 | ret = *pointer + amount; | 51 | */ |
53 | *pointer = ret; | 52 | int ret = InterlockedExchangeAdd((LONG *)pointer, (LONG)amount); |
54 | CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE, type, file, line); | 53 | return ret + amount; |
55 | return (ret); | ||
56 | } | 54 | } |