diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 1dd38c02fc..078c435dab 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -1432,6 +1432,11 @@ unsigned int wolfSSL_Atomic_Uint_SubFetch(wolfSSL_Atomic_Uint* c, return val - i; } +int wolfSSL_Atomic_Int_Exchange(wolfSSL_Atomic_Int* c, int new_i) +{ + return atomic_swap_int(c, new_i); +} + int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int* c, int *expected_i, int new_i) { @@ -1495,6 +1500,11 @@ int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int* c, int i) return ret - i; } +int wolfSSL_Atomic_Int_Exchange(wolfSSL_Atomic_Int* c, int new_i) +{ + return atomic_exchange_explicit(c, new_i, memory_order_seq_cst); +} + int wolfSSL_Atomic_Int_CompareExchange( wolfSSL_Atomic_Int* c, int *expected_i, int new_i) { @@ -1600,6 +1610,11 @@ int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int* c, int i) return __atomic_sub_fetch(c, i, __ATOMIC_RELAXED); } +int wolfSSL_Atomic_Int_Exchange(wolfSSL_Atomic_Int* c, int new_i) +{ + return __atomic_exchange_n(c, new_i, __ATOMIC_SEQ_CST); +} + int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int* c, int *expected_i, int new_i) { @@ -1692,6 +1707,12 @@ int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int* c, int i) return ret - i; } +int wolfSSL_Atomic_Int_Exchange(wolfSSL_Atomic_Int* c, int new_i) +{ + long actual_i = InterlockedExchange(c, (long)new_i); + return (int)actual_i; +} + int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int* c, int *expected_i, int new_i) { diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 4f7d373ab9..6c68d15919 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -613,6 +613,8 @@ WOLFSSL_API int wolfSSL_Atomic_Int_FetchSub(wolfSSL_Atomic_Int* c, int i); WOLFSSL_API int wolfSSL_Atomic_Int_AddFetch(wolfSSL_Atomic_Int* c, int i); WOLFSSL_API int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int* c, int i); + WOLFSSL_API int wolfSSL_Atomic_Int_Exchange( + wolfSSL_Atomic_Int* c, int new_i); WOLFSSL_API int wolfSSL_Atomic_Int_CompareExchange( wolfSSL_Atomic_Int* c, int *expected_i, int new_i); WOLFSSL_API unsigned int wolfSSL_Atomic_Uint_FetchAdd( @@ -652,6 +654,13 @@ static WC_INLINE int wolfSSL_Atomic_Int_SubFetch(int *c, int i) { return (*c -= i); } + static WC_INLINE int wolfSSL_Atomic_Int_Exchange( + int *c, int new_i) + { + int ret = *c; + *c = new_i; + return ret; + } static WC_INLINE int wolfSSL_Atomic_Int_CompareExchange( int *c, int *expected_i, int new_i) {