loading & admin pass

This commit is contained in:
EntireTwix 2021-04-03 00:24:51 -07:00
parent 048519c1a5
commit 4026d7c632
2 changed files with 12 additions and 2 deletions

View file

@ -98,7 +98,10 @@ public:
std::unique_lock<std::shared_mutex> lock{size_lock}; //grabbing it from any busy add/del opperations std::unique_lock<std::shared_mutex> lock{size_lock}; //grabbing it from any busy add/del opperations
for (const auto &u : users) for (const auto &u : users)
{ {
temp[u.first] = u.second.Serialize(); //we know it contains this key but we call this func to grab mutex
users.if_contains(u.first, [&temp, &u](const User &u_val) {
temp[u.first] = u_val.Serialize();
});
} }
std::cout << "dropped unique lock\n"; std::cout << "dropped unique lock\n";
} }
@ -106,6 +109,7 @@ public:
writer->write(temp, &user_save); writer->write(temp, &user_save);
user_save.close(); user_save.close();
} }
//NOT THREAD SAFE, BY NO MEANS SHOULD THIS BE CALLED WHILE RECEIEVING REQUESTS //NOT THREAD SAFE, BY NO MEANS SHOULD THIS BE CALLED WHILE RECEIEVING REQUESTS
void Load() void Load()
{ {

View file

@ -7,7 +7,7 @@ int main(int argc, char **argv)
{ {
if (argc != 5) if (argc != 5)
{ {
std::cerr << "Usage: sudo ./bank <admin pass> <saving frequency in minutes> <run in background (1 or 0)> <threads>\n"; std::cerr << "Usage: sudo ./bank <admin password> <saving frequency in minutes> <run in background (1 or 0)> <threads>\n";
return 0; return 0;
} }
if ((argv[3][0] != '0' && argv[3][0] != '1')) if ((argv[3][0] != '0' && argv[3][0] != '1'))
@ -16,6 +16,12 @@ int main(int argc, char **argv)
return 0; return 0;
} }
//Loading users from users.json
Bank.Load();
//Admin Password
Bank.admin_pass = argv[2];
//Auto Saving //Auto Saving
volatile bool saving_flag = true; volatile bool saving_flag = true;
std::thread([&argv, &saving_flag]() { std::thread([&argv, &saving_flag]() {