diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-07-29 10:39:47 +0000 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-08-02 09:43:32 +0000 |
commit | 28ba2d46001b79fb860b3fda821adb8a6b3f34c4 (patch) | |
tree | fadb460d22e69479d2f96561e3e9887f173668aa /atomic.h | |
parent | Rewrite installer logic in C (diff) | |
download | wintun-28ba2d46001b79fb860b3fda821adb8a6b3f34c4.tar.xz wintun-28ba2d46001b79fb860b3fda821adb8a6b3f34c4.zip |
Separate out atomic helpers
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'atomic.h')
-rw-r--r-- | atomic.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/atomic.h b/atomic.h new file mode 100644 index 0000000..01dd35e --- /dev/null +++ b/atomic.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (C) 2018-2019 WireGuard LLC. All Rights Reserved. + */ + +#pragma once + +#include <wdm.h> + +static __forceinline VOID +InterlockedSet(_Inout_ _Interlocked_operand_ LONG volatile *Target, _In_ LONG Value) +{ + *Target = Value; +} + +static __forceinline VOID +InterlockedSetU(_Inout_ _Interlocked_operand_ ULONG volatile *Target, _In_ ULONG Value) +{ + *Target = Value; +} + +static __forceinline VOID +InterlockedSetPointer(_Inout_ _Interlocked_operand_ VOID *volatile *Target, _In_opt_ VOID *Value) +{ + *Target = Value; +} + +static __forceinline LONG +InterlockedGet(_In_ _Interlocked_operand_ LONG volatile *Value) +{ + return *Value; +} + +static __forceinline ULONG +InterlockedGetU(_In_ _Interlocked_operand_ ULONG volatile *Value) +{ + return *Value; +} + +static __forceinline PVOID +InterlockedGetPointer(_In_ _Interlocked_operand_ PVOID volatile *Value) +{ + return *Value; +} + +static __forceinline LONG64 +InterlockedGet64(_In_ _Interlocked_operand_ LONG64 volatile *Value) +{ +#ifdef _WIN64 + return *Value; +#else + return InterlockedCompareExchange64(Value, 0, 0); +#endif +}
\ No newline at end of file |