From 33d25fb18102e0d5bab226bd652274dc6aaeaf61 Mon Sep 17 00:00:00 2001 From: mbandic Date: Thu, 26 Sep 2024 07:37:06 +0000 Subject: [PATCH] Async fork start commit --- lib/mysql.hpp | 4 ++-- src/mysql.cpp | 14 +++++++------- test/test.cpp | 47 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/lib/mysql.hpp b/lib/mysql.hpp index 7c284ec..662d0cb 100644 --- a/lib/mysql.hpp +++ b/lib/mysql.hpp @@ -154,7 +154,7 @@ class MySQL { * Internal tloop periodic */ - void _tloop(); + void _tloop(uint32_t b, uint32_t e); public: function on_error; @@ -219,7 +219,7 @@ public: * please call this function in it for proper operation at a certain time interval. * You can use the default MYSQL_PERIODIC_INTERNAL_TIME */ - void tloop(); + void tloop(uint32_t b, uint32_t e); /** * Destruktor diff --git a/src/mysql.cpp b/src/mysql.cpp index 1850603..bd7b64f 100644 --- a/src/mysql.cpp +++ b/src/mysql.cpp @@ -15,7 +15,7 @@ marcelb::mysql::MySQL::MySQL(const string _path, const string _username, const s tloop_future = async(launch::async, [&](){ while (run_tloop) { usleep(MYSQL_PERIODIC_INTERNAL_TIME*1000); - _tloop(); + _tloop(0, connection_pool.size()); } return; }); @@ -93,11 +93,11 @@ bool marcelb::mysql::MySQL::disconnect_connection(Connection* connection) { return status; } -void marcelb::mysql::MySQL::_tloop() { +void marcelb::mysql::MySQL::_tloop(uint32_t b, uint32_t e) { if (!run_tloop) { return; } - for (size_t i=0; iisClosed()){ - cout << "Zatvori----" << endl; + cout << "Zatvori----" << endl; conn->close(); } Connection *n_conn = create_connection(); - { + cout << "Otvori----" << endl; lock_guard lock(io); connection_pool.push(n_conn); condition.notify_one(); @@ -168,12 +168,12 @@ marcelb::mysql::MySQL::~MySQL() { } -void marcelb::mysql::MySQL::tloop() { +void marcelb::mysql::MySQL::tloop(uint32_t b, uint32_t e) { if (tloop_type == time_loop_type::internal) { if (on_error) { on_error("Can't start external call tloop, internal is active!"); } return; } - _tloop(); + _tloop(b,e); } \ No newline at end of file diff --git a/test/test.cpp b/test/test.cpp index 524148f..044f790 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -14,8 +14,9 @@ using namespace marcelb::asynco; int main() { auto inis = rtime_ms(); try { + const int n = 30; // MySQL mydb("tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 5, time_loop_type::internal); - MySQL mydb("tcp://bitelex.ddns.net:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 12, time_loop_type::external); + MySQL mydb("tcp://bitelex.ddns.net:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", n, time_loop_type::external); // MySQL mydb("tcp://bitelex.ddns.net:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 5); cout << "init: " << rtime_ms() - inis << endl; @@ -25,14 +26,44 @@ int main() { }; periodic mysql_tloop ( [&mydb] () { - try { - auto start = rtime_ms(); - mydb.tloop(); - cout << "loop--------------------------- nema error, trajalo: " << rtime_ms() - start << endl; - } catch (...) { - cout << "Bude neki error u loopu" << endl; + auto l_start = rtime_ms(); + vector> to_wait; + for (int i=0, old_i=0; i