mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 18:42:28 +00:00
feat(atomic): add SInterlockedIncrement and SInterlockedDecrement
This commit is contained in:
parent
4307fb2a1d
commit
653fa81853
3 changed files with 55 additions and 0 deletions
25
storm/Atomic.cpp
Normal file
25
storm/Atomic.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "storm/Atomic.hpp"
|
||||
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
int32_t SInterlockedDecrement(int32_t* ptr) {
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
return InterlockedDecrement(ptr);
|
||||
#endif
|
||||
|
||||
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||
return __sync_fetch_and_sub(ptr, 1) - 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t SInterlockedIncrement(int32_t* ptr) {
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
return InterlockedIncrement(ptr);
|
||||
#endif
|
||||
|
||||
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||
return __sync_fetch_and_add(ptr, 1) + 1;
|
||||
#endif
|
||||
}
|
||||
10
storm/Atomic.hpp
Normal file
10
storm/Atomic.hpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef STORM_ATOMIC_HPP
|
||||
#define STORM_ATOMIC_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
int32_t SInterlockedDecrement(int32_t* ptr);
|
||||
|
||||
int32_t SInterlockedIncrement(int32_t* ptr);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue