diff --git a/include/bank.hpp b/include/bank.hpp index c31c06c..c001bfa 100644 --- a/include/bank.hpp +++ b/include/bank.hpp @@ -98,7 +98,10 @@ public: std::unique_lock lock{size_lock}; //grabbing it from any busy add/del opperations 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"; } @@ -106,6 +109,7 @@ public: writer->write(temp, &user_save); user_save.close(); } + //NOT THREAD SAFE, BY NO MEANS SHOULD THIS BE CALLED WHILE RECEIEVING REQUESTS void Load() { diff --git a/main.cpp b/main.cpp index ec820a6..c9f8d36 100644 --- a/main.cpp +++ b/main.cpp @@ -7,7 +7,7 @@ int main(int argc, char **argv) { if (argc != 5) { - std::cerr << "Usage: sudo ./bank \n"; + std::cerr << "Usage: sudo ./bank \n"; return 0; } if ((argv[3][0] != '0' && argv[3][0] != '1')) @@ -16,6 +16,12 @@ int main(int argc, char **argv) return 0; } + //Loading users from users.json + Bank.Load(); + + //Admin Password + Bank.admin_pass = argv[2]; + //Auto Saving volatile bool saving_flag = true; std::thread([&argv, &saving_flag]() {