diff --git a/main.cpp b/main.cpp index 0a61df6..1279c46 100644 --- a/main.cpp +++ b/main.cpp @@ -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; diff --git a/src/bank.cpp b/src/bank.cpp index e116393..9a7ee10 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -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 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 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 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 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 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