@@ -1357,6 +1357,13 @@ int wolfSSL_Atomic_Uint_CompareExchange(
13571357 c , expected_i , new_i , 0 /* weak */ , __ATOMIC_SEQ_CST , __ATOMIC_ACQUIRE );
13581358}
13591359
1360+ int wolfSSL_Atomic_Ptr_CompareExchange (
1361+ void * * c , void * * expected_ptr , void * new_ptr )
1362+ {
1363+ return __atomic_compare_exchange_n (
1364+ c , expected_ptr , new_ptr , 0 /* weak */ , __ATOMIC_SEQ_CST , __ATOMIC_ACQUIRE );
1365+ }
1366+
13601367#else
13611368
13621369/* Default C Implementation */
@@ -1444,6 +1451,17 @@ int wolfSSL_Atomic_Uint_CompareExchange(
14441451 c , expected_i , new_i , memory_order_seq_cst , memory_order_acquire );
14451452}
14461453
1454+ int wolfSSL_Atomic_Ptr_CompareExchange (
1455+ void * * c , void * * expected_ptr , void * new_ptr )
1456+ {
1457+ /* use gcc-built-in __atomic_compare_exchange_n(), not
1458+ * atomic_compare_exchange_strong_explicit(), to sidestep _Atomic type
1459+ * requirements.
1460+ */
1461+ return __atomic_compare_exchange_n (
1462+ c , expected_ptr , new_ptr , 0 /* weak */ , __ATOMIC_SEQ_CST , __ATOMIC_ACQUIRE );
1463+ }
1464+
14471465#endif /* __cplusplus */
14481466
14491467#elif defined(_MSC_VER )
@@ -1538,6 +1556,32 @@ int wolfSSL_Atomic_Uint_CompareExchange(
15381556 }
15391557}
15401558
1559+ int wolfSSL_Atomic_Uint_CompareExchange (
1560+ void * * c , void * * expected_ptr , void * new_ptr )
1561+ {
1562+ #ifdef _WIN64
1563+ LONG64 actual_ptr = InterlockedCompareExchange64
1564+ ((LONG64 * )c , (LONG64 )new_i , (LONG64 )* expected_i );
1565+ if (actual_ptr == (LONG64 )* expected_i ) {
1566+ return 1 ;
1567+ }
1568+ else {
1569+ * expected_i = (void * )actual_ptr ;
1570+ return 0 ;
1571+ }
1572+ #else /* !_WIN64 */
1573+ LONG actual_ptr = InterlockedCompareExchange
1574+ ((LONG * )c , (LONG )new_i , (LONG )* expected_i );
1575+ if (actual_ptr == (LONG )* expected_i ) {
1576+ return 1 ;
1577+ }
1578+ else {
1579+ * expected_i = (void * )actual_ptr ;
1580+ return 0 ;
1581+ }
1582+ #endif /* !_WIN64 */
1583+ }
1584+
15411585#endif
15421586
15431587#endif /* WOLFSSL_ATOMIC_OPS */
0 commit comments