use InterlockedExchangeAdd for add
This commit is contained in:
parent
e508171956
commit
565258a447
@ -30,8 +30,7 @@ CRYPTO_lock(int mode, int type, const char *file, int line)
|
|||||||
if (locks[type] == NULL) {
|
if (locks[type] == NULL) {
|
||||||
LPCRITICAL_SECTION lcs = malloc(sizeof(CRITICAL_SECTION));
|
LPCRITICAL_SECTION lcs = malloc(sizeof(CRITICAL_SECTION));
|
||||||
InitializeCriticalSection(lcs);
|
InitializeCriticalSection(lcs);
|
||||||
if (InterlockedCompareExchangePointer((void **)&locks[type], (void *)lcs, NULL) != NULL)
|
if (InterlockedCompareExchangePointer((void **)&locks[type], (void *)lcs, NULL) != NULL) {
|
||||||
{
|
|
||||||
DeleteCriticalSection(lcs);
|
DeleteCriticalSection(lcs);
|
||||||
free(lcs);
|
free(lcs);
|
||||||
}
|
}
|
||||||
@ -47,10 +46,9 @@ int
|
|||||||
CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
|
CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
|
||||||
int line)
|
int line)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
/*
|
||||||
CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE, type, file, line);
|
* Windows is LLP64. sizeof(LONG) == sizeof(int) on 32-bit and 64-bit.
|
||||||
ret = *pointer + amount;
|
*/
|
||||||
*pointer = ret;
|
int ret = InterlockedExchangeAdd((LONG *)pointer, (LONG)amount);
|
||||||
CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE, type, file, line);
|
return ret + amount;
|
||||||
return (ret);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user