🔥 reverted last couple commits

This commit is contained in:
EntireTwix 2021-04-11 15:38:52 -07:00
parent 32c8964647
commit ad814f99b8

View file

@ -29,18 +29,14 @@ private:
*/ */
std::shared_mutex send_funds_l; std::shared_mutex send_funds_l;
bool size_lock_flag = true;
Json::Value temp;
public: public:
std::string admin_pass; std::string admin_pass;
bool AddUser(const std::string &name, std::string &&init_pass) bool AddUser(const std::string &name, std::string &&init_pass)
{ {
std::unique_lock<std::shared_mutex> lock{size_lock}; std::unique_lock<std::shared_mutex> lock{size_lock};
size_lock_flag = true;
return users.try_emplace_l( return users.try_emplace_l(
name, [this](User &) { size_lock_flag = false; }, std::move(init_pass)); name, [](User &) {}, std::move(init_pass));
} }
bool AdminAddUser(const std::string &attempt, std::string &&name, uint_fast32_t init_bal, std::string &&init_pass) bool AdminAddUser(const std::string &attempt, std::string &&name, uint_fast32_t init_bal, std::string &&init_pass)
{ {
@ -48,7 +44,7 @@ public:
if (state) if (state)
{ {
std::unique_lock<std::shared_mutex> lock{size_lock}; std::unique_lock<std::shared_mutex> lock{size_lock};
size_lock_flag += state = users.try_emplace_l( state = users.try_emplace_l(
name, [](User &) {}, init_bal, std::move(init_pass)); name, [](User &) {}, init_bal, std::move(init_pass));
} }
return state; return state;
@ -57,16 +53,12 @@ public:
bool DelUser(const std::string &name, const std::string &attempt) bool DelUser(const std::string &name, const std::string &attempt)
{ {
std::unique_lock<std::shared_mutex> lock{size_lock}; std::unique_lock<std::shared_mutex> lock{size_lock};
bool state = users.erase_if(name, [&attempt](const User &u) { return (attempt == u.password); }); return users.erase_if(name, [&attempt](const User &u) { return (attempt == u.password); });
size_lock_flag += state;
return state;
} }
bool AdminDelUser(const std::string &name, const std::string &attempt) bool AdminDelUser(const std::string &name, const std::string &attempt)
{ {
std::unique_lock<std::shared_mutex> lock{size_lock}; std::unique_lock<std::shared_mutex> lock{size_lock};
bool state = users.erase_if(name, [this, &attempt](const User &) { return (admin_pass == attempt); }); return users.erase_if(name, [this, &attempt](const User &) { return (admin_pass == attempt); });
size_lock_flag += state;
return state;
} }
bool SendFunds(const std::string &a_name, const std::string &b_name, uint_fast32_t amount, const std::string &attempt) bool SendFunds(const std::string &a_name, const std::string &b_name, uint_fast32_t amount, const std::string &attempt)
@ -152,23 +144,13 @@ public:
Json::Value AllUsers() Json::Value AllUsers()
{ {
bool temp_flag = false; Json::Value temp;
Json::UInt i = 0;
std::shared_lock<std::shared_mutex> lock{size_lock}; //gives readers of users the lock
for (const auto &u : users)
{ {
std::shared_lock<std::shared_mutex> lock{size_lock}; //we know it contains this key but we call this func to grab mutex
temp_flag = size_lock_flag; temp[i++] = u.first;
}
if (temp_flag)
{
temp = Json::Value();
Json::UInt i = 0;
for (const auto &u : users)
{
//we know it contains this key but we call this func to grab mutex
temp[i++] = u.first;
}
std::unique_lock<std::shared_mutex> lock{size_lock};
size_lock_flag = false;
} }
return temp; return temp;
} }