mirror of
https://github.com/Expand-sys/CCash
synced 2026-03-22 20:47:10 +11:00
🐛 fixed last commit
This commit is contained in:
parent
7d1ec6d634
commit
1b950ce0c0
2 changed files with 2 additions and 10 deletions
2
main.cpp
2
main.cpp
|
|
@ -110,7 +110,9 @@ int main(int argc, char **argv)
|
||||||
.registerFilter(user_filter)
|
.registerFilter(user_filter)
|
||||||
.registerFilter(admin_filter)
|
.registerFilter(admin_filter)
|
||||||
.registerController(API)
|
.registerController(API)
|
||||||
|
#if MULTI_THREADED
|
||||||
.setThreadNum(get_nprocs())
|
.setThreadNum(get_nprocs())
|
||||||
|
#endif
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
10
src/bank.cpp
10
src/bank.cpp
|
|
@ -66,9 +66,7 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam
|
||||||
}
|
}
|
||||||
|
|
||||||
BankResponse state;
|
BankResponse state;
|
||||||
#if MULTI_THREADED
|
|
||||||
std::shared_lock<std::shared_mutex> lock{send_funds_l}; //about 10% of this function's cost
|
std::shared_lock<std::shared_mutex> lock{send_funds_l}; //about 10% of this function's cost
|
||||||
#endif
|
|
||||||
#if MAX_LOG_SIZE > 0
|
#if MAX_LOG_SIZE > 0
|
||||||
Transaction temp(a_name, b_name, amount);
|
Transaction temp(a_name, b_name, amount);
|
||||||
if (!users.modify_if(a_name, [&temp, &state, amount](User &a) {
|
if (!users.modify_if(a_name, [&temp, &state, amount](User &a) {
|
||||||
|
|
@ -164,9 +162,7 @@ BankResponse Bank::AddUser(std::string &&name, std::string &&init_pass) noexcept
|
||||||
{
|
{
|
||||||
return {k400BadRequest, "Invalid Name, breaks size and/or character restrictions"};
|
return {k400BadRequest, "Invalid Name, breaks size and/or character restrictions"};
|
||||||
}
|
}
|
||||||
#if MULTI_THREADED
|
|
||||||
std::shared_lock<std::shared_mutex> lock{size_l};
|
std::shared_lock<std::shared_mutex> lock{size_l};
|
||||||
#endif
|
|
||||||
return (users.try_emplace_l(
|
return (users.try_emplace_l(
|
||||||
std::move(name), [](User &) {}, std::move(init_pass)))
|
std::move(name), [](User &) {}, std::move(init_pass)))
|
||||||
? BankResponse(k200OK, "User added!")
|
? BankResponse(k200OK, "User added!")
|
||||||
|
|
@ -178,9 +174,7 @@ BankResponse Bank::AdminAddUser(std::string &&name, uint32_t init_bal, std::stri
|
||||||
{
|
{
|
||||||
return {k400BadRequest, "Invalid Name, breaks size and/or character restrictions"};
|
return {k400BadRequest, "Invalid Name, breaks size and/or character restrictions"};
|
||||||
}
|
}
|
||||||
#if MULTI_THREADED
|
|
||||||
std::shared_lock<std::shared_mutex> lock{size_l};
|
std::shared_lock<std::shared_mutex> lock{size_l};
|
||||||
#endif
|
|
||||||
return (users.try_emplace_l(
|
return (users.try_emplace_l(
|
||||||
std::move(name), [](User &) {}, init_bal, std::move(init_pass)))
|
std::move(name), [](User &) {}, init_bal, std::move(init_pass)))
|
||||||
? BankResponse(k200OK, "User added!")
|
? BankResponse(k200OK, "User added!")
|
||||||
|
|
@ -188,9 +182,7 @@ BankResponse Bank::AdminAddUser(std::string &&name, uint32_t init_bal, std::stri
|
||||||
}
|
}
|
||||||
BankResponse Bank::DelUser(const std::string &name) noexcept
|
BankResponse Bank::DelUser(const std::string &name) noexcept
|
||||||
{
|
{
|
||||||
#if MULTI_THREADED
|
|
||||||
std::shared_lock<std::shared_mutex> lock{size_l};
|
std::shared_lock<std::shared_mutex> lock{size_l};
|
||||||
#endif
|
|
||||||
#if RETURN_ON_DEL
|
#if RETURN_ON_DEL
|
||||||
uint32_t bal;
|
uint32_t bal;
|
||||||
if (users.erase_if(name, [this, &bal, &name](User &u) {
|
if (users.erase_if(name, [this, &bal, &name](User &u) {
|
||||||
|
|
@ -218,9 +210,7 @@ void Bank::Save()
|
||||||
|
|
||||||
//loading info into json temp
|
//loading info into json temp
|
||||||
{
|
{
|
||||||
#if MULTI_THREADED
|
|
||||||
std::scoped_lock<std::shared_mutex, std::shared_mutex> lock{size_l, send_funds_l};
|
std::scoped_lock<std::shared_mutex, std::shared_mutex> lock{size_l, send_funds_l};
|
||||||
#endif
|
|
||||||
for (const auto &u : users)
|
for (const auto &u : users)
|
||||||
{
|
{
|
||||||
//we know it contains this key but we call this func to grab mutex
|
//we know it contains this key but we call this func to grab mutex
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue