@@ -1278,8 +1278,86 @@ char* wc_strdup_ex(const char *src, int memType) {
12781278#elif defined(SINGLE_THREADED )
12791279
12801280#elif defined(WOLFSSL_BSDKM )
1281+ /* Note: using compiler built-ins like __atomic_fetch_add will technically
1282+ * build in FreeBSD kernel, but are not commonly used in FreeBSD kernel and
1283+ * might not be safe or portable.
1284+ * */
1285+ void wolfSSL_Atomic_Int_Init (wolfSSL_Atomic_Int * c , int i )
1286+ {
1287+ * c = i ;
1288+ }
1289+
1290+ void wolfSSL_Atomic_Uint_Init (wolfSSL_Atomic_Uint * c , unsigned int i )
1291+ {
1292+ * c = i ;
1293+ }
1294+
1295+ int wolfSSL_Atomic_Int_FetchAdd (wolfSSL_Atomic_Int * c , int i )
1296+ {
1297+ return atomic_fetchadd_int (c , i );
1298+ }
1299+
1300+ int wolfSSL_Atomic_Int_FetchSub (wolfSSL_Atomic_Int * c , int i )
1301+ {
1302+ return atomic_fetchadd_int (c , - i );
1303+ }
1304+
1305+ int wolfSSL_Atomic_Int_AddFetch (wolfSSL_Atomic_Int * c , int i )
1306+ {
1307+ int val = atomic_fetchadd_int (c , i );
1308+ return val + i ;
1309+ }
1310+
1311+ int wolfSSL_Atomic_Int_SubFetch (wolfSSL_Atomic_Int * c , int i )
1312+ {
1313+ int val = atomic_fetchadd_int (c , - i );
1314+ return val - i ;
1315+ }
1316+
1317+ unsigned int wolfSSL_Atomic_Uint_FetchAdd (wolfSSL_Atomic_Uint * c ,
1318+ unsigned int i )
1319+ {
1320+ return atomic_fetchadd_int (c , i );
1321+ }
1322+
1323+ unsigned int wolfSSL_Atomic_Uint_FetchSub (wolfSSL_Atomic_Uint * c ,
1324+ unsigned int i )
1325+ {
1326+ return atomic_fetchadd_int (c , - i );
1327+ }
1328+
1329+ unsigned int wolfSSL_Atomic_Uint_AddFetch (wolfSSL_Atomic_Uint * c ,
1330+ unsigned int i )
1331+ {
1332+ unsigned int val = atomic_fetchadd_int (c , i );
1333+ return val + i ;
1334+ }
1335+
1336+ unsigned int wolfSSL_Atomic_Uint_SubFetch (wolfSSL_Atomic_Uint * c ,
1337+ unsigned int i )
1338+ {
1339+ unsigned int val = atomic_fetchadd_int (c , - i );
1340+ return val - i ;
1341+ }
1342+
1343+ int wolfSSL_Atomic_Int_CompareExchange (wolfSSL_Atomic_Int * c , int * expected_i ,
1344+ int new_i )
1345+ {
1346+ u_int exp = (u_int ) * expected_i ;
1347+ int ret = atomic_fcmpset_int (c , & exp , new_i );
1348+ * expected_i = (int )exp ;
1349+ return ret ;
1350+ }
1351+
1352+ int wolfSSL_Atomic_Uint_CompareExchange (
1353+ wolfSSL_Atomic_Uint * c , unsigned int * expected_i , unsigned int new_i )
1354+ {
1355+ u_int exp = (u_int ) * expected_i ;
1356+ int ret = atomic_fcmpset_int (c , & exp , new_i );
1357+ * expected_i = (unsigned int )exp ;
1358+ return ret ;
1359+ }
12811360
1282- /* definitions are in bsdkm/bsdkm_wc_port.h */
12831361
12841362#elif defined(HAVE_C___ATOMIC ) && defined(WOLFSSL_HAVE_ATOMIC_H ) && \
12851363 !defined(__cplusplus )
0 commit comments