mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
✨ conservative saving
This commit is contained in:
parent
ac859f2c17
commit
cf036901bb
2 changed files with 28 additions and 1 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <iostream> //temporary
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
|
#include <atomic>
|
||||||
#include "error_responses.hpp"
|
#include "error_responses.hpp"
|
||||||
#include "parallel-hashmap/parallel_hashmap/phmap.h"
|
#include "parallel-hashmap/parallel_hashmap/phmap.h"
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
|
|
@ -18,6 +19,16 @@ private:
|
||||||
std::mutex>
|
std::mutex>
|
||||||
users;
|
users;
|
||||||
|
|
||||||
|
#if CONSERVATIVE_DISK_SAVE
|
||||||
|
std::atomic<bool> change_flag = false; //if true changes have been made
|
||||||
|
|
||||||
|
void ChangesMade() noexcept; //called after making changes
|
||||||
|
void ChangesSaved() noexcept; //called after saving
|
||||||
|
#elif
|
||||||
|
#define ChangesMade() ;
|
||||||
|
#define ChangesSaved() ;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief size_l should be grabbed if the operation MODIFIES the size (shared), this is so that when save claims unique
|
* @brief size_l should be grabbed if the operation MODIFIES the size (shared), this is so that when save claims unique
|
||||||
*
|
*
|
||||||
|
|
|
||||||
16
src/bank.cpp
16
src/bank.cpp
|
|
@ -1,11 +1,27 @@
|
||||||
#include "bank.h"
|
#include "bank.h"
|
||||||
|
|
||||||
|
#if CONSERVATIVE_DISK_SAVE
|
||||||
|
void Bank::ChangesMade() noexcept
|
||||||
|
{
|
||||||
|
while (change_flag.exchange(true, std::memory_order_relaxed))
|
||||||
|
;
|
||||||
|
std::atomic_thread_fence(std::memory_order_acquire);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bank::ChangesSaved() noexcept
|
||||||
|
{
|
||||||
|
std::atomic_thread_fence(std::memory_order_release);
|
||||||
|
change_flag.store(false, std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int_fast8_t Bank::AddUser(const std::string &name, const std::string &init_pass) noexcept
|
int_fast8_t Bank::AddUser(const std::string &name, const std::string &init_pass) noexcept
|
||||||
{
|
{
|
||||||
if (name.size() > max_name_size)
|
if (name.size() > max_name_size)
|
||||||
{
|
{
|
||||||
return ErrorResponse::NameTooLong;
|
return ErrorResponse::NameTooLong;
|
||||||
}
|
}
|
||||||
|
//replace with string find
|
||||||
for (char c : name)
|
for (char c : name)
|
||||||
{
|
{
|
||||||
if (c == ' ')
|
if (c == ' ')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue