Fix support for windows atomics

Make CRYPTO_atomic_add consistent with
CRYPTO_atomic_load_int and set the
reader_idx under write_lock since there
is no CRYPTO_atomic_store_int.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26963)
This commit is contained in:
Bernd Edlinger 2025-02-22 00:01:59 +01:00 committed by Tomas Mraz
parent b48145cd18
commit bcb8eae1af

View File

@ -339,7 +339,13 @@ static struct rcu_qp *update_qp(CRYPTO_RCU_LOCK *lock, uint32_t *curr_id)
/* update the reader index to be the prior qp */
tmp = lock->current_alloc_idx;
# if (defined(NO_INTERLOCKEDOR64))
CRYPTO_THREAD_write_lock(lock->rw_lock);
lock->reader_idx = tmp;
CRYPTO_THREAD_unlock(lock->rw_lock);
# else
InterlockedExchange((LONG volatile *)&lock->reader_idx, tmp);
# endif
/* wake up any waiters */
ossl_crypto_condvar_broadcast(lock->alloc_signal);
@ -606,9 +612,21 @@ int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b)
int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
{
# if (defined(NO_INTERLOCKEDOR64))
if (lock == NULL || !CRYPTO_THREAD_write_lock(lock))
return 0;
*val += amount;
*ret = *val;
if (!CRYPTO_THREAD_unlock(lock))
return 0;
return 1;
# else
*ret = (int)InterlockedExchangeAdd((LONG volatile *)val, (LONG)amount)
+ amount;
return 1;
# endif
}
int CRYPTO_atomic_add64(uint64_t *val, uint64_t op, uint64_t *ret,