🐛 fixed last commit

This commit is contained in:
EntireTwix 2021-07-03 00:46:40 -07:00
parent 7d1ec6d634
commit 1b950ce0c0
2 changed files with 2 additions and 10 deletions

View file

@ -110,7 +110,9 @@ int main(int argc, char **argv)
.registerFilter(user_filter)
.registerFilter(admin_filter)
.registerController(API)
#if MULTI_THREADED
.setThreadNum(get_nprocs())
#endif
.run();
return 0;

View file

@ -66,9 +66,7 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam
}
BankResponse state;
#if MULTI_THREADED
std::shared_lock<std::shared_mutex> lock{send_funds_l}; //about 10% of this function's cost
#endif
#if MAX_LOG_SIZE > 0
Transaction temp(a_name, b_name, amount);
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"};
}
#if MULTI_THREADED
std::shared_lock<std::shared_mutex> lock{size_l};
#endif
return (users.try_emplace_l(
std::move(name), [](User &) {}, std::move(init_pass)))
? 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"};
}
#if MULTI_THREADED
std::shared_lock<std::shared_mutex> lock{size_l};
#endif
return (users.try_emplace_l(
std::move(name), [](User &) {}, init_bal, std::move(init_pass)))
? 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
{
#if MULTI_THREADED
std::shared_lock<std::shared_mutex> lock{size_l};
#endif
#if RETURN_ON_DEL
uint32_t bal;
if (users.erase_if(name, [this, &bal, &name](User &u) {
@ -218,9 +210,7 @@ void Bank::Save()
//loading info into json temp
{
#if MULTI_THREADED
std::scoped_lock<std::shared_mutex, std::shared_mutex> lock{size_l, send_funds_l};
#endif
for (const auto &u : users)
{
//we know it contains this key but we call this func to grab mutex