-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,54 @@ | ||
#if defined(BINJNES_GCC) || defined(BINJNES_CLANG) | ||
#if defined(BINJNES_ATOMIC_C11) | ||
|
||
#include <stdatomic.h> | ||
|
||
typedef atomic_size_t AtomicSize; | ||
typedef atomic_bool AtomicBool; | ||
|
||
static inline size_t atomic_load_size(AtomicSize* addr) { | ||
return atomic_load(addr); | ||
return atomic_load(addr); | ||
} | ||
|
||
static inline void atomic_store_size(AtomicSize* addr, size_t value) { | ||
atomic_store(addr, value); | ||
atomic_store(addr, value); | ||
} | ||
|
||
static inline bool atomic_load_bool(AtomicBool* addr) { | ||
return atomic_load(addr); | ||
} | ||
|
||
#elif defined(BINJNES_MSVC) | ||
static inline void atomic_store_bool(AtomicBool* addr, bool value) { | ||
atomic_store(addr, value); | ||
} | ||
|
||
#elif defined(BINJNES_ATOMIC_MSVC) | ||
|
||
#define WIN32_LEAN_AND_MEAN | ||
#define NOMINMAX | ||
#include <windows.h> | ||
#undef ERROR | ||
|
||
typedef volatile PVOID AtomicSize; | ||
typedef AtomicSize AtomicBool; | ||
|
||
size_t atomic_load_size(AtomicSize* addr) { | ||
return (size_t)*addr; | ||
static inline size_t atomic_load_size(AtomicSize* addr) { | ||
return (size_t)*addr; | ||
} | ||
|
||
void atomic_store_size(AtomicSize* addr, size_t value) { | ||
_InterlockedExchangePointer(addr, (PVOID)value); | ||
static inline void atomic_store_size(AtomicSize* addr, size_t value) { | ||
_InterlockedExchangePointer(addr, (PVOID)value); | ||
} | ||
|
||
#endif | ||
static inline bool atomic_load_bool(AtomicBool* addr) { | ||
return (bool)atomic_load_size(addr); | ||
} | ||
|
||
static inline void atomic_store_bool(AtomicBool* addr, bool value) { | ||
atomic_store_size(addr, (size_t)value); | ||
} | ||
|
||
#else | ||
|
||
#error "No atomics" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters