-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use std::atomic instead of the windows-only primitives for atomic ope…
…rations in the song renderer
- Loading branch information
Showing
4 changed files
with
62 additions
and
4 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
40 changes: 40 additions & 0 deletions
40
WaveSabrePlayerLib/include/WaveSabrePlayerLib/AtomicHelpers.h
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef __WAVESABREPLAYERLIB_ATOMIC_HELPERS_H__ | ||
#define __WAVESABREPLAYERLIB_ATOMIC_HELPERS_H__ | ||
|
||
#ifdef _WIN32 | ||
#include <Windows.h> | ||
#else | ||
#include <atomic> | ||
#endif | ||
|
||
namespace WaveSabreCore | ||
{ | ||
namespace AtomicHelpers | ||
{ | ||
template<typename T> | ||
inline bool CmpXchg(T* value, T newval, T expect) | ||
{ | ||
#ifdef _WIN32 | ||
return InterlockedCompareExchange((unsigned int*)value, | ||
(unsigned int)newval, (unsigned int)expect) | ||
== (unsigned int)expect; | ||
#else | ||
return std::atomic_compare_exchange_strong((std::atomic_int*)value, | ||
(int*)&expect, newval); | ||
#endif | ||
} | ||
|
||
template<typename T> | ||
inline T XDec(T* value) | ||
{ | ||
#ifdef _WIN32 | ||
return (T)InterlockedDecrement((unsigned int*)value); | ||
#else | ||
// returns the value *before* the call | ||
return (T)(std::atomic_fetch_sub((std::atomic_int*)value, 1) - 1); | ||
#endif | ||
} | ||
} | ||
} | ||
|
||
#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