Skip to content

Commit 84a4abf

Browse files
committed
wolfssl/wolfcrypt/wc_port.h and wolfcrypt/src/wc_port.c: implement wolfSSL_Atomic_Int_Exchange().
1 parent 0f41e99 commit 84a4abf

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

wolfcrypt/src/wc_port.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,11 @@ unsigned int wolfSSL_Atomic_Uint_SubFetch(wolfSSL_Atomic_Uint* c,
14321432
return val - i;
14331433
}
14341434

1435+
int wolfSSL_Atomic_Int_Exchange(wolfSSL_Atomic_Int* c, int new_i)
1436+
{
1437+
return atomic_swap_int(c, new_i);
1438+
}
1439+
14351440
int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int* c, int *expected_i,
14361441
int new_i)
14371442
{
@@ -1495,6 +1500,11 @@ int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int* c, int i)
14951500
return ret - i;
14961501
}
14971502

1503+
int wolfSSL_Atomic_Int_Exchange(wolfSSL_Atomic_Int* c, int new_i)
1504+
{
1505+
return atomic_exchange_explicit(c, new_i, memory_order_seq_cst);
1506+
}
1507+
14981508
int wolfSSL_Atomic_Int_CompareExchange(
14991509
wolfSSL_Atomic_Int* c, int *expected_i, int new_i)
15001510
{
@@ -1600,6 +1610,11 @@ int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int* c, int i)
16001610
return __atomic_sub_fetch(c, i, __ATOMIC_RELAXED);
16011611
}
16021612

1613+
int wolfSSL_Atomic_Int_Exchange(wolfSSL_Atomic_Int* c, int new_i)
1614+
{
1615+
return __atomic_exchange_n(c, new_i, __ATOMIC_SEQ_CST);
1616+
}
1617+
16031618
int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int* c, int *expected_i,
16041619
int new_i)
16051620
{
@@ -1692,6 +1707,12 @@ int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int* c, int i)
16921707
return ret - i;
16931708
}
16941709

1710+
int wolfSSL_Atomic_Int_Exchange(wolfSSL_Atomic_Int* c, int new_i)
1711+
{
1712+
long actual_i = InterlockedExchange(c, (long)new_i);
1713+
return (int)actual_i;
1714+
}
1715+
16951716
int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int* c, int *expected_i,
16961717
int new_i)
16971718
{

wolfssl/wolfcrypt/wc_port.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,8 @@
613613
WOLFSSL_API int wolfSSL_Atomic_Int_FetchSub(wolfSSL_Atomic_Int* c, int i);
614614
WOLFSSL_API int wolfSSL_Atomic_Int_AddFetch(wolfSSL_Atomic_Int* c, int i);
615615
WOLFSSL_API int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int* c, int i);
616+
WOLFSSL_API int wolfSSL_Atomic_Int_Exchange(
617+
wolfSSL_Atomic_Int* c, int new_i);
616618
WOLFSSL_API int wolfSSL_Atomic_Int_CompareExchange(
617619
wolfSSL_Atomic_Int* c, int *expected_i, int new_i);
618620
WOLFSSL_API unsigned int wolfSSL_Atomic_Uint_FetchAdd(
@@ -652,6 +654,13 @@
652654
static WC_INLINE int wolfSSL_Atomic_Int_SubFetch(int *c, int i) {
653655
return (*c -= i);
654656
}
657+
static WC_INLINE int wolfSSL_Atomic_Int_Exchange(
658+
int *c, int new_i)
659+
{
660+
int ret = *c;
661+
*c = new_i;
662+
return ret;
663+
}
655664
static WC_INLINE int wolfSSL_Atomic_Int_CompareExchange(
656665
int *c, int *expected_i, int new_i)
657666
{

0 commit comments

Comments
 (0)