mirror of
https://github.com/Expand-sys/CCash
synced 2026-03-22 20:47:10 +11:00
🐎 reduced time that Save() needs lock
This commit is contained in:
parent
80b7daad96
commit
18424c64c3
2 changed files with 12 additions and 6 deletions
|
|
@ -97,17 +97,23 @@ public:
|
||||||
std::ofstream user_save("users.json");
|
std::ofstream user_save("users.json");
|
||||||
Json::Value temp;
|
Json::Value temp;
|
||||||
|
|
||||||
|
std::vector<std::string> temp_names;
|
||||||
|
temp_names.reserve(users.size());
|
||||||
{
|
{
|
||||||
std::unique_lock<std::shared_mutex> lock{save_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)
|
for (const auto &u : users)
|
||||||
{
|
{
|
||||||
//we know it contains this key but we call this func to grab mutex
|
temp_names.push_back(u.first);
|
||||||
users.if_contains(u.first, [&temp, &u](const User &u_val) {
|
|
||||||
temp[u.first] = u_val.Serialize();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const std::string &s : temp_names)
|
||||||
|
{
|
||||||
|
users.if_contains(s, [&temp, &s](const User &u) {
|
||||||
|
temp[s] = u.Serialize();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
writer->write(temp, &user_save);
|
writer->write(temp, &user_save);
|
||||||
user_save.close();
|
user_save.close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
main.cpp
4
main.cpp
|
|
@ -7,9 +7,9 @@
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc != 4)
|
if (argc != 3)
|
||||||
{
|
{
|
||||||
std::cerr << "Usage: sudo ./bank <admin password> <saving frequency in minutes> <threads>\n";
|
std::cerr << "Usage: sudo ./bank <admin password> <saving frequency in minutes>\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (geteuid() != 0)
|
if (geteuid() != 0)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue