From 80d567478118d11d147b30b95a0be324da679c24 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 20 Jul 2021 17:22:56 -0400 Subject: [PATCH] Optimize Media Layer Proxy --- VERSION | 2 +- docs/CHANGELOG.md | 3 +++ media-layer/proxy/src/server/server.cpp | 22 ++++------------------ media-layer/proxy/src/server/server.h | 14 ++++++++++++-- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/VERSION b/VERSION index cd57a8b95..399088bf4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.5 +2.1.6 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index db43bc340..2472724b5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +**2.1.6** +* Optimize Media Layer Proxy + **2.1.5** * Print Error Message If RakNet Fails To Start diff --git a/media-layer/proxy/src/server/server.cpp b/media-layer/proxy/src/server/server.cpp index 0e3bbdf19..a0a1b380f 100644 --- a/media-layer/proxy/src/server/server.cpp +++ b/media-layer/proxy/src/server/server.cpp @@ -147,30 +147,16 @@ static std::unordered_map &get_unique_ids() { void _assign_unique_id(const char *name, unsigned char id) { get_unique_ids()[name] = id; } -// Only Compare Strings The First Time, Then Cache C String Addresses -static std::unordered_map &get_unique_ids_cache() { - static std::unordered_map unique_ids; - return unique_ids; -} -static unsigned char get_unique_id(const char *name) { - // Check If C String Is Cached - if (get_unique_ids_cache().find(name) != get_unique_ids_cache().end()) { - // Use Cache - return get_unique_ids_cache()[name]; - } else { - // Compare Strings - unsigned char id = get_unique_ids()[name]; // Assume ID Exists - get_unique_ids_cache()[name] = id; - return id; - } +unsigned char _get_unique_id(const char *name) { + return get_unique_ids()[name]; // Assume ID Exists } // The Proxy Is Single-Threaded static pthread_mutex_t proxy_mutex = PTHREAD_MUTEX_INITIALIZER; -void _start_proxy_call(const char *call_name) { +void _start_proxy_call(unsigned char call_id) { // Lock Proxy pthread_mutex_lock(&proxy_mutex); - write_byte(get_unique_id(call_name)); + write_byte(call_id); } void end_proxy_call() { // Flush Write Cache diff --git a/media-layer/proxy/src/server/server.h b/media-layer/proxy/src/server/server.h index 788cabf3f..85e6bfb25 100644 --- a/media-layer/proxy/src/server/server.h +++ b/media-layer/proxy/src/server/server.h @@ -4,10 +4,20 @@ // Assign Unique ID To Function __attribute__((visibility("internal"))) void _assign_unique_id(const char *name, unsigned char id); +__attribute__((visibility("internal"))) unsigned char _get_unique_id(const char *name); // Must Call After Every Call -__attribute__((visibility("internal"))) void _start_proxy_call(const char *name); -#define start_proxy_call() _start_proxy_call(__func__) +__attribute__((visibility("internal"))) void _start_proxy_call(unsigned char call_id); +#define start_proxy_call() \ + { \ + static int _loaded_id = 0; \ + static unsigned char _call_id; \ + if (!_loaded_id) { \ + _loaded_id = 1; \ + _call_id = _get_unique_id(__func__); \ + } \ + _start_proxy_call(_call_id); \ + } __attribute__((visibility("internal"))) void end_proxy_call(); #define CALL(unique_id, name, return_type, args) \