Skip to content

Commit

Permalink
Fix support for windows atomics
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl/openssl#26963)
  • Loading branch information
bernd-edlinger authored and t8m committed Mar 5, 2025
1 parent b48145c commit bcb8eae
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crypto/threads_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bcb8eae

Please sign in to comment.