mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-15 15:52:13 +11:00
🔥🐎 made initial value compile time
This commit is contained in:
parent
6dbb9fd98a
commit
e502f3ce1f
5 changed files with 19 additions and 17 deletions
|
|
@ -28,7 +28,7 @@ class Bank
|
|||
private:
|
||||
#if CONSERVATIVE_DISK_SAVE
|
||||
#if MULTI_THREADED
|
||||
ChangeFlag save_flag;
|
||||
ChangeFlag<false> save_flag;
|
||||
#else
|
||||
bool save_flag = false;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
#pragma once
|
||||
#include <atomic>
|
||||
|
||||
template <bool init>
|
||||
class ChangeFlag
|
||||
{
|
||||
private:
|
||||
std::atomic<bool> change_flag = false; //if true changes have been made
|
||||
std::atomic<bool> change_flag = init; //if true changes have been made
|
||||
|
||||
public:
|
||||
ChangeFlag() noexcept;
|
||||
|
|
|
|||
|
|
@ -9,11 +9,10 @@
|
|||
struct Log
|
||||
{
|
||||
private:
|
||||
ChangeFlag log_flag;
|
||||
ChangeFlag<true> log_flag;
|
||||
std::string log_snapshot;
|
||||
|
||||
public:
|
||||
Log() noexcept;
|
||||
#if MAX_LOG_SIZE == 1
|
||||
Transaction data;
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -1,21 +1,28 @@
|
|||
#include "change_flag.h"
|
||||
|
||||
ChangeFlag::ChangeFlag() noexcept {}
|
||||
|
||||
ChangeFlag::ChangeFlag(ChangeFlag &&f) noexcept
|
||||
template <bool init>
|
||||
ChangeFlag<init>::ChangeFlag() noexcept {}
|
||||
template <bool init>
|
||||
ChangeFlag<init>::ChangeFlag(ChangeFlag &&f) noexcept
|
||||
{
|
||||
change_flag.store(f.GetChangeState(), std::memory_order_release); //is this safe?
|
||||
change_flag.store(f.GetChangeState(), std::memory_order_release);
|
||||
}
|
||||
|
||||
void ChangeFlag::SetChangesOn() noexcept
|
||||
template <bool init>
|
||||
void ChangeFlag<init>::SetChangesOn() noexcept
|
||||
{
|
||||
return change_flag.store(1, std::memory_order_release);
|
||||
}
|
||||
void ChangeFlag::SetChangesOff() noexcept
|
||||
template <bool init>
|
||||
void ChangeFlag<init>::SetChangesOff() noexcept
|
||||
{
|
||||
return change_flag.store(0, std::memory_order_release);
|
||||
}
|
||||
bool ChangeFlag::GetChangeState() const noexcept
|
||||
template <bool init>
|
||||
bool ChangeFlag<init>::GetChangeState() const noexcept
|
||||
{
|
||||
return change_flag.load(std::memory_order_acquire);
|
||||
}
|
||||
}
|
||||
|
||||
template class ChangeFlag<true>;
|
||||
template class ChangeFlag<false>;
|
||||
|
|
@ -1,10 +1,5 @@
|
|||
#include "log.h"
|
||||
|
||||
Log::Log() noexcept
|
||||
{
|
||||
log_flag.SetChangesOn();
|
||||
}
|
||||
|
||||
void Log::AddTrans(Transaction &&t) noexcept
|
||||
{
|
||||
#if MAX_LOG_SIZE == 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue