forked from wolfSSL/wolfssl
Add MSVC atomics
This commit is contained in:
@@ -1177,23 +1177,41 @@ int wolfSSL_Atomic_Int_FetchSub(wolfSSL_Atomic_Int* c, int i)
|
||||
}
|
||||
#else
|
||||
/* Default C Implementation */
|
||||
WC_INLINE void wolfSSL_Atomic_Int_Init(wolfSSL_Atomic_Int* c, int i)
|
||||
void wolfSSL_Atomic_Int_Init(wolfSSL_Atomic_Int* c, int i)
|
||||
{
|
||||
atomic_init(c, i);
|
||||
}
|
||||
|
||||
WC_INLINE int wolfSSL_Atomic_Int_FetchAdd(wolfSSL_Atomic_Int* c, int i)
|
||||
int wolfSSL_Atomic_Int_FetchAdd(wolfSSL_Atomic_Int* c, int i)
|
||||
{
|
||||
return atomic_fetch_add_explicit(c, i, memory_order_relaxed);
|
||||
}
|
||||
|
||||
WC_INLINE int wolfSSL_Atomic_Int_FetchSub(wolfSSL_Atomic_Int* c, int i)
|
||||
int wolfSSL_Atomic_Int_FetchSub(wolfSSL_Atomic_Int* c, int i)
|
||||
{
|
||||
return atomic_fetch_sub_explicit(c, i, memory_order_relaxed);
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HAVE_C___ATOMIC */
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
/* Default C Implementation */
|
||||
void wolfSSL_Atomic_Int_Init(wolfSSL_Atomic_Int* c, int i)
|
||||
{
|
||||
*c = i;
|
||||
}
|
||||
|
||||
int wolfSSL_Atomic_Int_FetchAdd(wolfSSL_Atomic_Int* c, int i)
|
||||
{
|
||||
return (int)_InterlockedExchangeAdd(c, (long)i);
|
||||
}
|
||||
|
||||
int wolfSSL_Atomic_Int_FetchSub(wolfSSL_Atomic_Int* c, int i)
|
||||
{
|
||||
return (int)_InterlockedExchangeAdd(c, (long)-i);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* WOLFSSL_ATOMIC_OPS */
|
||||
|
||||
|
@@ -298,6 +298,7 @@
|
||||
typedef wolfSSL_Mutex wolfSSL_RwLock;
|
||||
#endif
|
||||
|
||||
#ifndef WOLFSSL_NO_ATOMICS
|
||||
#ifdef HAVE_C___ATOMIC
|
||||
#ifdef __cplusplus
|
||||
#if defined(__GNUC__) && defined(__ATOMIC_RELAXED)
|
||||
@@ -311,7 +312,13 @@
|
||||
typedef atomic_int wolfSSL_Atomic_Int;
|
||||
#define WOLFSSL_ATOMIC_OPS
|
||||
#endif
|
||||
#elif defined(_MSC_VER)
|
||||
/* Use MSVC compiler intrinsics for atomic ops */
|
||||
#include <intrin.h>
|
||||
typedef volatile long wolfSSL_Atomic_Int;
|
||||
#define WOLFSSL_ATOMIC_OPS
|
||||
#endif
|
||||
#endif /* WOLFSSL_NO_ATOMICS */
|
||||
|
||||
#ifdef WOLFSSL_ATOMIC_OPS
|
||||
WOLFSSL_LOCAL void wolfSSL_Atomic_Int_Init(wolfSSL_Atomic_Int* c, int i);
|
||||
|
Reference in New Issue
Block a user