From 0a73e4c10c4af3b6f982c0e2986f122e75bd20a8 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Thu, 15 Apr 2021 03:28:08 +0200 Subject: [PATCH] Heavily improving the clients join and leave performance --- src/Definitions.h | 1 - src/Properties.h | 6 +++--- src/misc/task_executor.h | 17 ++++++++++++----- src/sql/sqlite/SqliteSQL.cpp | 3 +-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Definitions.h b/src/Definitions.h index 8321180..ef9b7de 100644 --- a/src/Definitions.h +++ b/src/Definitions.h @@ -103,7 +103,6 @@ namespace ts { INIT_HIGH, //Web -> Auth CONNECTED, DISCONNECTING, - DISCONNECTING_FLUSHING, DISCONNECTED }; } diff --git a/src/Properties.h b/src/Properties.h index e2c3c78..e59afdf 100644 --- a/src/Properties.h +++ b/src/Properties.h @@ -315,14 +315,14 @@ namespace ts { CLIENT_OUTPUT_HARDWARE, //automatically up-to-date for any client "in view", this clients headphone/speakers hardware status (is the playback device opened?) CLIENT_DEFAULT_CHANNEL, //only usable for ourself, the default channel we used to connect on our last connection attempt CLIENT_DEFAULT_CHANNEL_PASSWORD, //internal use - CLIENT_SERVER_PASSWORD, //internal use + CLIENT_SERVER_PASSWORD, //internal use (Passed within the clientinit, will not be stored) CLIENT_META_DATA, //automatically up-to-date for any client "in view", not used by TeamSpeak, free storage for sdk users CLIENT_IS_RECORDING, //automatically up-to-date for any client "in view" - CLIENT_VERSION_SIGN, //sign + CLIENT_VERSION_SIGN, //sign (will currently not be set within the clientinit method!) CLIENT_SECURITY_HASH, //SDK use, not used by teamspeak. Hash is provided by an outside source. A channel will use the security salt + other client data to calculate a hash, which must be the same as the one provided here. //Rare properties - CLIENT_KEY_OFFSET, //internal use + CLIENT_KEY_OFFSET, //internal use (Passed within the clientinit, will not be stored) CLIENT_LOGIN_NAME, //used for serverquery clients, makes no sense on normal clients currently CLIENT_LOGIN_PASSWORD, //used for serverquery clients, makes no sense on normal clients currently CLIENT_DATABASE_ID, //automatically up-to-date for any client "in view", only valid with PERMISSION feature, holds database client id diff --git a/src/misc/task_executor.h b/src/misc/task_executor.h index 788e3b4..fcc857a 100644 --- a/src/misc/task_executor.h +++ b/src/misc/task_executor.h @@ -128,6 +128,7 @@ namespace ts { * Helper class for tasks which could be executed multiple times. * It will avoid execution stacking while the task is executing. * The task will never be executed twice only sequential. + * Note: If the `multi_shot_task` handle gets deleted no enqueued tasks will be executed. */ struct multi_shot_task { public: @@ -135,16 +136,22 @@ namespace ts { multi_shot_task(std::shared_ptr executor, std::string task_name, std::function callback) : inner{std::make_shared(std::move(executor), std::move(task_name), std::move(callback))} { - this->inner->callback_wrapper = [inner = this->inner]{ - auto result = inner->schedule_kind.exchange(2); + std::weak_ptr weak_inner{this->inner}; + this->inner->callback_wrapper = [weak_inner]{ + auto callback_inner = weak_inner.lock(); + if(!callback_inner) { + return; + } + + auto result = callback_inner->schedule_kind.exchange(2); assert(result == 1); (void) result; try { - (inner->callback)(); - execute_finished(&*inner); + (callback_inner->callback)(); + execute_finished(&*callback_inner); } catch (...) { - execute_finished(&*inner); + execute_finished(&*callback_inner); std::rethrow_exception(std::current_exception()); } }; diff --git a/src/sql/sqlite/SqliteSQL.cpp b/src/sql/sqlite/SqliteSQL.cpp index 0c0561e..ef84ac5 100644 --- a/src/sql/sqlite/SqliteSQL.cpp +++ b/src/sql/sqlite/SqliteSQL.cpp @@ -90,8 +90,7 @@ std::shared_ptr SqliteManager::allocateStatement(const std::string return nullptr; return std::shared_ptr(stmt, [](void* _ptr) { - auto _stmt = static_cast(_ptr); - if(_stmt) sqlite3_finalize(_stmt); + sqlite3_finalize(static_cast(_ptr)); }); }