mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-18 09:02:14 +11:00
🔥 removed thread argument in place of detecting CPU cores
This commit is contained in:
parent
e88d699ea8
commit
dfaac069a8
1 changed files with 19 additions and 4 deletions
23
main.cpp
23
main.cpp
|
|
@ -5,11 +5,15 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "bank_api.h"
|
#include "bank_api.h"
|
||||||
|
|
||||||
|
//sig handling headers
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
//threads of cpu
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
using namespace drogon;
|
using namespace drogon;
|
||||||
|
|
||||||
|
|
@ -17,20 +21,25 @@ static Bank bank;
|
||||||
|
|
||||||
void SaveSig(int s)
|
void SaveSig(int s)
|
||||||
{
|
{
|
||||||
bank.Save();
|
|
||||||
std::cout << "\nSaving on close...\n";
|
std::cout << "\nSaving on close...\n";
|
||||||
|
bank.Save();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
std::cout << "\nSSE3 : " << (__builtin_cpu_supports("sse3") ? "enabled" : "disabled")
|
||||||
|
<< "\nCores : " << get_nprocs() / 2
|
||||||
|
<< "\nThreads : " << get_nprocs() + 1
|
||||||
|
<< 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(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");
|
static_assert(max_log_size >= pre_log_size, "The maximum log size must be larger than or equal to the amount preallocated.\n");
|
||||||
static_assert(!max_log_size || !(max_log_size % pre_log_size), "The maximum log size must be divisible by the preallocation size.\n");
|
static_assert(!max_log_size || !(max_log_size % pre_log_size), "The maximum log size must be divisible by the preallocation size.\n");
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -73,12 +82,18 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
//endpoints
|
//endpoints
|
||||||
auto APIv1 = std::make_shared<v1::api>(bank); //v1
|
auto APIv1 = std::make_shared<v1::api>(bank); //v1
|
||||||
|
auto user_filter = std::make_shared<UserFilter>(bank);
|
||||||
|
|
||||||
app().registerPostHandlingAdvice(
|
app().registerPostHandlingAdvice(
|
||||||
[](const drogon::HttpRequestPtr &req, const drogon::HttpResponsePtr &resp) {
|
[](const drogon::HttpRequestPtr &req, const drogon::HttpResponsePtr &resp) {
|
||||||
resp->addHeader("Access-Control-Allow-Origin", "*"); //CORS
|
resp->addHeader("Access-Control-Allow-Origin", "*"); //CORS
|
||||||
});
|
});
|
||||||
app().loadConfigFile(config_location).registerController(APIv1).setThreadNum(std::stoul(std::string(argv[3]))).run();
|
app()
|
||||||
|
.loadConfigFile(config_location)
|
||||||
|
.registerFilter(user_filter)
|
||||||
|
.registerController(APIv1)
|
||||||
|
.setThreadNum(get_nprocs())
|
||||||
|
.run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue