diff --git a/include/bank.h b/include/bank.h index 8693d7f..0aca280 100644 --- a/include/bank.h +++ b/include/bank.h @@ -41,6 +41,9 @@ private: public: std::string admin_account; + size_t NumOfUsers() const noexcept; + uint64_t NumOfLogs() const noexcept; + #if CONSERVATIVE_DISK_SAVE bool GetChangeState() const noexcept; #endif diff --git a/main.cpp b/main.cpp index bde9c69..7f217f3 100644 --- a/main.cpp +++ b/main.cpp @@ -28,21 +28,6 @@ void SaveSig(int s) int main(int argc, char **argv) { - std::cout - << "\nAVX : " << (__builtin_cpu_supports("avx") ? "enabled" : "disabled") - << "\nAVX 2 : " << (__builtin_cpu_supports("avx2") ? "enabled" : "disabled") - << "\nSSE 2 : " << (__builtin_cpu_supports("sse2") ? "enabled" : "disabled") - << "\nSSE 3 : " << (__builtin_cpu_supports("sse3") ? "enabled" : "disabled") - << "\nSSE 4.1 : " << (__builtin_cpu_supports("sse4.1") ? "enabled" : "disabled") - << "\nSSE 4.2 : " << (__builtin_cpu_supports("sse4.2") ? "enabled" : "disabled") -#if MULTI_THREADED - << "\n\nThreads : " << get_nprocs() + 1 - << "\nMulti threading : enabled" -#else - << "\n\nThreads : " << 2 - << "\nMulti threading : disabled" -#endif - << std::endl; //flushing before EventLoop static_assert(bool(MAX_LOG_SIZE) == bool(PRE_LOG_SIZE), "You must either utilize both or neither logging variables.\n"); static_assert(MAX_LOG_SIZE >= PRE_LOG_SIZE, "The maximum log size must be larger than or equal to the amount preallocated.\n"); @@ -58,10 +43,28 @@ int main(int argc, char **argv) std::cerr << "ERROR: CCash MUST be ran as root\n"; return 0; } + std::cout + << "\nAVX : " << (__builtin_cpu_supports("avx") ? "enabled" : "disabled") + << "\nAVX 2 : " << (__builtin_cpu_supports("avx2") ? "enabled" : "disabled") + << "\nSSE 2 : " << (__builtin_cpu_supports("sse2") ? "enabled" : "disabled") + << "\nSSE 3 : " << (__builtin_cpu_supports("sse3") ? "enabled" : "disabled") + << "\nSSE 4.1 : " << (__builtin_cpu_supports("sse4.1") ? "enabled" : "disabled") + << "\nSSE 4.2 : " << (__builtin_cpu_supports("sse4.2") ? "enabled" : "disabled") +#if MULTI_THREADED + << "\n\nThreads : " << get_nprocs() + 1 + << "\nMulti threading : enabled"; +#else + << "\n\nThreads : " << 2 + << "\nMulti threading : disabled"; +#endif //Loading users from users.json bank.Load(); + std::cout << "\n\nLoaded " << bank.NumOfUsers() << " Users" + << "\nLoaded " << bank.NumOfLogs() << " Logs" + << std::endl; //flushing before EventLoop + //Sig handling struct sigaction sigIntHandler; diff --git a/src/bank.cpp b/src/bank.cpp index e3c065a..945cacd 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -1,5 +1,7 @@ #include "bank.h" +using namespace drogon; + __attribute__((always_inline)) inline bool ValidUsrname(const std::string &name) noexcept { if (name.size() < min_name_size || name.size() > max_name_size) @@ -16,7 +18,19 @@ __attribute__((always_inline)) inline bool ValidUsrname(const std::string &name) return true; } -using namespace drogon; +//NOT THREAD SAFE +size_t Bank::NumOfUsers() const noexcept { return users.size(); } + +//NOT THREAD SAFE +uint64_t Bank::NumOfLogs() const noexcept +{ + uint64_t res; + for (const auto &u : users) + { + res += u.second.log.data.size(); + } + return res; +} #if CONSERVATIVE_DISK_SAVE bool Bank::GetChangeState() const noexcept @@ -29,8 +43,7 @@ bool Bank::GetChangeState() const noexcept } #endif -BankResponse -Bank::GetBal(const std::string &name) const noexcept +BankResponse Bank::GetBal(const std::string &name) const noexcept { uint64_t res = 0; users.if_contains(name, [&res](const User &u) { res = u.balance + 1; });