mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-16 08:12:12 +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:
|
private:
|
||||||
#if CONSERVATIVE_DISK_SAVE
|
#if CONSERVATIVE_DISK_SAVE
|
||||||
#if MULTI_THREADED
|
#if MULTI_THREADED
|
||||||
ChangeFlag save_flag;
|
ChangeFlag<false> save_flag;
|
||||||
#else
|
#else
|
||||||
bool save_flag = false;
|
bool save_flag = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
|
template <bool init>
|
||||||
class ChangeFlag
|
class ChangeFlag
|
||||||
{
|
{
|
||||||
private:
|
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:
|
public:
|
||||||
ChangeFlag() noexcept;
|
ChangeFlag() noexcept;
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,10 @@
|
||||||
struct Log
|
struct Log
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
ChangeFlag log_flag;
|
ChangeFlag<true> log_flag;
|
||||||
std::string log_snapshot;
|
std::string log_snapshot;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Log() noexcept;
|
|
||||||
#if MAX_LOG_SIZE == 1
|
#if MAX_LOG_SIZE == 1
|
||||||
Transaction data;
|
Transaction data;
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,28 @@
|
||||||
#include "change_flag.h"
|
#include "change_flag.h"
|
||||||
|
|
||||||
ChangeFlag::ChangeFlag() noexcept {}
|
template <bool init>
|
||||||
|
ChangeFlag<init>::ChangeFlag() noexcept {}
|
||||||
ChangeFlag::ChangeFlag(ChangeFlag &&f) 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);
|
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);
|
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);
|
return change_flag.load(std::memory_order_acquire);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template class ChangeFlag<true>;
|
||||||
|
template class ChangeFlag<false>;
|
||||||
|
|
@ -1,10 +1,5 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
Log::Log() noexcept
|
|
||||||
{
|
|
||||||
log_flag.SetChangesOn();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Log::AddTrans(Transaction &&t) noexcept
|
void Log::AddTrans(Transaction &&t) noexcept
|
||||||
{
|
{
|
||||||
#if MAX_LOG_SIZE == 1
|
#if MAX_LOG_SIZE == 1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue