mirror of
https://github.com/thunderbrewhq/bc.git
synced 2025-12-12 18:12:29 +00:00
feat(lock): add basic lock functions
This commit is contained in:
parent
3b5da1af9c
commit
e8d3709d31
8 changed files with 207 additions and 0 deletions
13
bc/lock/Atomic.cpp
Normal file
13
bc/lock/Atomic.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include "bc/lock/Atomic.hpp"
|
||||
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
int32_t Blizzard::Lock::Atomic::Increment(volatile int32_t* value) {
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
return InterlockedIncrement(reinterpret_cast<volatile long*>(value));
|
||||
#elif defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||
return __sync_fetch_and_add(value, 1) + 1;
|
||||
#endif
|
||||
}
|
||||
16
bc/lock/Atomic.hpp
Normal file
16
bc/lock/Atomic.hpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef BC_LOCK_ATOMIC_HPP
|
||||
#define BC_LOCK_ATOMIC_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Blizzard {
|
||||
namespace Lock {
|
||||
namespace Atomic {
|
||||
|
||||
int32_t Increment(volatile int32_t* value);
|
||||
|
||||
} // namespace Atomic
|
||||
} // namespace Lock
|
||||
} // namespace Blizzard
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue