mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
🐛 Send funds wasn't grabbing save_lock as shared
This commit is contained in:
parent
f7b842197d
commit
34873d702b
1 changed files with 6 additions and 6 deletions
|
|
@ -16,14 +16,14 @@ private:
|
|||
std::mutex>
|
||||
users;
|
||||
|
||||
std::shared_mutex size_lock;
|
||||
std::shared_mutex save_lock;
|
||||
|
||||
public:
|
||||
std::string admin_pass;
|
||||
|
||||
bool AddUser(const std::string &name, std::string &&init_pass)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock{size_lock};
|
||||
std::shared_lock<std::shared_mutex> lock{save_lock};
|
||||
return users.try_emplace_l(
|
||||
name, [](User &) {}, std::forward<std::string &&>(init_pass));
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ public:
|
|||
bool state = (admin_pass == attempt);
|
||||
if (state)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock{size_lock};
|
||||
std::shared_lock<std::shared_mutex> lock{save_lock};
|
||||
state = users.try_emplace_l(
|
||||
name, [](User &) {}, init_bal, std::forward<std::string &&>(init_pass));
|
||||
}
|
||||
|
|
@ -61,7 +61,7 @@ public:
|
|||
{
|
||||
//if A exists, A can afford it, and A's password matches
|
||||
bool state = false;
|
||||
|
||||
std::shared_lock<std::shared_mutex> lock{save_lock};
|
||||
users.modify_if(a_name, [&state, amount, &attempt](User &a) {
|
||||
if (state = (a.balance >= amount) && (a.password == attempt), state)
|
||||
{
|
||||
|
|
@ -96,7 +96,7 @@ public:
|
|||
Json::Value temp;
|
||||
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock{size_lock}; //grabbing it from any busy add/del opperations
|
||||
std::unique_lock<std::shared_mutex> lock{save_lock}; //grabbing it from any busy add/del opperations
|
||||
for (const auto &u : users)
|
||||
{
|
||||
//we know it contains this key but we call this func to grab mutex
|
||||
|
|
@ -133,4 +133,4 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
} Bank;
|
||||
} Bank;
|
||||
|
|
|
|||
Loading…
Reference in a new issue