mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-16 16:12:14 +11:00
🐎 made SendFunds 10% faster
This commit is contained in:
parent
1c7b2f67fe
commit
ed04fb556f
2 changed files with 11 additions and 6 deletions
|
|
@ -20,15 +20,21 @@ public:
|
|||
const bool state = (password == attempt);
|
||||
if (state)
|
||||
{
|
||||
password = new_pass;
|
||||
password == new_pass;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
friend bool SendFunds(User &a, User &b, uint_fast64_t amount, const std::string &attempt)
|
||||
{
|
||||
std::scoped_lock<std::mutex, std::mutex> lock{a.bal_lock, a.pass_lock};
|
||||
const bool state = (a.password == attempt) && (a.balance >= amount);
|
||||
bool state;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{a.pass_lock};
|
||||
state = (a.password == attempt);
|
||||
}
|
||||
|
||||
std::scoped_lock<std::mutex, std::mutex> lock{a.bal_lock, b.bal_lock};
|
||||
state = state && (a.balance >= amount);
|
||||
if (state)
|
||||
{
|
||||
a.balance -= amount;
|
||||
|
|
|
|||
5
main.cpp
5
main.cpp
|
|
@ -5,11 +5,10 @@ int main()
|
|||
{
|
||||
User a(1000, "pass123");
|
||||
User b(0, "pass123");
|
||||
std::cout << a.ChangePassword("pass123", "newpass123") << '\n';
|
||||
std::cout << SendFunds(a, b, 250, "newpass123") << '\n';
|
||||
a.ChangePassword("pass123", "newpass123");
|
||||
SendFunds(a, b, 250, "newpass123");
|
||||
a.GetBal();
|
||||
a.VerifyPassword("newpass124");
|
||||
std::cout << a.GetBal() << '\n';
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in a new issue